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] Random sampling feature #143221

Merged
merged 28 commits into from
Oct 24, 2022
Merged

[Lens] Random sampling feature #143221

merged 28 commits into from
Oct 24, 2022

Conversation

dej611
Copy link
Contributor

@dej611 dej611 commented Oct 12, 2022

Summary

Closes #142958

This PR introduces the random sampling feature in Lens, as a layer setting.

Main features in the PR:

  • Add a new Layer Settings action/panel
  • Add a new Random sampling feature for each layer
  • Refactored DimensionContainer to be reusable across Lens

random_sampling

Todo list:

  • Refactor DimensionContainer to be a reusable flyout component

    • make DimensionEditor use the new flyout component
  • Layer settings
    Screenshot 2022-10-19 at 10 50 29

    • Enable on Data layers
    • Add tech preview tag to it (used lab icon + tooltip)
      Screenshot 2022-10-19 at 10 51 53
    • Add some basic documentation
    • Refactor action to be within the datasource
    • Make it work for Reference lines layer
    • Make it work for Annotations? No.
  • Remove random_sampler agg (originally ported from [Lens] Random sampling #142980)

  • Inject probability into aggConfigs and use it when less than 1

    • Fix case when aggs have no DSL to inject
  • Use SearchSessionId as sampler seed

    • Check Other terms agg
  • Check time shift when sampling

    • revisit doc_count
  • Add tests

  • Add functional tests

  • 🐛 There's a weird bug I could not reproduce reliably when switching from a date histogram to a Top values as sampling is enabled and some expression fails.

Some testing behaviour

  • Duplicating a layer should carry the current sampling value to the new layer
  • Dropping a field into the workspace when no layer is configured should not change the set sampling rate (set it before dropping the field)
  • Clearing layer should reset the sampling
  • When using Terms with Other option enabled check the Inspector that both requests are using the same seed

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:

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

For maintainers

@dej611 dej611 added Team:Visualizations Visualization editors, elastic-charts and infrastructure Feature:Lens v8.6.0 labels Oct 12, 2022
@@ -16,6 +16,15 @@ import type { DataView } from '@kbn/data-views-plugin/common';
import { stubIndexPattern } from '../../stubs';
import { IEsSearchResponse } from '..';

// Mute moment.tz warnings about not finding a mock timezone
jest.mock('../utils', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Debugging test failures was really hard with all warning from moment.tz. This fixed the issue assigning a fixed (supported) timezone for moment.

@@ -427,11 +427,11 @@ export function insertTimeShiftSplit(
const timeRange = aggConfigs.timeRange;
const filters: Record<string, unknown> = {};
const timeField = aggConfigs.timeFields[0];
const timeFilter = getTime(aggConfigs.indexPattern, timeRange, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This computation could be done once for all the timeShifts

@dej611 dej611 marked this pull request as ready for review October 19, 2022 12:48
@dej611 dej611 requested review from a team as code owners October 19, 2022 12:48
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-vis-editors @elastic/kibana-vis-editors-external (Team:VisEditors)

Copy link
Contributor

@flash1293 flash1293 left a comment

Choose a reason for hiding this comment

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

Tested and everything works as expected, LGTM. Still think we should add some in-product documentation, but we can do that as a follow-up

Copy link
Contributor

@MichaelMarcialis MichaelMarcialis left a comment

Choose a reason for hiding this comment

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

Hey, @dej611! I've left you a few small comments for your review. As none of them are super critical, assuming you're able to address them, I'll go ahead and approve this now so I don't hold you up further.

Just for the sake of visibility, the plan is to follow this with another PR to address the following items that @dej611, @KOTungseth, and I have discussed:

  • Switch the slider's EuiFormRow from columnCompressed to rowCompressed to allow the slider to expand to the full available width of the flyout.
  • Show "Speed" and "Accuracy" labels at each of the slider's respective extremities to emphasize what is happening.
  • Change the slider's tick numbers to percentages for easier reading.
  • Update help text below the slider to briefly explaining what this feature does (supplied by @KOTungseth) and include a link to the full documentation.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
data 520 521 +1
lens 943 959 +16
total +17

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
data 2517 2523 +6
lens 576 581 +5
total +11

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.3MB 1.3MB +10.9KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
lens 46 47 +1

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
data 437.6KB 439.0KB +1.4KB
lens 29.2KB 29.2KB +1.0B
total +1.4KB
Unknown metric groups

API count

id before after diff
data 3245 3251 +6
lens 669 674 +5
total +11

History

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

isSamplingEnabled() {
return (
isSamplingEnabled(this.opts.probability) &&
this.getRequestAggs().filter((agg) => !agg.type.hasNoDsl).length > 0
Copy link
Contributor

Choose a reason for hiding this comment

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

Trying to follow...
Could you please explain this condition?

this.getRequestAggs().filter((agg) => !agg.type.hasNoDsl).length > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That condition is set to detect a specific case when no sub-agg is available for the sampling, therefore it makes no sense to have it. That's the case of Count of Records in Lens, where it should just return the number of documents.

Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

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

App services code lgtm

@dej611 dej611 merged commit 9d819ba into elastic:main Oct 24, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Oct 24, 2022
@dej611 dej611 deleted the feature/142958 branch October 25, 2022 07:58
@dej611 dej611 mentioned this pull request Oct 25, 2022
9 tasks
drewdaemon pushed a commit to drewdaemon/kibana that referenced this pull request Oct 25, 2022
* ✨ First pass with UI for random sampling

* ✨ Initial working version

* 🔥 Remove unused stuff

* 🔧 Refactor layer settings panel

* 🐛 Fix terms other query and some refactor

* 🏷️ Fix types issues

* 🐛 Fix sampling for other terms agg

* 🐛 Fix issue with count operation

* ✅ Fix jest tests

* 🐛 fix test stability

* 🐛 fix test with newer params

* 💄 Add tech preview label

* ✅ Add new tests for sampling

* ✅ Add more tests

* ✅ Add new test for suggestions

* ✅ Add functional tests for layer actions and random sampling

* Update x-pack/plugins/lens/public/datasources/form_based/layer_settings.tsx

Co-authored-by: Michael Marcialis <michael@marcial.is>

* 👌 Integrated design feedback

Co-authored-by: Joe Reuter <johannes.reuter@elastic.co>
Co-authored-by: Michael Marcialis <michael@marcial.is>
@stratoula stratoula added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:enhancement labels Nov 14, 2022
@KOTungseth KOTungseth mentioned this pull request Apr 25, 2023
19 tasks
KOTungseth added a commit that referenced this pull request May 23, 2023
## Summary

Adds the 8.8 documentation for the following:

- Enable report sharing: #153429
Docs preview:
https://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/reporting-getting-started.html

- Random sampling feature: #143221
Docs preview:
https://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#improve-visualization-loading-time

- Improve Ignore global filters UI:
#154441 and
#155280
Docs preview:
https://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#add-annotations

---------

Co-authored-by: Tim Sullivan <tsullivan@users.noreply.github.com>
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request May 23, 2023
## Summary

Adds the 8.8 documentation for the following:

- Enable report sharing: elastic#153429
Docs preview:
https://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/reporting-getting-started.html

- Random sampling feature: elastic#143221
Docs preview:
https://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#improve-visualization-loading-time

- Improve Ignore global filters UI:
elastic#154441 and
elastic#155280
Docs preview:
https://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#add-annotations

---------

Co-authored-by: Tim Sullivan <tsullivan@users.noreply.github.com>
(cherry picked from commit 06a800f)
kibanamachine added a commit that referenced this pull request May 23, 2023
# Backport

This will backport the following commits from `main` to `8.8`:
- [[DOCS] Adds 8.8 Viz docs
(#157215)](#157215)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Kaarina
Tungseth","email":"kaarina.tungseth@elastic.co"},"sourceCommit":{"committedDate":"2023-05-23T15:41:42Z","message":"[DOCS]
Adds 8.8 Viz docs (#157215)\n\n## Summary\r\n\r\nAdds the 8.8
documentation for the following:\r\n\r\n- Enable report sharing:
#153429
preview:\r\nhttps://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/reporting-getting-started.html\r\n\r\n-
Random sampling feature:
#143221
preview:\r\nhttps://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#improve-visualization-loading-time\r\n\r\n-
Improve Ignore global filters
UI:\r\nhttps://github.com//pull/154441
and\r\nhttps://github.com//pull/155280\r\nDocs
preview:\r\nhttps://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#add-annotations\r\n\r\n---------\r\n\r\nCo-authored-by:
Tim Sullivan
<tsullivan@users.noreply.github.com>","sha":"06a800fbad1f2a8fd9146bfe0c439e2107f771fc","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Docs","release_note:skip","Team:SharedUX","v8.8.0","v8.9.0"],"number":157215,"url":"#157215
Adds 8.8 Viz docs (#157215)\n\n## Summary\r\n\r\nAdds the 8.8
documentation for the following:\r\n\r\n- Enable report sharing:
#153429
preview:\r\nhttps://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/reporting-getting-started.html\r\n\r\n-
Random sampling feature:
#143221
preview:\r\nhttps://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#improve-visualization-loading-time\r\n\r\n-
Improve Ignore global filters
UI:\r\nhttps://github.com//pull/154441
and\r\nhttps://github.com//pull/155280\r\nDocs
preview:\r\nhttps://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#add-annotations\r\n\r\n---------\r\n\r\nCo-authored-by:
Tim Sullivan
<tsullivan@users.noreply.github.com>","sha":"06a800fbad1f2a8fd9146bfe0c439e2107f771fc"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"#157215
Adds 8.8 Viz docs (#157215)\n\n## Summary\r\n\r\nAdds the 8.8
documentation for the following:\r\n\r\n- Enable report sharing:
#153429
preview:\r\nhttps://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/reporting-getting-started.html\r\n\r\n-
Random sampling feature:
#143221
preview:\r\nhttps://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#improve-visualization-loading-time\r\n\r\n-
Improve Ignore global filters
UI:\r\nhttps://github.com//pull/154441
and\r\nhttps://github.com//pull/155280\r\nDocs
preview:\r\nhttps://kibana_157215.docs-preview.app.elstc.co/guide/en/kibana/master/lens.html#add-annotations\r\n\r\n---------\r\n\r\nCo-authored-by:
Tim Sullivan
<tsullivan@users.noreply.github.com>","sha":"06a800fbad1f2a8fd9146bfe0c439e2107f771fc"}}]}]
BACKPORT-->

Co-authored-by: Kaarina Tungseth <kaarina.tungseth@elastic.co>
delanni pushed a commit to delanni/kibana that referenced this pull request May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Lens release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v8.6.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Lens] Random sampling
8 participants