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] Implement time scaling function #82104

Merged
merged 8 commits into from
Nov 6, 2020

Conversation

flash1293
Copy link
Contributor

@flash1293 flash1293 commented Oct 30, 2020

Fixes #77692

Adds lens_time_scale function to scale numbers by time bucket.

The time scale function takes the following arguments:

  • inputColumnId, outputColumnId, outputColumnName (similar behavior to new expression time series functions)
  • targetUnit - unit to scale to
  • dateColumnId - column containing the start of the date bucket

This function fails if there is no meta data on the date column to determine the used time zone, time range and interval.

It builds on top of the getDateMetaByDatatableColumn added in a previous PR, but one change was necessary.

Right now, the applied time range is added to the column meta data using the input date math range (e.g. from now-24h to now). This is problematic because due to async search the time scale function could get triggered much later than the actual query hitting Elasticsearch - this would skew the size of the first and last bucket in the time range and produce wrong scaling for those buckets. By resolving the date range directly before sending the request to Elasticsearch and converting it into ISO strings for from and to, the time scaling will be very close to exact even for long running searches.

@flash1293
Copy link
Contributor Author

Jenkins, test this.

@flash1293 flash1293 added Feature:Lens Team:AppArch Team:Visualizations Visualization editors, elastic-charts and infrastructure release_note:skip Skip the PR/issue when compiling release notes v7.11.0 v8.0.0 labels Nov 3, 2020
@flash1293 flash1293 marked this pull request as ready for review November 3, 2020 16:14
@flash1293 flash1293 requested a review from a team November 3, 2020 16:14
@flash1293 flash1293 requested a review from a team as a code owner November 3, 2020 16:14
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-arch (Team:AppArch)

Copy link
Member

@lukeelmers lukeelmers left a comment

Choose a reason for hiding this comment

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

App arch code LGTM, just one testing nit

Comment on lines +109 to +110
from: '2020-10-05T00:00:00.000Z',
to: '2020-10-10T00:00:00.000Z',
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should also add a test for the new case that is introduced in this PR where we fall back to interval if the appliedTimeRange is undefined

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point - we always had this case but the types didn't reflect it. Actually it's an error case, I extended the condition to throw an error and added unit tests.

@flash1293
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@mbondyra mbondyra left a comment

Choose a reason for hiding this comment

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

LGTM, didn't test (I think tests are sufficient)

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

@kbn/optimizer bundle module count

id before after diff
lens 558 559 +1

async chunks size

id before after diff
lens 1.0MB 1.0MB +5.6KB

page load bundle size

id before after diff
data 954.8KB 955.3KB +563.0B
lens 49.7KB 49.9KB +143.0B
total +706.0B

History

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

@flash1293 flash1293 merged commit 94d0e60 into elastic:master Nov 6, 2020
flash1293 added a commit to flash1293/kibana that referenced this pull request Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Expression function to scale numbers to a specific time interval
5 participants