Skip to content
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

[Lens] Formula overall functions #99461

Merged
merged 302 commits into from
Jun 16, 2021
Merged

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented May 6, 2021

Fixes #94597

Adds new formula functions:
overall_sum, overall_min, overall_max, overall_average

They calculate the respective overall metric for the current series. If there are no separate series, it's calculating the overall metric by all rows. A series is defined by a histogram or date histogram dimension.
Examples

  • Dimensions: (Date) histogram, top values of fieldA, top values of fieldB - overall_sum will group by both fieldA and fieldB values
  • Dimensions: top values of fieldA, top values of fieldB - overall_sum will create one large single group
  • Dimensions: (Date) histogram - overall_sum will create one large single group

Example use cases

Percentage of sum over a number histogram (this is the o11y use case)
Screenshot 2021-05-06 at 12 12 26

Divergence from the mean overall:
Screenshot 2021-05-06 at 12 14 05

Divergence from the mean over time (separate for each series):
Screenshot 2021-05-06 at 12 13 35

Relative percent range over time (separate for each series):
Screenshot 2021-05-06 at 13 36 57

What do you think @ghudgins @dej611 @mbondyra @wylieconlon ?

dej611 and others added 30 commits March 3, 2021 17:42
@wylieconlon wylieconlon mentioned this pull request Jun 10, 2021
14 tasks
@flash1293 flash1293 marked this pull request as ready for review June 10, 2021 16:49
@flash1293 flash1293 requested a review from a team June 10, 2021 16:49
@flash1293 flash1293 requested a review from a team as a code owner June 10, 2021 16:49
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@botelastic botelastic bot added the Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) label Jun 14, 2021
Copy link
Member

@ppisljar ppisljar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code LGTM

movingAverage,
mapColumn,
math,
];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This style was removed last week, instead you should move this list into src/plugins/expressions/common/service/expressions_services.ts.

inputTypes: ['datatable'],

help: i18n.translate('expressions.functions.overallSum.help', {
defaultMessage: 'Calculates the overall sum of a column in a data table',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doc still calls it "overall sum" instead of talking about the 4 possible functions. The same goes for most of the other i18n help strings here. Please update them all

case 'average':
valueCounter[bucketIdentifier] = (valueCounter[bucketIdentifier] ?? 0) + 1;
case 'sum':
accumulators[bucketIdentifier] = accumulatorValue + Number(currentValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you're handling array-value fields in average but not in sum, is that right? Will this fail for array values, or null?

selectionStyle: 'hidden',
requiredReferences: [
{
input: ['field', 'managedReference'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it could take a fullReference as input, not entirely sure whether it should. Thoughts?

return true;
},

filterable: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is not filterable, why is there logic to pass KQL from the previous to this column?

operationType: 'overall_max';
};

export const overallMaxOperation: OperationDefinition<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there such a big difference between each overall function that they need to be in separate files? It looks to me like the main difference is the text, but we could generate these functions the same as we generate the simple metrics?

const nonHistogramColumns = buckets.filter(
(colId) =>
layer.columns[colId].operationType !== 'date_histogram' &&
layer.columns[colId].operationType !== 'range'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of unusual to exclude range operations from this, it's not something we do for the other group-by logic. I think this should be consistent with the rest so I'm inclined to remove the range filter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this so it's possible to use overall calculations on number histograms. I think it makes sense because number histograms are often a distribution of some sort and it makes sense to treat it as a single data series in respect to overall calculation. This is an important use case for o11y.

@flash1293
Copy link
Contributor Author

@wylieconlon I think I addressed all of your comments, could you check again? It's also handling array values now.

@flash1293 flash1293 requested a review from wylieconlon June 15, 2021 12:36
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
expressions 156 157 +1
lens 687 688 +1
total +2

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
expressions 1469 1508 +39

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
lens 1.4MB 1.4MB +7.0KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
expressions 202.8KB 206.1KB +3.2KB
Unknown metric groups

API count

id before after diff
expressions 1896 1936 +40

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@wylieconlon wylieconlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM! Now we can update the docs for overall functions

@flash1293 flash1293 merged commit 4180a02 into elastic:master Jun 16, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 16, 2021
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Feature:Lens release_note:enhancement Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.14.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Formula: Overall metrics
8 participants