-
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] Absolute time shift support in formula #144564
Conversation
Pinging @elastic/kibana-visualizations @elastic/kibana-visualizations-external (Team:Visualizations) |
This is probably debatable, but is it anchoring the right way?
|
Another considerations about the negative shift case - maybe we should allow it because with static anchor it's easy to change the time range and run into the error. For example you look at the last week with a reference time frame from last month (that works fine). However when trying to check a week from last year, you would get an error because it's a negative time shift now. Not sure whether relevant, we can also split that out |
That's a good point. I've assumed that I've updated the PR to work the other way around. |
I've introduced a stricter check now on these cases. I see how it can be useful if the reference time range is in the past, but there's no easy way to make a proper distinction of cases. |
On the matter I've had a chat offline with @markov00 and the notation format is something confusing/not fully clear (is the At first something like |
Thanks @stratoula for the feedback, managed to reproduce this. I've forgotten to pass the new interval in this case and the error is not propagated to the chart. Will fix this ASAP.
Good catch! Managed to reproduce it. On it! |
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.
Thanx for the fix Marco. This looks much better now. Do you think we could document it?
If I type shift it suggests me relative shifts and not the startAt/endAt (which I like tbh but how the users can know about this addition?) If we dont' add this on autocomplete but add a note on our documentation? Wdyt?
The autosuggests for the absolute time shift kicks in after the |
@stratoula I've changed the autocomplete logic to be more user friendly:
Would that work for you? |
Yes Marco! Much better now! Thanx |
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 saw Data Discovery was requested on this, so a quick code-only review. I don't really have the context needed to review properly, but the code, comments, and tests for parse_time_shift
LGTM.
We share ownership of the data
plugin now anyway, so I think @stratoula's approval is most important here anyway 👍
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.
Minor nit but otherwise LGTM! Code review
const anchoredTimeShiftRegexp = /^(startAt|endAt)\((.+)\)$/; | ||
const durationRegexp = /^(\d+)\s*(\w)$/; | ||
const invalidDate = 'invalid'; | ||
const previousDate = 'previous'; |
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.
Nit: Prefer upper case for constants (e.g. `const PREVIOUS_DATE = 'previous';)
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Public APIs missing comments
Async chunks
Page load bundle
Unknown metric groupsAPI count
ESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
Closes #102493
This PR introduces the ability to define an absolute time shift as a new type of time shift in Lens.
The idea is to avoid to push down the absolute logic to the agg level, rather translate as soon as possible the absolute shift into a relative one (in seconds, the minimal time unit allowed) and perform all checks in this format.
Note:
The feature is currently enabled as formula-only and using it in a Quick function context will validate it as an invalid shift.
Details:
The used format for anchoring right now is:
startAt(2022-11-03T18:30:27.278Z)
for start anchoring (from the given date used asstart
anchor forward to a dynamic end date), andendAt(2022-11-03T18:30:27.278Z)
for end anchoring (from the given date backward to a start date dynamically computed)Basics
Implementation details
While the range is computed correctly based on the current interval, the actual shift is rounded to prevent issues on data fetching. The interval is computed with an algorithm similar to the one used by ES and the shift is offset to the closest multiple of that interval (i.e. if the current shift is
1.78
times the interval, then the shift is rounded to2
intervals in a way to include the given date).Checklist
Delete any items that are not applicable to this PR.
Risk Matrix
Delete this section if it is not applicable to this PR.
Before closing this PR, invite QA, stakeholders, and other developers to identify risks that should be tested prior to the change/feature release.
When forming the risk matrix, consider some of the following examples and how they may potentially impact the change:
For maintainers