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 time shift #101718

Merged
merged 306 commits into from
Jun 17, 2021
Merged

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Jun 9, 2021

Fixes #35043

Adds time shift support to formula.

You can use time shift on all Elasticsearch functions (average, sum etc.) - the parameter is called shift and takes the same input as the "Time shift" advanced option for quick functions. Inputs than won't parse (like 3ds instead of 3d) will cause a formula error and won't render. Time shifts which are not aligned with the date histogram interval will cause a formula warning but will be treated as value and render as usual.

wylieconlon and others added 30 commits March 3, 2021 19:03
@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
@elasticmachine
Copy link
Contributor

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

@flash1293
Copy link
Contributor Author

@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.

I'm seeing an inconsistent warning count when transitioning from a Count with shift to a formula, then changing the interval:

Screen Shot 2021-06-14 at 4 30 48 PM

@@ -603,6 +607,8 @@ export function DimensionEditor(props: DimensionEditorProps) {
const formulaTab = ParamEditor ? (
<ParamEditor
layer={state.layers[layerId]}
layerId={layerId}
activeData={props.activeData}
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it'll cause extra re-renders of the formula panel and all the others, any idea how much of an impact this has?

extraArgs += i18n.translate('xpack.lens.formula.shiftExtraArguments', {
defaultMessage: '[shift]?: string',
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic here breaks when transitioning to a shifted count when using the en-xa locale, it produces count(Recordsshift='3h') instead of count(shift='3h'). Maybe we're doing some string equality?

Copy link
Contributor

@dej611 dej611 left a comment

Choose a reason for hiding this comment

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

Screenshot 2021-06-15 at 11 42 11

Because now an extra argument is allowed on functions, the lucene suggestion is coming even where a kql query has been already put in place.
Would it be possible to remove it? There's already a validation error, but it would be nice to not promote it.

Also, I was wondering if we could improve something on this side: not a blocker but the helping tooltip is not pointing to the right direction at least.
Screenshot 2021-06-15 at 11 41 19

@flash1293
Copy link
Contributor Author

flash1293 commented Jun 15, 2021

@dej611 @wylieconlon

Addressed the following points:

  • Did the same warnings for formula and chart
  • Calculate the important bit (date histogram interval) outside of the formula editor memoize boundary
  • Fixed the logic for looking up the field name - it was looking for a hard-coded "Records" - changed that to look at the operation type instead
  • Do not show lucene if kql got added already
  • Improve error message for invalid time shift in the formula

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@flash1293 flash1293 requested review from wylieconlon and dej611 June 16, 2021 08:30
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.

LGTM, the performance impact of the extra re-renders appears to be minimal.

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
lens 690 691 +1

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.5MB 1.5MB +4.7KB

History

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

Copy link
Contributor

@dej611 dej611 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. Tested again and found no more issues 👍

@flash1293 flash1293 merged commit 84e8676 into elastic:master Jun 17, 2021
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 17, 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: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.

Month over month calculation in visualizations
6 participants