-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change #195090
[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change #195090
Conversation
Pinging @elastic/ml-ui (:ml) |
…en-query-is-cleared
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Unrelated to the fix here as also happens on Screen.Recording.2024-10-07.at.16.49.25.movIs the page number reset to 1 when the query changes? |
💛 Build succeeded, but was flaky
Failed CI StepsMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @rbrtj |
…en-query-is-cleared
let isEmptyQuery = true; | ||
|
||
if (isOfQueryType(query)) { | ||
isEmptyQuery = !query.query; | ||
} else { | ||
isEmptyQuery = !query?.esql; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the query provides enough results for several pages, and the user wants to page further?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I reckon we should approach it differently. When query changes , we need to update swimLaneInput$
observable, resetting the pagination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check the AnomalyTimelineStateService as an example
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed in: 868dd88
x-pack/plugins/ml/public/embeddables/anomaly_swimlane/initialize_swim_lane_data_fetcher.ts
Outdated
Show resolved
Hide resolved
let isEmptyQuery = true; | ||
|
||
if (isOfQueryType(query)) { | ||
isEmptyQuery = !query.query; | ||
} else { | ||
isEmptyQuery = !query?.esql; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check the AnomalyTimelineStateService as an example
filters$.pipe(map(() => 1)) | ||
).pipe( | ||
distinctUntilChanged(), | ||
tap((fromPage) => swimLaneApi.updatePagination({ fromPage })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized we should also reset the pagination on time filter changes. In the Anomaly Explorer page, we listen to filter, query and time range, and form a ES query. Then the pagination observable listens for the ES query change and reset pagination accordingly.
And looking at this side effect I wonder if fromPage
update should happen inside of initializeSwimLaneControls
instead 🤔 In that case the swim lane fetcher logic only get the latest fromPage value, and the controls code is directly responsible for resetting it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, updated in: 5a95ba0
I think it should be more convenient now
@@ -127,12 +131,14 @@ export const getAnomalySwimLaneEmbeddableFactory = ( | |||
serialize: serializeTimeRange, | |||
} = initializeTimeRange(state); | |||
|
|||
const swimlaneControlsDependencies$ = merge(query$, filters$, timeRange$); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please use fetch$ instead? It combines all of them, also the search session id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use fetch$
in: ab9b445
@@ -235,6 +237,19 @@ export const getAnomalySwimLaneEmbeddableFactory = ( | |||
anomalySwimLaneServices | |||
); | |||
|
|||
const fetchSubscription = fetch$(api) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need a dedicated subscription. Try
const fetchSubscription = fetch$(api) | |
subscriptions.add(fetch$(api) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in: 55c3e67
map((fetchContext) => ({ | ||
query: fetchContext.query, | ||
filters: fetchContext.filters, | ||
timeRange: fetchContext.timeRange, | ||
})), | ||
distinctUntilChanged(fastIsEqual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I presume it's more expensive than skipWhile, because you need to compare objects on every emission instead of checking a boolean value of isReload
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, neither skipWhile
nor filter
will work in this case, as fetchContext.isReload
emits true
even when changing the query, and the skipWhile
operator only checks until the condition is met.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested latest changes and LGTM
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Async chunks
History
cc @rbrtj |
Starting backport for target branches: 8.15, 8.x https://github.com/elastic/kibana/actions/runs/11271128192 |
…change (elastic#195090) ## Summary Fix for: [elastic#194579](elastic#194579) In Anomaly Explorer, we do not limit the query size, as it is based on a constant value of `1000`. However, we did limit the query for the embeddable by setting the size to the value of the previous query cardinality. After discussing with @darnautov, we couldn't identify any potential regressions from removing this check. Includes fix for issue mentioned in: [#2397303538](elastic#195090 (comment)) When querying from a pagination page other than page 1, we didn’t reset the `fromPage` value, which prevented the query from returning results. Before: https://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614 After: https://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c https://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370 (cherry picked from commit d44d354)
…change (elastic#195090) ## Summary Fix for: [elastic#194579](elastic#194579) In Anomaly Explorer, we do not limit the query size, as it is based on a constant value of `1000`. However, we did limit the query for the embeddable by setting the size to the value of the previous query cardinality. After discussing with @darnautov, we couldn't identify any potential regressions from removing this check. Includes fix for issue mentioned in: [#2397303538](elastic#195090 (comment)) When querying from a pagination page other than page 1, we didn’t reset the `fromPage` value, which prevented the query from returning results. Before: https://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614 After: https://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c https://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370 (cherry picked from commit d44d354)
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
… query change (#195090) (#195723) # Backport This will backport the following commits from `main` to `8.15`: - [[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change (#195090)](#195090) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Robert Jaszczurek","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-10T09:19:28Z","message":"[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change (#195090)\n\n## Summary\r\n\r\nFix for: [#194579](https://github.com/elastic/kibana/issues/194579)\r\nIn Anomaly Explorer, we do not limit the query size, as it is based on a\r\nconstant value of `1000`.\r\nHowever, we did limit the query for the embeddable by setting the size\r\nto the value of the previous query cardinality.\r\nAfter discussing with @darnautov, we couldn't identify any potential\r\nregressions from removing this check.\r\nIncludes fix for issue mentioned in:\r\n[#2397303538](https://github.com/elastic/kibana/pull/195090#issuecomment-2397303538)\r\nWhen querying from a pagination page other than page 1, we didn’t reset\r\nthe `fromPage` value, which prevented the query from returning results.\r\nBefore:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614\r\n\r\nAfter:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370","sha":"d44d3543fb71858de5b09e04f3a538bd8cb0bf5b","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Feature:Anomaly Detection","v9.0.0","Team:ML","v8.16.0","backport:version","v8.15.3"],"title":"[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change","number":195090,"url":"https://github.com/elastic/kibana/pull/195090","mergeCommit":{"message":"[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change (#195090)\n\n## Summary\r\n\r\nFix for: [#194579](https://github.com/elastic/kibana/issues/194579)\r\nIn Anomaly Explorer, we do not limit the query size, as it is based on a\r\nconstant value of `1000`.\r\nHowever, we did limit the query for the embeddable by setting the size\r\nto the value of the previous query cardinality.\r\nAfter discussing with @darnautov, we couldn't identify any potential\r\nregressions from removing this check.\r\nIncludes fix for issue mentioned in:\r\n[#2397303538](https://github.com/elastic/kibana/pull/195090#issuecomment-2397303538)\r\nWhen querying from a pagination page other than page 1, we didn’t reset\r\nthe `fromPage` value, which prevented the query from returning results.\r\nBefore:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614\r\n\r\nAfter:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370","sha":"d44d3543fb71858de5b09e04f3a538bd8cb0bf5b"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.15"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195090","number":195090,"mergeCommit":{"message":"[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change (#195090)\n\n## Summary\r\n\r\nFix for: [#194579](https://github.com/elastic/kibana/issues/194579)\r\nIn Anomaly Explorer, we do not limit the query size, as it is based on a\r\nconstant value of `1000`.\r\nHowever, we did limit the query for the embeddable by setting the size\r\nto the value of the previous query cardinality.\r\nAfter discussing with @darnautov, we couldn't identify any potential\r\nregressions from removing this check.\r\nIncludes fix for issue mentioned in:\r\n[#2397303538](https://github.com/elastic/kibana/pull/195090#issuecomment-2397303538)\r\nWhen querying from a pagination page other than page 1, we didn’t reset\r\nthe `fromPage` value, which prevented the query from returning results.\r\nBefore:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614\r\n\r\nAfter:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370","sha":"d44d3543fb71858de5b09e04f3a538bd8cb0bf5b"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.15","label":"v8.15.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Robert Jaszczurek <[email protected]>
…query change (#195090) (#195725) # Backport This will backport the following commits from `main` to `8.x`: - [[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change (#195090)](#195090) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Robert Jaszczurek","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-10T09:19:28Z","message":"[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change (#195090)\n\n## Summary\r\n\r\nFix for: [#194579](https://github.com/elastic/kibana/issues/194579)\r\nIn Anomaly Explorer, we do not limit the query size, as it is based on a\r\nconstant value of `1000`.\r\nHowever, we did limit the query for the embeddable by setting the size\r\nto the value of the previous query cardinality.\r\nAfter discussing with @darnautov, we couldn't identify any potential\r\nregressions from removing this check.\r\nIncludes fix for issue mentioned in:\r\n[#2397303538](https://github.com/elastic/kibana/pull/195090#issuecomment-2397303538)\r\nWhen querying from a pagination page other than page 1, we didn’t reset\r\nthe `fromPage` value, which prevented the query from returning results.\r\nBefore:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614\r\n\r\nAfter:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370","sha":"d44d3543fb71858de5b09e04f3a538bd8cb0bf5b","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Feature:Anomaly Detection","v9.0.0","Team:ML","v8.16.0","backport:version","v8.15.3"],"title":"[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change","number":195090,"url":"https://github.com/elastic/kibana/pull/195090","mergeCommit":{"message":"[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change (#195090)\n\n## Summary\r\n\r\nFix for: [#194579](https://github.com/elastic/kibana/issues/194579)\r\nIn Anomaly Explorer, we do not limit the query size, as it is based on a\r\nconstant value of `1000`.\r\nHowever, we did limit the query for the embeddable by setting the size\r\nto the value of the previous query cardinality.\r\nAfter discussing with @darnautov, we couldn't identify any potential\r\nregressions from removing this check.\r\nIncludes fix for issue mentioned in:\r\n[#2397303538](https://github.com/elastic/kibana/pull/195090#issuecomment-2397303538)\r\nWhen querying from a pagination page other than page 1, we didn’t reset\r\nthe `fromPage` value, which prevented the query from returning results.\r\nBefore:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614\r\n\r\nAfter:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370","sha":"d44d3543fb71858de5b09e04f3a538bd8cb0bf5b"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.15"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195090","number":195090,"mergeCommit":{"message":"[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change (#195090)\n\n## Summary\r\n\r\nFix for: [#194579](https://github.com/elastic/kibana/issues/194579)\r\nIn Anomaly Explorer, we do not limit the query size, as it is based on a\r\nconstant value of `1000`.\r\nHowever, we did limit the query for the embeddable by setting the size\r\nto the value of the previous query cardinality.\r\nAfter discussing with @darnautov, we couldn't identify any potential\r\nregressions from removing this check.\r\nIncludes fix for issue mentioned in:\r\n[#2397303538](https://github.com/elastic/kibana/pull/195090#issuecomment-2397303538)\r\nWhen querying from a pagination page other than page 1, we didn’t reset\r\nthe `fromPage` value, which prevented the query from returning results.\r\nBefore:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/80476a0c-8fcc-40f7-8cac-04ecfb01d614\r\n\r\nAfter:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/f55e20fd-b1a4-446e-b16a-b1a6069bf63c\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/d31cb47d-cd13-4b3c-b6f9-c0ee60d3a370","sha":"d44d3543fb71858de5b09e04f3a538bd8cb0bf5b"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.15","label":"v8.15.3","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Robert Jaszczurek <[email protected]>
This PR didn't make it into the latest BC of v8.15.3. Updating the labels. |
Summary
Fix for: #194579
In Anomaly Explorer, we do not limit the query size, as it is based on a constant value of
1000
.However, we did limit the query for the embeddable by setting the size to the value of the previous query cardinality.
After discussing with @darnautov, we couldn't identify any potential regressions from removing this check.
Includes fix for issue mentioned in: #2397303538
When querying from a pagination page other than page 1, we didn’t reset the
fromPage
value, which prevented the query from returning results.Before:
Screen.Recording.2024-10-04.at.16.28.48.mov
After:
Screen.Recording.2024-10-04.at.16.30.12.mov
Screen.Recording.2024-10-08.at.11.12.53.mov