Commit dd7a1393 by Carl Bergquist

adds null check for response parser

parent 8ad10149
......@@ -76,8 +76,12 @@ function (_, queryDef) {
newSeries = { datapoints: [], metric: metric.type, field: metric.field, props: props};
for (i = 0; i < esAgg.buckets.length; i++) {
bucket = esAgg.buckets[i];
value = bucket[metric.id].value;
newSeries.datapoints.push([value, bucket.key]);
value = bucket[metric.id];
if (value !== undefined) {
newSeries.datapoints.push([value.value, bucket.key]);
}
}
seriesList.push(newSeries);
break;
......
......@@ -35,6 +35,10 @@ function (angular, _, queryDef) {
}
switch($scope.agg.type) {
case 'moving_avg': {
$scope.agg.aggregation = $scope.agg.aggregation || 'sum';
break;
}
case 'percentiles': {
$scope.agg.settings.percents = $scope.agg.settings.percents || [25,50,75,95,99];
$scope.settingsLinkText = 'values: ' + $scope.agg.settings.percents.join(',');
......@@ -79,19 +83,9 @@ function (angular, _, queryDef) {
};
$scope.getMetrics = function() {
console.log($scope.target.metrics);
var mets = _.filter($scope.target.metrics, function(x) {
return x.type !== 'moving_avg';
});
mets = _.map(mets, function(m) {
return { text: m.type, type: m.id };
});
console.log(mets);
var aggs = [{ text: 'Sum', type: 'sum'}, { text: 'Average', type: 'avg'}];
return $q.when(mets)
return $q.when(aggs)
.then(uiSegmentSrv.transformToSegments(false));
};
......
......@@ -10,7 +10,7 @@
<metric-segment-model property="agg.field" get-options="getFieldsInternal()" on-change="onChange()" css-class="tight-form-item-xxlarge"></metric-segment-model>
</li>
<li ng-if="aggDef.requiresBucketsPath">
<metric-segment-model property="agg.field" get-options="getMetrics()" on-change="onChange()" css-class="tight-form-item-xxlarge"></metric-segment-model>
<metric-segment-model property="agg.aggregation" get-options="getMetrics()" on-change="onChange()" css-class="tight-form-item-xxlarge"></metric-segment-model>
</li>
<li class="tight-form-item last" ng-if="settingsLinkText">
<a ng-click="toggleOptions()">{{settingsLinkText}}</a>
......
......@@ -167,36 +167,28 @@ function () {
continue;
}
var metricAgg = {field: metric.field};
var aggField = {};
var metricAgg = null;
if (metric.type === 'moving_avg') {
var subBucket = metric.id + "_mavg";
var af = {};
af[metric.aggregation] = {field: metric.field};
nestedAggs.aggs[subBucket] = af;
metricAgg = { buckets_path: subBucket };
} else {
metricAgg = {field: metric.field};
}
for (var prop in metric.settings) {
if (metric.settings.hasOwnProperty(prop) && metric.settings[prop] !== null) {
metricAgg[prop] = metric.settings[prop];
}
}
var aggField = {};
if (metric.type === 'moving_avg') {
var pipeAgg = '';
for(var aggname in nestedAggs.aggs) {
var agg = nestedAggs.aggs[aggname];
for(prop in agg) {
if (agg.hasOwnProperty(prop) && agg[prop] !== null) {
if (metric.field === prop) {
pipeAgg = aggname;
break;
}
}
}
}
if (pipeAgg !== '') {
aggField[metric.type] = { buckets_path: pipeAgg };
nestedAggs.aggs[metric.id] = aggField;
}
} else {
aggField[metric.type] = metricAgg;
nestedAggs.aggs[metric.id] = aggField;
}
aggField[metric.type] = metricAgg;
nestedAggs.aggs[metric.id] = aggField;
}
return query;
......
......@@ -13,7 +13,7 @@ function (_) {
{text: "Min", value: 'min', requiresField: true},
{text: "Extended Stats", value: 'extended_stats', requiresField: true},
{text: "Percentiles", value: 'percentiles', requiresField: true},
{text: "Moving Avg", value: 'moving_avg', requiresField: false, requiresBucketsPath: true},
{text: "Moving Avg", value: 'moving_avg', requiresField: true, requiresBucketsPath: true},
{text: "Unique Count", value: "cardinality", requiresField: true},
{text: "Raw Document", value: "raw_document", requiresField: false}
],
......
......@@ -159,14 +159,10 @@ describe('ElasticQueryBuilder', function() {
var query = builder.build({
metrics: [
{
id: '1',
type: 'sum',
field: '@value',
},
{
id: '2',
type: 'moving_avg',
field: 'sum'
field: '@value',
aggregation: 'sum'
}
],
bucketAggs: [
......@@ -175,8 +171,9 @@ describe('ElasticQueryBuilder', function() {
});
var firstLevel = query.aggs["3"];
console.log(JSON.stringify(query));
expect(firstLevel.aggs["2"]).not.to.be(undefined);
expect(firstLevel.aggs["2"].moving_avg).not.to.be(undefined);
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("1");
expect(firstLevel.aggs["2"].moving_avg.buckets_path).to.be("99");
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment