Skip to content

[ML] Adds cache for data recognizer module configs to reduce number of privilege checks#126338

Merged
jgowdyelastic merged 4 commits intoelastic:mainfrom
jgowdyelastic:adding-data-recognizer-config-cache
Mar 7, 2022
Merged

[ML] Adds cache for data recognizer module configs to reduce number of privilege checks#126338
jgowdyelastic merged 4 commits intoelastic:mainfrom
jgowdyelastic:adding-data-recognizer-config-cache

Conversation

@jgowdyelastic
Copy link
Copy Markdown
Member

@jgowdyelastic jgowdyelastic commented Feb 24, 2022

Adding a cache for modules loaded from disk and from the saved objects index.
The modules on disk and in the saved objects will not change in the time frame that each DataRecognizer instance exist.

By retrieving the modules from a cache for subsequent calls to _loadConfigs, the total number privileges checks caused by the saved object loading is drastically reduced.

image

vs

image

Fixes #125913

@jgowdyelastic jgowdyelastic added bug Fixes for quality problems that affect the customer experience release_note:fix :ml Feature:Anomaly Detection ML anomaly detection v8.2.0 labels Feb 24, 2022
@jgowdyelastic jgowdyelastic self-assigned this Feb 24, 2022
@jgowdyelastic jgowdyelastic requested a review from a team as a code owner February 24, 2022 12:27
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/ml-ui (:ml)

@peteharverson peteharverson requested a review from walterra March 2, 2022 15:11
Copy link
Copy Markdown
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

LGTM

private _resultsService: ReturnType<typeof resultsServiceProvider>;
private _calculateModelMemoryLimit: ReturnType<typeof calculateModelMemoryLimitProvider>;

private _configCache: Config[] | null = null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we invalidate this cache if the saved object configs have been changed?

Copy link
Copy Markdown
Member Author

@jgowdyelastic jgowdyelastic Mar 7, 2022

Choose a reason for hiding this comment

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

As I mentioned in the description

The modules on disk and in the saved objects will not change in the time frame that each DataRecognizer instance exist.

Each instance of the DataRecognizer exists for one endpoint call. The modules on disk will not change in that time frame. The modules in the saved object could theoretically change if someone installs a fleet module at the exact same time, but IMO it is very unlikely.

The _has_privileges calls were all happening from inside the saved object client and so I imagine adding a check to see if the saved objects have changed each loop would reintroduce them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggestion: It would be great if we could add some of the PR description and this explanation as comments to the code so the reasoning is also documented there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added in 561d3ad

@jgowdyelastic
Copy link
Copy Markdown
Member Author

@elasticmachine merge upstream

Copy link
Copy Markdown
Contributor

@walterra walterra 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, did a local test and verified the improvement in APM compared to main . Just added a comment about potentially adding some comments to the code.

@kibana-ci
Copy link
Copy Markdown

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

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

cc @jgowdyelastic

@jgowdyelastic jgowdyelastic merged commit 0640782 into elastic:main Mar 7, 2022
@jgowdyelastic jgowdyelastic deleted the adding-data-recognizer-config-cache branch March 7, 2022 18:33
jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 8, 2022
…ed-unexpectedly-error

* 'main' of github.com:elastic/kibana: (46 commits)
  Fix copy and pasted renderer user_name test (elastic#126663)
  [Gauge] Vis editors gauge legacy percent mode. (elastic#126318)
  Remove all cases related code from timelines (elastic#127003)
  Hide Enterprise search panel when no nodes are present (elastic#127100)
  [Lens] Fixed flakiness on runtime fields' appearance on the list (elastic#126945)
  [Security Solution][Lists] - Add missing privileges callout to exception lists page (elastic#126874)
  [Security Solution][Lists] - Updates exception flyout edit error messages (elastic#126875)
  [Security Solution][Rules] - Remove rule selection for read only users (elastic#126827)
  Fix session cleanup test (elastic#126966)
  [ftr] implement support for accessing ES through CCS (elastic#126547)
  [type-summarizer] always use normalized paths, fix windows compat (elastic#127055)
  Revert "[ci] Configure hourly pipeline for a small spot instance trial (elastic#126824)"
  Revert "[CI] Expand spot instance trial a bit (elastic#126928)"
  [Alerting] Adding functional tests for alerting and actions telemetry (elastic#126528)
  [Telemetry] Check permissions when requesting telemetry (elastic#126238)
  Don't submit empty seed_urls or sitemap_urls when making a partial crawl request (elastic#126972)
  Remove License Requirement for Enterprise Search App Search Meta Engines (elastic#127046)
  [ML] Adding data recognizer module config cache (elastic#126338)
  skip flaky suite (elastic#126027)
  [Reporting] Improve error logging for rescheduled jobs (elastic#126737)
  ...

# Conflicts:
#	x-pack/plugins/reporting/server/core.ts
#	x-pack/plugins/reporting/server/lib/tasks/execute_report.ts
jloleysens added a commit to jloleysens/kibana that referenced this pull request Mar 8, 2022
…re-browser-errors

* 'main' of github.com:elastic/kibana: (46 commits)
  Fix copy and pasted renderer user_name test (elastic#126663)
  [Gauge] Vis editors gauge legacy percent mode. (elastic#126318)
  Remove all cases related code from timelines (elastic#127003)
  Hide Enterprise search panel when no nodes are present (elastic#127100)
  [Lens] Fixed flakiness on runtime fields' appearance on the list (elastic#126945)
  [Security Solution][Lists] - Add missing privileges callout to exception lists page (elastic#126874)
  [Security Solution][Lists] - Updates exception flyout edit error messages (elastic#126875)
  [Security Solution][Rules] - Remove rule selection for read only users (elastic#126827)
  Fix session cleanup test (elastic#126966)
  [ftr] implement support for accessing ES through CCS (elastic#126547)
  [type-summarizer] always use normalized paths, fix windows compat (elastic#127055)
  Revert "[ci] Configure hourly pipeline for a small spot instance trial (elastic#126824)"
  Revert "[CI] Expand spot instance trial a bit (elastic#126928)"
  [Alerting] Adding functional tests for alerting and actions telemetry (elastic#126528)
  [Telemetry] Check permissions when requesting telemetry (elastic#126238)
  Don't submit empty seed_urls or sitemap_urls when making a partial crawl request (elastic#126972)
  Remove License Requirement for Enterprise Search App Search Meta Engines (elastic#127046)
  [ML] Adding data recognizer module config cache (elastic#126338)
  skip flaky suite (elastic#126027)
  [Reporting] Improve error logging for rescheduled jobs (elastic#126737)
  ...

# Conflicts:
#	x-pack/plugins/reporting/server/lib/tasks/execute_report.ts
@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 126338 or prevent reminders by adding the backport:skip label.

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 9, 2022
@jgowdyelastic jgowdyelastic added backport:skip This PR does not require backporting and removed backport missing Added to PRs automatically when the are determined to be missing a backport. labels Mar 10, 2022
@lcawl lcawl changed the title [ML] Adding data recognizer module config cache [ML] Adds cache for data recognizer module configs to reduce number of privilege checks Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting bug Fixes for quality problems that affect the customer experience Feature:Anomaly Detection ML anomaly detection :ml release_note:enhancement v8.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ML] Calls to get module endpoint produces excessive _has_privileges checks

8 participants