Skip to content

[ML] Anomaly Explorer: Prevent crash on anomaly table filter#213075

Merged
rbrtj merged 2 commits intoelastic:mainfrom
rbrtj:ml-anomaly-explorer-crashes-after-applying-a-filter
Mar 6, 2025
Merged

[ML] Anomaly Explorer: Prevent crash on anomaly table filter#213075
rbrtj merged 2 commits intoelastic:mainfrom
rbrtj:ml-anomaly-explorer-crashes-after-applying-a-filter

Conversation

@rbrtj
Copy link
Copy Markdown
Contributor

@rbrtj rbrtj commented Mar 4, 2025

Fix for: #212569
From what I found, the issue was with the useUrlStateService after changes introduced in #203224, which made the service more generic.

When filtering causes the explorer to remount the AnomaliesTable, pagination state updates are triggered before the effect that sets setCallback.current executes.

Initializing the ref with setState ensures its availability from the first render.

Screen.Recording.2025-03-04.at.12.36.28.mov

@rbrtj rbrtj added bug Fixes for quality problems that affect the customer experience release_note:fix :ml Feature:Anomaly Detection ML anomaly detection v9.0.0 Team:ML Team label for ML (also use :ml) t// backport:version Backport to applied version labels v8.18.0 v9.1.0 labels Mar 4, 2025
@rbrtj rbrtj requested review from darnautov and peteharverson March 4, 2025 11:40
@rbrtj rbrtj self-assigned this Mar 4, 2025
@rbrtj rbrtj requested a review from a team as a code owner March 4, 2025 11:40
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/ml-ui (:ml)

: state;

const setCallback = useRef<typeof setState>();
const setCallback = useRef<typeof setState>(setState);
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.

This looks good, preventing the crashes which I have been seeing when changing the filter.

However looks like the URL is persisting the anomalies table page index when changing properties of the view, such as the selected job ID(s). I think we should reset the page index to 0 when changing the selected job(s). @rbrtj @darnautov what do you think? I'd still recommend getting this fix in, and then potentially doing the reset in a follow-up unless it's a simple change.

Copy link
Copy Markdown
Contributor Author

@rbrtj rbrtj Mar 4, 2025

Choose a reason for hiding this comment

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

It should definitely reset the page index to 0 when changing the selected jobs, in my opinion.
Also, without this fix, the page would crash if we select a page in the anomalies table that is not available for a different job (..and then we change the job).

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.

As discussed offline, let's fix the page index reset to 0 in a separate PR, and get this fix for the page crash in first.

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
aiops 454.5KB 454.5KB +1.0B
transform 475.8KB 475.8KB +1.0B
total +2.0B

Page load bundle

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

id before after diff
dataVisualizer 28.0KB 28.0KB +1.0B
ml 78.7KB 78.7KB +1.0B
total +2.0B

cc @rbrtj

Copy link
Copy Markdown
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

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

LGTM

@rbrtj rbrtj requested a review from peteharverson March 6, 2025 16:14
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. Please create a separate issue for the page reset when the job ID, query or time range changes.

@rbrtj rbrtj merged commit 0210468 into elastic:main Mar 6, 2025
9 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.18, 9.0

https://github.com/elastic/kibana/actions/runs/13710136881

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 6, 2025
…#213075)

Fix for: elastic#212569
From what I found, the issue was with the `useUrlStateService` after
changes introduced in elastic#203224,
which made the service more generic.

When filtering causes the `explorer` to remount the `AnomaliesTable`,
pagination state updates are triggered before the effect that sets
`setCallback.current` executes.

Initializing the ref with `setState` ensures its availability from the
first render.

https://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6
(cherry picked from commit 0210468)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 6, 2025
…#213075)

Fix for: elastic#212569
From what I found, the issue was with the `useUrlStateService` after
changes introduced in elastic#203224,
which made the service more generic.

When filtering causes the `explorer` to remount the `AnomaliesTable`,
pagination state updates are triggered before the effect that sets
`setCallback.current` executes.

Initializing the ref with `setState` ensures its availability from the
first render.

https://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6
(cherry picked from commit 0210468)
@kibanamachine
Copy link
Copy Markdown
Contributor

💚 All backports created successfully

Status Branch Result
8.18
9.0

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 7, 2025
…213075) (#213499)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[ML] Anomaly Explorer: Prevent crash on anomaly table filter
(#213075)](#213075)

<!--- Backport version: 9.6.6 -->

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

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-03-06T23:18:49Z","message":"[ML]
Anomaly Explorer: Prevent crash on anomaly table filter (#213075)\n\nFix
for: https://github.com/elastic/kibana/issues/212569\nFrom what I found,
the issue was with the `useUrlStateService` after\nchanges introduced in
https://github.com/elastic/kibana/pull/203224,\nwhich made the service
more generic.\n\nWhen filtering causes the `explorer` to remount the
`AnomaliesTable`,\npagination state updates are triggered before the
effect that sets\n`setCallback.current` executes.\n\nInitializing the
ref with `setState` ensures its availability from the\nfirst
render.\n\n\nhttps://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6","sha":"0210468548e3d3c68f1ffbeba196ebfe418b0c4e","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix",":ml","Feature:Anomaly
Detection","v9.0.0","Team:ML","backport:version","v8.18.0","v9.1.0"],"title":"[ML]
Anomaly Explorer: Prevent crash on anomaly table
filter","number":213075,"url":"https://github.com/elastic/kibana/pull/213075","mergeCommit":{"message":"[ML]
Anomaly Explorer: Prevent crash on anomaly table filter (#213075)\n\nFix
for: https://github.com/elastic/kibana/issues/212569\nFrom what I found,
the issue was with the `useUrlStateService` after\nchanges introduced in
https://github.com/elastic/kibana/pull/203224,\nwhich made the service
more generic.\n\nWhen filtering causes the `explorer` to remount the
`AnomaliesTable`,\npagination state updates are triggered before the
effect that sets\n`setCallback.current` executes.\n\nInitializing the
ref with `setState` ensures its availability from the\nfirst
render.\n\n\nhttps://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6","sha":"0210468548e3d3c68f1ffbeba196ebfe418b0c4e"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/213075","number":213075,"mergeCommit":{"message":"[ML]
Anomaly Explorer: Prevent crash on anomaly table filter (#213075)\n\nFix
for: https://github.com/elastic/kibana/issues/212569\nFrom what I found,
the issue was with the `useUrlStateService` after\nchanges introduced in
https://github.com/elastic/kibana/pull/203224,\nwhich made the service
more generic.\n\nWhen filtering causes the `explorer` to remount the
`AnomaliesTable`,\npagination state updates are triggered before the
effect that sets\n`setCallback.current` executes.\n\nInitializing the
ref with `setState` ensures its availability from the\nfirst
render.\n\n\nhttps://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6","sha":"0210468548e3d3c68f1ffbeba196ebfe418b0c4e"}}]}]
BACKPORT-->

Co-authored-by: Robert Jaszczurek <92210485+rbrtj@users.noreply.github.com>
kibanamachine added a commit that referenced this pull request Mar 7, 2025
…213075) (#213498)

# Backport

This will backport the following commits from `main` to `8.18`:
- [[ML] Anomaly Explorer: Prevent crash on anomaly table filter
(#213075)](#213075)

<!--- Backport version: 9.6.6 -->

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

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"92210485+rbrtj@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-03-06T23:18:49Z","message":"[ML]
Anomaly Explorer: Prevent crash on anomaly table filter (#213075)\n\nFix
for: https://github.com/elastic/kibana/issues/212569\nFrom what I found,
the issue was with the `useUrlStateService` after\nchanges introduced in
https://github.com/elastic/kibana/pull/203224,\nwhich made the service
more generic.\n\nWhen filtering causes the `explorer` to remount the
`AnomaliesTable`,\npagination state updates are triggered before the
effect that sets\n`setCallback.current` executes.\n\nInitializing the
ref with `setState` ensures its availability from the\nfirst
render.\n\n\nhttps://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6","sha":"0210468548e3d3c68f1ffbeba196ebfe418b0c4e","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix",":ml","Feature:Anomaly
Detection","v9.0.0","Team:ML","backport:version","v8.18.0","v9.1.0"],"title":"[ML]
Anomaly Explorer: Prevent crash on anomaly table
filter","number":213075,"url":"https://github.com/elastic/kibana/pull/213075","mergeCommit":{"message":"[ML]
Anomaly Explorer: Prevent crash on anomaly table filter (#213075)\n\nFix
for: https://github.com/elastic/kibana/issues/212569\nFrom what I found,
the issue was with the `useUrlStateService` after\nchanges introduced in
https://github.com/elastic/kibana/pull/203224,\nwhich made the service
more generic.\n\nWhen filtering causes the `explorer` to remount the
`AnomaliesTable`,\npagination state updates are triggered before the
effect that sets\n`setCallback.current` executes.\n\nInitializing the
ref with `setState` ensures its availability from the\nfirst
render.\n\n\nhttps://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6","sha":"0210468548e3d3c68f1ffbeba196ebfe418b0c4e"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.18"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.18","label":"v8.18.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/213075","number":213075,"mergeCommit":{"message":"[ML]
Anomaly Explorer: Prevent crash on anomaly table filter (#213075)\n\nFix
for: https://github.com/elastic/kibana/issues/212569\nFrom what I found,
the issue was with the `useUrlStateService` after\nchanges introduced in
https://github.com/elastic/kibana/pull/203224,\nwhich made the service
more generic.\n\nWhen filtering causes the `explorer` to remount the
`AnomaliesTable`,\npagination state updates are triggered before the
effect that sets\n`setCallback.current` executes.\n\nInitializing the
ref with `setState` ensures its availability from the\nfirst
render.\n\n\nhttps://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6","sha":"0210468548e3d3c68f1ffbeba196ebfe418b0c4e"}}]}]
BACKPORT-->

Co-authored-by: Robert Jaszczurek <92210485+rbrtj@users.noreply.github.com>
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Mar 22, 2025
…#213075)

Fix for: elastic#212569
From what I found, the issue was with the `useUrlStateService` after
changes introduced in elastic#203224,
which made the service more generic.

When filtering causes the `explorer` to remount the `AnomaliesTable`,
pagination state updates are triggered before the effect that sets
`setCallback.current` executes.

Initializing the ref with `setState` ensures its availability from the
first render.


https://github.com/user-attachments/assets/d1aa8409-56e5-4632-a5f2-82350b877db6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels bug Fixes for quality problems that affect the customer experience Feature:Anomaly Detection ML anomaly detection :ml release_note:fix Team:ML Team label for ML (also use :ml) t// v8.18.0 v9.0.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants