Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] Enable new context constants in formula (#158452)
## Summary Fixes #151827, Fixes #117548 This PR contains constant function features in Lens formula: * direct exposure of the `time_range()` - as suggested in #117548) <img width="297" alt="Screenshot 2023-05-29 at 12 05 43" src="https://github.com/elastic/kibana/assets/924948/8dbd63a6-c5ec-4177-a4a2-cc0770a495bc"> * `interval()` (as intended in #151827) <img width="359" alt="Screenshot 2023-05-29 at 12 04 18" src="https://github.com/elastic/kibana/assets/924948/8c3a4637-bd23-4b4d-8a5f-36853ccbfee3"> * and `now()` (as suggested in [here](#112851 (comment))) functions in the formula input <img width="364" alt="Screenshot 2023-05-25 at 14 30 14" src="https://github.com/elastic/kibana/assets/924948/2137717b-44a0-4531-bcc2-1fbda40368ba"> A visual explanation of what each constant represent: <img width="677" alt="Screenshot 2023-05-29 at 11 56 16" src="https://github.com/elastic/kibana/assets/924948/b7b7e92c-b061-4cce-a77e-e7baeab323a8"> Documentation: <img width="546" alt="Screenshot 2023-05-31 at 12 59 40" src="https://github.com/elastic/kibana/assets/924948/1fea7e88-6e4f-4958-949f-6b71a770cd44"> Some example usage <img width="683" alt="Screenshot 2023-05-25 at 13 33 26" src="https://github.com/elastic/kibana/assets/924948/e03442ab-0062-4999-8a38-c00a66b3b13b"> TSVB => Lens with `params._interval` support: ![tsvb_to_lens_with_interval](https://github.com/elastic/kibana/assets/924948/6ea86bd1-8e71-4928-b2e2-7ad27537b33d) **Notes**: * context values work like static values, with the same limits, therefore it is not possible to build a date histogram with a context value alone (i.e. a formula with only `interval()` or `now()`). It works ok without the `Date Histogram` dimension. * The `interval()` function will report an error if used without a configured `Date Histogram` dimension: <img width="671" alt="Screenshot 2023-05-29 at 12 14 13" src="https://github.com/elastic/kibana/assets/924948/ca67f102-35bb-4e4d-ab16-15d1be4cadcc"> * The `interval()` function does not take into account different bucket interval size (i.e. DST changes, leap years, etc...), rather return the same value to all the buckets. This is the same behaviour as in TSVB, but in Lens it can be a problem due to the usage of `calendar_interval`. * I had to duplicate a couple of function from the helpers to avoid issues with tests. I've tried a different organization of the helpers (between pure vs impure fns) but that took longer than expected, so I would defer this task later in another PR. <details> <summary>General approach with `constant(...)` removed</summary> * a more general approach using `constants(value="...")` <img width="301" alt="Screenshot 2023-05-29 at 12 07 23" src="https://github.com/elastic/kibana/assets/924948/0a800aa4-8db5-4055-996d-344d37adfc01"> </details> A cloud deployment has been created to test both approaches here. Let me know which one do you prefer cc @elastic/kibana-visualizations ### Checklist Delete any items that are not applicable to this PR. - [ ] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] Any UI touched in this PR is usable by keyboard only (learn more about [keyboard accessibility](https://webaim.org/techniques/keyboard/)) - [ ] Any UI touched in this PR does not create any new axe failures (run axe in browser: [FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/), [Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US)) - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This renders correctly on smaller devices using a responsive layout. (You can test this [in your browser](https://www.browserstack.com/guide/responsive-testing-on-local-server)) - [ ] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### 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: | Risk | Probability | Severity | Mitigation/Notes | |---------------------------|-------------|----------|-------------------------| | Multiple Spaces—unexpected behavior in non-default Kibana Space. | Low | High | Integration tests will verify that all features are still supported in non-default Kibana Space and when user switches between spaces. | | Multiple nodes—Elasticsearch polling might have race conditions when multiple Kibana nodes are polling for the same tasks. | High | Low | Tasks are idempotent, so executing them multiple times will not result in logical error, but will degrade performance. To test for this case we add plenty of unit tests around this logic and document manual testing procedure. | | Code should gracefully handle cases when feature X or plugin Y are disabled. | Medium | High | Unit tests will verify that any feature flag or plugin combination still results in our service operational. | | [See more potential risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) | ### For maintainers - [ ] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: kibanamachine <[email protected]> Co-authored-by: Stratoula Kalafateli <[email protected]>
- Loading branch information