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

[ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change #195090

Conversation

rbrtj
Copy link
Contributor

@rbrtj rbrtj commented Oct 4, 2024

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

@rbrtj rbrtj added release_note:fix :ml Feature:Anomaly Detection ML anomaly detection v9.0.0 Team:ML Team label for ML (also use :ml) v8.16.0 backport:version Backport to applied version labels labels Oct 4, 2024
@rbrtj rbrtj self-assigned this Oct 4, 2024
@rbrtj rbrtj requested a review from a team as a code owner October 4, 2024 14:41
@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

Copy link
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

@peteharverson
Copy link
Contributor

Unrelated to the fix here as also happens on main but there's an issue in the embeddable if the query is for an entity which is not on page 1 of the results:

Screen.Recording.2024-10-07.at.16.49.25.mov

Is the page number reset to 1 when the query changes?

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

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
ml 4.6MB 4.6MB -65.0B

History

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

cc @rbrtj

@rbrtj rbrtj requested a review from darnautov October 8, 2024 09:14
Comment on lines 98 to 105
let isEmptyQuery = true;

if (isOfQueryType(query)) {
isEmptyQuery = !query.query;
} else {
isEmptyQuery = !query?.esql;
}

Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed in: 868dd88

@darnautov darnautov self-requested a review October 8, 2024 09:54
@rbrtj rbrtj requested a review from darnautov October 8, 2024 14:30
Comment on lines 98 to 105
let isEmptyQuery = true;

if (isOfQueryType(query)) {
isEmptyQuery = !query.query;
} else {
isEmptyQuery = !query?.esql;
}

Copy link
Contributor

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 }))
Copy link
Contributor

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.

Copy link
Contributor Author

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

@darnautov darnautov self-requested a review October 8, 2024 14:42
@@ -127,12 +131,14 @@ export const getAnomalySwimLaneEmbeddableFactory = (
serialize: serializeTimeRange,
} = initializeTimeRange(state);

const swimlaneControlsDependencies$ = merge(query$, filters$, timeRange$);
Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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

Suggested change
const fetchSubscription = fetch$(api)
subscriptions.add(fetch$(api)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in: 55c3e67

Comment on lines 242 to 247
map((fetchContext) => ({
query: fetchContext.query,
filters: fetchContext.filters,
timeRange: fetchContext.timeRange,
})),
distinctUntilChanged(fastIsEqual)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
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.

Tested latest changes and LGTM

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #29 / custom visualizations self changing vis "before all" hook for "should allow updating params via the editor"

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
ml 4.6MB 4.6MB +137.0B

History

cc @rbrtj

@rbrtj rbrtj added the v8.15.3 label Oct 10, 2024
@rbrtj rbrtj merged commit d44d354 into elastic:main Oct 10, 2024
26 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.15, 8.x

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 10, 2024
…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)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 10, 2024
…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)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.15
8.x

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 Oct 10, 2024
… 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]>
kibanamachine added a commit that referenced this pull request Oct 10, 2024
…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]>
@mistic
Copy link
Member

mistic commented Oct 17, 2024

This PR didn't make it into the latest BC of v8.15.3. Updating the labels.

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 Feature:Anomaly Detection ML anomaly detection :ml release_note:fix Team:ML Team label for ML (also use :ml) v8.15.4 v8.16.0 v9.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants