Skip to content

Commit

Permalink
Merge pull request #6309 from spalger/fix/readingPercentileAgg
Browse files Browse the repository at this point in the history
Properly read new percentile agg format
  • Loading branch information
epixa committed Feb 25, 2016
2 parents c7e08ea + 3422584 commit 41a6fb0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/plugins/elasticsearch/lib/__tests__/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ describe('plugins/elasticsearch', function () {
testRoute({
method: 'POST',
url: '/elasticsearch/_msearch?timeout=0&ignore_unavailable=true&preference=1429577952339',
payload: '{"index":"logstash-2015.04.21","ignore_unavailable":true}\n{"size":500,"sort":{"@timestamp":"desc"},"query":{"bool":{"must":[{"query_string":{"analyze_wildcard":true,"query":"*"}},{"bool":{"must":[{"range":{"@timestamp":{"gte":1429577068175,"lte":1429577968175}}}],"must_not":[]}}],"must_not":[]}},"highlight":{"pre_tags":["@kibana-highlighted-field@"],"post_tags":["@/kibana-highlighted-field@"],"fields":{"*":{}}},"aggs":{"2":{"date_histogram":{"field":"@timestamp","interval":"30s","pre_zone":"-07:00","pre_zone_adjust_large_interval":true,"min_doc_count":0,"extended_bounds":{"min":1429577068175,"max":1429577968175}}}},"fields":["*","_source"],"script_fields":{},"fielddata_fields":["timestamp_offset","@timestamp","utc_time"]}\n' // eslint-disable-line max-len
payload: '{"index":"logstash-2015.04.21","ignore_unavailable":true}\n{"size":500,"sort":{"@timestamp":"desc"},"query":{"bool":{"must":[{"query_string":{"analyze_wildcard":true,"query":"*"}},{"bool":{"must":[{"range":{"@timestamp":{"gte":1429577068175,"lte":1429577968175}}}],"must_not":[]}}],"must_not":[]}},"highlight":{"pre_tags":["@kibana-highlighted-field@"],"post_tags":["@/kibana-highlighted-field@"],"fields":{"*":{}}},"aggs":{"2":{"date_histogram":{"field":"@timestamp","interval":"30s","min_doc_count":0,"extended_bounds":{"min":1429577068175,"max":1429577968175}}}},"fields":["*","_source"],"script_fields":{},"fielddata_fields":["timestamp_offset","@timestamp","utc_time"]}\n' // eslint-disable-line max-len
});

});
Expand Down
9 changes: 3 additions & 6 deletions src/ui/public/agg_types/metrics/percentile_ranks.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import 'ui/number_list';
import AggTypesMetricsMetricAggTypeProvider from 'ui/agg_types/metrics/MetricAggType';
import AggTypesMetricsGetResponseAggConfigClassProvider from 'ui/agg_types/metrics/getResponseAggConfigClass';
import RegistryFieldFormatsProvider from 'ui/registry/field_formats';
export default function AggTypeMetricPercentileRanksProvider(Private) {
import getPercentileValue from './percentiles_get_value';

export default function AggTypeMetricPercentileRanksProvider(Private) {
var MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
var getResponseAggConfigClass = Private(AggTypesMetricsGetResponseAggConfigClassProvider);
var fieldFormats = Private(RegistryFieldFormatsProvider);
Expand Down Expand Up @@ -49,11 +50,7 @@ export default function AggTypeMetricPercentileRanksProvider(Private) {
return fieldFormats.getInstance('percent') || fieldFormats.getDefaultInstance('number');
},
getValue: function (agg, bucket) {
// values for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we
// parse the keys and respond with the value that matches
return _.find(bucket[agg.parentId] && bucket[agg.parentId].values, function (value, key) {
return agg.key === parseFloat(key);
}) / 100;
return getPercentileValue(agg, bucket) / 100;
}
});
};
11 changes: 3 additions & 8 deletions src/ui/public/agg_types/metrics/percentiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import 'ui/number_list';
import AggTypesMetricsMetricAggTypeProvider from 'ui/agg_types/metrics/MetricAggType';
import AggTypesMetricsGetResponseAggConfigClassProvider from 'ui/agg_types/metrics/getResponseAggConfigClass';
import RegistryFieldFormatsProvider from 'ui/registry/field_formats';
export default function AggTypeMetricPercentilesProvider(Private) {
import getPercentileValue from './percentiles_get_value';

export default function AggTypeMetricPercentilesProvider(Private) {
var MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider);
var getResponseAggConfigClass = Private(AggTypesMetricsGetResponseAggConfigClassProvider);
var fieldFormats = Private(RegistryFieldFormatsProvider);
Expand Down Expand Up @@ -43,12 +44,6 @@ export default function AggTypeMetricPercentilesProvider(Private) {
return new ValueAggConfig(percent);
});
},
getValue: function (agg, bucket) {
// percentiles for 1, 5, and 10 will come back as 1.0, 5.0, and 10.0 so we
// parse the keys and respond with the value that matches
return _.find(bucket[agg.parentId] && bucket[agg.parentId].values, function (value, key) {
return agg.key === parseFloat(key);
});
}
getValue: getPercentileValue
});
};
7 changes: 7 additions & 0 deletions src/ui/public/agg_types/metrics/percentiles_get_value.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { find } from 'lodash';

export default function getPercentileValue(agg, bucket) {
const values = bucket[agg.parentId] && bucket[agg.parentId].values;
const percentile = find(values, value => agg.key === value.key);
return percentile ? percentile.value : NaN;
}

0 comments on commit 41a6fb0

Please sign in to comment.