-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Conversation
…a into lens/formula-error-handling
Pinging @elastic/kibana-app (Team:KibanaApp) |
@elasticmachine merge upstream |
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.
code LGTM
movingAverage, | ||
mapColumn, | ||
math, | ||
]; |
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.
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', |
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.
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); |
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.
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'], |
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.
Seems like it could take a fullReference
as input, not entirely sure whether it should. Thoughts?
return true; | ||
}, | ||
|
||
filterable: false, |
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.
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< |
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.
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' |
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.
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.
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.
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.
@wylieconlon I think I addressed all of your comments, could you check again? It's also handling array values now. |
💚 Build SucceededMetrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
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.
Changes LGTM! Now we can update the docs for overall functions
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
Co-authored-by: Joe Reuter <[email protected]>
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
overall_sum
will group by both fieldA and fieldB valuesoverall_sum
will create one large single groupoverall_sum
will create one large single groupExample use cases
Percentage of sum over a number histogram (this is the o11y use case)

Divergence from the mean overall:

Divergence from the mean over time (separate for each series):

Relative percent range over time (separate for each series):

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