-
Notifications
You must be signed in to change notification settings - Fork 8.6k
derivative metric aggregation #10020
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
f83a3af
updating agg_config to allow adding parent aggregations
ppisljar c04b6c9
derivative metric aggregation
ppisljar 0698336
disable on metric and tagcloud
ppisljar 69a5329
fixing point series to correctly handle missing y values
ppisljar 85c0b46
adding unit tests
ppisljar 20ae746
fix broken ui
ppisljar 7402c6c
removing percentile ranks
ppisljar 40af4a3
updating based on review
ppisljar 1d5e0c3
fixing bug and adding make_nested_label tests
ppisljar affdef6
fixing error
ppisljar b043ce1
fixing test
ppisljar 8b321d6
fixing based on last review
ppisljar 32e75cc
fixing based on thomas review
ppisljar 1754424
allow nested aggs
ppisljar ea7c055
prevent sorting on derivative metric
ppisljar acb11d8
updating based on last review
ppisljar 4dc6af6
adding error message when histogram is not the last bucket
ppisljar ff4777f
fixing test
ppisljar dc1133b
updating error message
ppisljar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
src/ui/public/agg_types/__tests__/metrics/derivative.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| import _ from 'lodash'; | ||
| import expect from 'expect.js'; | ||
| import ngMock from 'ng_mock'; | ||
| import DerivativeProvider from 'ui/agg_types/metrics/derivative'; | ||
| import VisProvider from 'ui/vis'; | ||
| import StubbedIndexPattern from 'fixtures/stubbed_logstash_index_pattern'; | ||
|
|
||
| describe('Derivative metric', function () { | ||
| let aggDsl; | ||
| let derivativeMetric; | ||
| let aggConfig; | ||
|
|
||
| function init(settings) { | ||
| ngMock.module('kibana'); | ||
| ngMock.inject(function (Private) { | ||
| const Vis = Private(VisProvider); | ||
| const indexPattern = Private(StubbedIndexPattern); | ||
| derivativeMetric = Private(DerivativeProvider); | ||
|
|
||
| const params = settings || { | ||
| metricAgg: '1', | ||
| customMetric: null | ||
| }; | ||
|
|
||
| const vis = new Vis(indexPattern, { | ||
| title: 'New Visualization', | ||
| type: 'metric', | ||
| params: { | ||
| fontSize: 60, | ||
| handleNoResults: true | ||
| }, | ||
| aggs: [ | ||
| { | ||
| id: '1', | ||
| type: 'count', | ||
| schema: 'metric' | ||
| }, | ||
| { | ||
| id: '2', | ||
| type: 'derivative', | ||
| schema: 'metric', | ||
| params | ||
| } | ||
| ], | ||
| listeners: {} | ||
| }); | ||
|
|
||
| // Grab the aggConfig off the vis (we don't actually use the vis for anything else) | ||
| aggConfig = vis.aggs[1]; | ||
| aggDsl = aggConfig.toDsl(); | ||
| }); | ||
| } | ||
|
|
||
| it('should return a label prefixed with Derivative of', function () { | ||
| init(); | ||
| expect(derivativeMetric.makeLabel(aggConfig)).to.eql('Derivative of Count'); | ||
| }); | ||
|
|
||
| it('should return a label Derivative of max bytes', function () { | ||
| init({ | ||
| metricAgg: 'custom', | ||
| customMetric: { | ||
| id:'1-orderAgg', | ||
| type: 'max', | ||
| params: { field: 'bytes' }, | ||
| schema: 'orderAgg' | ||
| } | ||
| }); | ||
| expect(derivativeMetric.makeLabel(aggConfig)).to.eql('Derivative of Max bytes'); | ||
| }); | ||
|
|
||
| it('should return a label prefixed with number of derivative', function () { | ||
| init({ | ||
| metricAgg: 'custom', | ||
| customMetric: { | ||
| id:'2-orderAgg', | ||
| type: 'derivative', | ||
| params: { | ||
| buckets_path: 'custom', | ||
| customMetric: { | ||
| id:'2-orderAgg-orderAgg', | ||
| type: 'count', | ||
| schema: 'orderAgg' | ||
| } | ||
| }, | ||
| schema: 'orderAgg' | ||
| } | ||
| }); | ||
| expect(derivativeMetric.makeLabel(aggConfig)).to.eql('2. derivative of Count'); | ||
| }); | ||
|
|
||
| it('should set parent aggs', function () { | ||
| init({ | ||
| metricAgg: 'custom', | ||
| customMetric: { | ||
| id:'2-metric', | ||
| type: 'max', | ||
| params: { field: 'bytes' }, | ||
| schema: 'orderAgg' | ||
| } | ||
| }); | ||
| expect(aggDsl.derivative.buckets_path).to.be('2-metric'); | ||
| expect(aggDsl.parentAggs['2-metric'].max.field).to.be('bytes'); | ||
| }); | ||
|
|
||
| it('should set nested parent aggs', function () { | ||
| init({ | ||
| metricAgg: 'custom', | ||
| customMetric: { | ||
| id:'2-metric', | ||
| type: 'derivative', | ||
| params: { | ||
| buckets_path: 'custom', | ||
| customMetric: { | ||
| id:'2-metric-metric', | ||
| type: 'max', | ||
| params: { field: 'bytes' }, | ||
| schema: 'orderAgg' | ||
| } | ||
| }, | ||
| schema: 'orderAgg' | ||
| } | ||
| }); | ||
| expect(aggDsl.derivative.buckets_path).to.be('2-metric'); | ||
| expect(aggDsl.parentAggs['2-metric'].derivative.buckets_path).to.be('2-metric-metric'); | ||
| }); | ||
|
|
||
| }); |
34 changes: 34 additions & 0 deletions
34
src/ui/public/agg_types/__tests__/metrics/lib/make_nested_label.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import expect from 'expect.js'; | ||
| import { makeNestedLabel } from 'ui/agg_types/metrics/lib/make_nested_label'; | ||
|
|
||
| describe('metric agg make_nested_label', function () { | ||
|
|
||
| function generateAggConfig(metricLabel) { | ||
| return { | ||
| params: { | ||
| customMetric: { | ||
| makeLabel: () => { return metricLabel; } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| it('should return a metric label with prefix', function () { | ||
| const aggConfig = generateAggConfig('Count'); | ||
| const label = makeNestedLabel(aggConfig, 'derivative'); | ||
| expect(label).to.eql('Derivative of Count'); | ||
| }); | ||
|
|
||
| it('should return a numbered prefix', function () { | ||
| const aggConfig = generateAggConfig('Derivative of Count'); | ||
| const label = makeNestedLabel(aggConfig, 'derivative'); | ||
| expect(label).to.eql('2. derivative of Count'); | ||
| }); | ||
|
|
||
| it('should return a prefix with correct order', function () { | ||
| const aggConfig = generateAggConfig('3. derivative of Count'); | ||
| const label = makeNestedLabel(aggConfig, 'derivative'); | ||
| expect(label).to.eql('4. derivative of Count'); | ||
| }); | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <div ng-controller="aggParam.controller"> | ||
| <div class="form-group"> | ||
| <label>Metric</label> | ||
| <select | ||
| name="metricAgg" | ||
| ng-model="agg.params.metricAgg" | ||
| required | ||
| class="form-control"> | ||
| <option | ||
| ng-repeat="respAgg in responseValueAggs track by respAgg.id" | ||
| value="{{respAgg.id}}" | ||
| ng-if="respAgg.type.name !== agg.type.name" | ||
| ng-disabled="isDisabledAgg(respAgg)" | ||
| ng-selected="agg.params.metricAgg === respAgg.id"> | ||
| metric: {{safeMakeLabel(respAgg)}} | ||
| </option> | ||
| <option value="custom" ng-selected="agg.params.metricAgg === 'custom'"> | ||
| Custom Metric | ||
| </option> | ||
| </select> | ||
| </div> | ||
| <div ng-if="agg.params.metricAgg === 'custom'" class="vis-editor-agg-order-agg"> | ||
| <ng-form name="customMetricForm"> | ||
| <vis-editor-agg-params | ||
| agg="agg.params.customMetric" | ||
| group-name="'metrics'"> | ||
| </vis-editor-agg-params> | ||
| </ng-form> | ||
| </div> | ||
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import AggTypesMetricsMetricAggTypeProvider from 'ui/agg_types/metrics/metric_agg_type'; | ||
| import metricAggTemplate from 'ui/agg_types/controls/sub_agg.html'; | ||
| import _ from 'lodash'; | ||
| import VisAggConfigProvider from 'ui/vis/agg_config'; | ||
| import VisSchemasProvider from 'ui/vis/schemas'; | ||
| import { makeNestedLabel } from './lib/make_nested_label'; | ||
| import { parentPipelineAggController } from './lib/parent_pipeline_agg_controller'; | ||
| import { parentPipelineAggWritter } from './lib/parent_pipeline_agg_writter'; | ||
|
|
||
| export default function AggTypeMetricDerivativeProvider(Private) { | ||
| const MetricAggType = Private(AggTypesMetricsMetricAggTypeProvider); | ||
| const AggConfig = Private(VisAggConfigProvider); | ||
| const Schemas = Private(VisSchemasProvider); | ||
|
|
||
| const aggFilter = ['!top_hits', '!percentiles', '!percentile_ranks', '!median', '!std_dev']; | ||
| const orderAggSchema = (new Schemas([ | ||
| { | ||
| group: 'none', | ||
| name: 'orderAgg', | ||
| title: 'Order Agg', | ||
| aggFilter: aggFilter | ||
| } | ||
| ])).all[0]; | ||
|
|
||
| return new MetricAggType({ | ||
| name: 'derivative', | ||
| title: 'Derivative', | ||
| makeLabel: agg => makeNestedLabel(agg, 'derivative'), | ||
| params: [ | ||
| { | ||
| name: 'customMetric', | ||
| type: AggConfig, | ||
| default: null, | ||
| serialize: function (customMetric) { | ||
| return customMetric.toJSON(); | ||
| }, | ||
| deserialize: function (state, agg) { | ||
| return this.makeAgg(agg, state); | ||
| }, | ||
| makeAgg: function (termsAgg, state) { | ||
| state = state || { type: 'count' }; | ||
| state.schema = orderAggSchema; | ||
| const metricAgg = new AggConfig(termsAgg.vis, state); | ||
| metricAgg.id = termsAgg.id + '-metric'; | ||
| return metricAgg; | ||
| }, | ||
| write: _.noop | ||
| }, | ||
| { | ||
| name: 'buckets_path', | ||
| write: _.noop | ||
| }, | ||
| { | ||
| name: 'metricAgg', | ||
| editor: metricAggTemplate, | ||
| default: 'custom', | ||
| controller: parentPipelineAggController, | ||
| write: parentPipelineAggWritter | ||
| } | ||
| ] | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import _ from 'lodash'; | ||
|
|
||
| const makeNestedLabel = function (aggConfig, label) { | ||
| const uppercaseLabel = _.startCase(label); | ||
| if (aggConfig.params.customMetric) { | ||
| let metricLabel = aggConfig.params.customMetric.makeLabel(); | ||
| if (metricLabel.includes(`${uppercaseLabel} of `)) { | ||
| metricLabel = metricLabel.substring(`${uppercaseLabel} of `.length); | ||
| metricLabel = `2. ${label} of ${metricLabel}`; | ||
| } | ||
| else if (metricLabel.includes(`${label} of `)) { | ||
| metricLabel = (parseInt(metricLabel.substring(0, 1)) + 1) + metricLabel.substring(1); | ||
| } | ||
| else { | ||
| metricLabel = `${uppercaseLabel} of ${metricLabel}`; | ||
| } | ||
| return metricLabel; | ||
| } | ||
| const metric = aggConfig.vis.aggs.find(agg => agg.id === aggConfig.params.metricAgg); | ||
| return `${uppercaseLabel} of ${metric.makeLabel()}`; | ||
| }; | ||
|
|
||
| export { makeNestedLabel }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd want to exclude the derivate aggregation from
tile_map.jsas well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its already excluded as tile map defines which aggs to use (incontrary to here where which aggs not to use are defined)