Skip to content

[ResponseOps][Rules] Add loading state to rule params data views selector#203654

Merged
umbopepato merged 8 commits intoelastic:mainfrom
umbopepato:198502-fix-empty-rule-data-views-selector
Dec 16, 2024
Merged

[ResponseOps][Rules] Add loading state to rule params data views selector#203654
umbopepato merged 8 commits intoelastic:mainfrom
umbopepato:198502-fix-empty-rule-data-views-selector

Conversation

@umbopepato
Copy link
Copy Markdown
Member

@umbopepato umbopepato commented Dec 10, 2024

Summary

Introduces a loading state in the data views select popover and renders a loading indicator when DVs are not available yet. This makes sure that even if the savedObjectsClient.find call of the data views service takes a long time, we don't show an empty popover in the meantime.

Screen.Recording.2024-12-10.at.18.34.41.mov

References

Fixes #198502

Release note

Fix race condition in alerting rules data view selector

@umbopepato umbopepato added release_note:fix Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// labels Dec 10, 2024
@umbopepato umbopepato requested a review from a team as a code owner December 10, 2024 17:37
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@cnasikas cnasikas added the backport:all-open Backport to all branches that could still receive a release label Dec 11, 2024
Copy link
Copy Markdown
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

I looked at the code and wanted to discuss some ideas along with what you did.

  1. Stop relying on cache.
const ids = await dataViews.getIds(true); <--- refreshes the cache. We will always make a call to get the data views.
  1. Load data views only on mount.
useEffect(() => {
    loadPersistedDataViews();
  }, []); <--- remove the loadPersistedDataViews dependency. We want to run on mount once.
  1. Could we use React Query? I assume the effort is big as the components are being shared in various solutions.

  2. Remove this check.

if (!allDataViewItems) {
    return null;
  }

@umbopepato
Copy link
Copy Markdown
Member Author

umbopepato commented Dec 11, 2024

  1. Stop relying on cache.
const ids = await dataViews.getIds(true); <--- refreshes the cache. We will always make a call to get the data views.

Yes, that's what I did in order to manage the case where the DV cache is initialized but empty. In hindsight, I think we also need a separate loading state because the initialized but empty cache would still fall under the case of "ready" data. This could be the reason why the issue is not always reproducible the same way!

  1. Load data views only on mount.
useEffect(() => {
    loadPersistedDataViews();
  }, []); <--- remove the loadPersistedDataViews dependency. We want to run on mount once.

I agree, the effect should be the same though, it's just the exhaustive deps lint rule that advises to add the callback to the dependencies, but it should be referentially stable and execute one time only.

  1. Could we use React Query? I assume the effort is big as the components are being shared in various solutions.

Of course that was my first thought 😂 I agree that it would take a bit of time though, so how about we start with an intermediate solution and then add a work item for the migration to RQ?

  1. Remove this check.
if (!allDataViewItems) {
    return null;
  }

Right, it should never execute since allDataViewItems is always defined, even if empty?

@cnasikas cnasikas added the bug Fixes for quality problems that affect the customer experience label Dec 11, 2024
@cnasikas
Copy link
Copy Markdown
Member

I agree, the effect should be the same though, it's just the exhaustive deps lint rule that advises to add the callback to the dependencies, but it should be referentially stable and execute one time only.

The useEffect relies on the useCallback which in turn relies on the dataViews service. Are we sure that the dataViews service is the same instance every time?

Of course that was my first thought 😂 I agree that it would take a bit of time though, so how about we start with an intermediate solution and then add a work item for the migration to RQ?

Totally agree. Let's do the intermediate solution and fix the bug.

@umbopepato
Copy link
Copy Markdown
Member Author

The useEffect relies on the useCallback which in turn relies on the dataViews service. Are we sure that the dataViews service is the same instance every time?

It seems stable 🙂

image

Totally agree. Let's do the intermediate solution and fix the bug.

Ok! I left the error management empty for now. I don't know if the saved objects client already shows a toast but when we move to RQ we could maybe consider using an in-place Prompt or Callout

@umbopepato umbopepato enabled auto-merge (squash) December 16, 2024 13:56
@umbopepato umbopepato merged commit 713d4bb into elastic:main Dec 16, 2024
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Page load bundle

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

id before after diff
stackAlerts 25.1KB 25.2KB +103.0B

History

@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 7.17, 8.16, 8.17, 8.x

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

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 16, 2024
…ctor (elastic#203654)

## Summary

Introduces a loading state in the data views select popover and renders
a loading indicator when DVs are not available yet. This makes sure that
even if the `savedObjectsClient.find` call of the data views service
takes a long time, we don't show an empty popover in the meantime.

https://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1

## References

Fixes elastic#198502

## Release note

Fix race condition in alerting rules data view selector

(cherry picked from commit 713d4bb)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 16, 2024
…ctor (elastic#203654)

## Summary

Introduces a loading state in the data views select popover and renders
a loading indicator when DVs are not available yet. This makes sure that
even if the `savedObjectsClient.find` call of the data views service
takes a long time, we don't show an empty popover in the meantime.

https://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1

## References

Fixes elastic#198502

## Release note

Fix race condition in alerting rules data view selector

(cherry picked from commit 713d4bb)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Dec 16, 2024
…ctor (elastic#203654)

## Summary

Introduces a loading state in the data views select popover and renders
a loading indicator when DVs are not available yet. This makes sure that
even if the `savedObjectsClient.find` call of the data views service
takes a long time, we don't show an empty popover in the meantime.

https://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1

## References

Fixes elastic#198502

## Release note

Fix race condition in alerting rules data view selector

(cherry picked from commit 713d4bb)
@kibanamachine
Copy link
Copy Markdown
Contributor

💔 Some backports could not be created

Status Branch Result
7.17 Backport failed because of merge conflicts
8.16
8.17
8.x

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

Manual backport

To create the backport manually run:

node scripts/backport --pr 203654

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Dec 16, 2024
…ws selector (#203654) (#204422)

# Backport

This will backport the following commits from `main` to `8.16`:
- [[ResponseOps][Rules] Add loading state to rule params data views
selector (#203654)](#203654)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Umberto
Pepato","email":"umbopepato@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-12-16T15:43:13Z","message":"[ResponseOps][Rules]
Add loading state to rule params data views selector (#203654)\n\n##
Summary\r\n\r\nIntroduces a loading state in the data views select
popover and renders\r\na loading indicator when DVs are not available
yet. This makes sure that\r\neven if the `savedObjectsClient.find` call
of the data views service\r\ntakes a long time, we don't show an empty
popover in the
meantime.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1\r\n\r\n##
References\r\n\r\nFixes #198502 \r\n\r\n## Release note\r\n\r\nFix race
condition in alerting rules data view
selector","sha":"713d4bbcb2d9f5e707d06c1d298287edd3e694d0","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:ResponseOps","v9.0.0","backport:all-open"],"title":"[ResponseOps][Rules]
Add loading state to rule params data views
selector","number":203654,"url":"https://github.com/elastic/kibana/pull/203654","mergeCommit":{"message":"[ResponseOps][Rules]
Add loading state to rule params data views selector (#203654)\n\n##
Summary\r\n\r\nIntroduces a loading state in the data views select
popover and renders\r\na loading indicator when DVs are not available
yet. This makes sure that\r\neven if the `savedObjectsClient.find` call
of the data views service\r\ntakes a long time, we don't show an empty
popover in the
meantime.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1\r\n\r\n##
References\r\n\r\nFixes #198502 \r\n\r\n## Release note\r\n\r\nFix race
condition in alerting rules data view
selector","sha":"713d4bbcb2d9f5e707d06c1d298287edd3e694d0"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203654","number":203654,"mergeCommit":{"message":"[ResponseOps][Rules]
Add loading state to rule params data views selector (#203654)\n\n##
Summary\r\n\r\nIntroduces a loading state in the data views select
popover and renders\r\na loading indicator when DVs are not available
yet. This makes sure that\r\neven if the `savedObjectsClient.find` call
of the data views service\r\ntakes a long time, we don't show an empty
popover in the
meantime.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1\r\n\r\n##
References\r\n\r\nFixes #198502 \r\n\r\n## Release note\r\n\r\nFix race
condition in alerting rules data view
selector","sha":"713d4bbcb2d9f5e707d06c1d298287edd3e694d0"}}]}]
BACKPORT-->

Co-authored-by: Umberto Pepato <umbopepato@users.noreply.github.com>
kibanamachine added a commit that referenced this pull request Dec 16, 2024
…ws selector (#203654) (#204423)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[ResponseOps][Rules] Add loading state to rule params data views
selector (#203654)](#203654)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Umberto
Pepato","email":"umbopepato@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-12-16T15:43:13Z","message":"[ResponseOps][Rules]
Add loading state to rule params data views selector (#203654)\n\n##
Summary\r\n\r\nIntroduces a loading state in the data views select
popover and renders\r\na loading indicator when DVs are not available
yet. This makes sure that\r\neven if the `savedObjectsClient.find` call
of the data views service\r\ntakes a long time, we don't show an empty
popover in the
meantime.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1\r\n\r\n##
References\r\n\r\nFixes #198502 \r\n\r\n## Release note\r\n\r\nFix race
condition in alerting rules data view
selector","sha":"713d4bbcb2d9f5e707d06c1d298287edd3e694d0","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:ResponseOps","v9.0.0","backport:all-open"],"title":"[ResponseOps][Rules]
Add loading state to rule params data views
selector","number":203654,"url":"https://github.com/elastic/kibana/pull/203654","mergeCommit":{"message":"[ResponseOps][Rules]
Add loading state to rule params data views selector (#203654)\n\n##
Summary\r\n\r\nIntroduces a loading state in the data views select
popover and renders\r\na loading indicator when DVs are not available
yet. This makes sure that\r\neven if the `savedObjectsClient.find` call
of the data views service\r\ntakes a long time, we don't show an empty
popover in the
meantime.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1\r\n\r\n##
References\r\n\r\nFixes #198502 \r\n\r\n## Release note\r\n\r\nFix race
condition in alerting rules data view
selector","sha":"713d4bbcb2d9f5e707d06c1d298287edd3e694d0"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203654","number":203654,"mergeCommit":{"message":"[ResponseOps][Rules]
Add loading state to rule params data views selector (#203654)\n\n##
Summary\r\n\r\nIntroduces a loading state in the data views select
popover and renders\r\na loading indicator when DVs are not available
yet. This makes sure that\r\neven if the `savedObjectsClient.find` call
of the data views service\r\ntakes a long time, we don't show an empty
popover in the
meantime.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1\r\n\r\n##
References\r\n\r\nFixes #198502 \r\n\r\n## Release note\r\n\r\nFix race
condition in alerting rules data view
selector","sha":"713d4bbcb2d9f5e707d06c1d298287edd3e694d0"}}]}]
BACKPORT-->

Co-authored-by: Umberto Pepato <umbopepato@users.noreply.github.com>
kibanamachine added a commit that referenced this pull request Dec 16, 2024
…s selector (#203654) (#204424)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][Rules] Add loading state to rule params data views
selector (#203654)](#203654)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT [{"author":{"name":"Umberto
Pepato","email":"umbopepato@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-12-16T15:43:13Z","message":"[ResponseOps][Rules]
Add loading state to rule params data views selector (#203654)\n\n##
Summary\r\n\r\nIntroduces a loading state in the data views select
popover and renders\r\na loading indicator when DVs are not available
yet. This makes sure that\r\neven if the `savedObjectsClient.find` call
of the data views service\r\ntakes a long time, we don't show an empty
popover in the
meantime.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1\r\n\r\n##
References\r\n\r\nFixes #198502 \r\n\r\n## Release note\r\n\r\nFix race
condition in alerting rules data view
selector","sha":"713d4bbcb2d9f5e707d06c1d298287edd3e694d0","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:ResponseOps","v9.0.0","backport:all-open"],"title":"[ResponseOps][Rules]
Add loading state to rule params data views
selector","number":203654,"url":"https://github.com/elastic/kibana/pull/203654","mergeCommit":{"message":"[ResponseOps][Rules]
Add loading state to rule params data views selector (#203654)\n\n##
Summary\r\n\r\nIntroduces a loading state in the data views select
popover and renders\r\na loading indicator when DVs are not available
yet. This makes sure that\r\neven if the `savedObjectsClient.find` call
of the data views service\r\ntakes a long time, we don't show an empty
popover in the
meantime.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1\r\n\r\n##
References\r\n\r\nFixes #198502 \r\n\r\n## Release note\r\n\r\nFix race
condition in alerting rules data view
selector","sha":"713d4bbcb2d9f5e707d06c1d298287edd3e694d0"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/203654","number":203654,"mergeCommit":{"message":"[ResponseOps][Rules]
Add loading state to rule params data views selector (#203654)\n\n##
Summary\r\n\r\nIntroduces a loading state in the data views select
popover and renders\r\na loading indicator when DVs are not available
yet. This makes sure that\r\neven if the `savedObjectsClient.find` call
of the data views service\r\ntakes a long time, we don't show an empty
popover in the
meantime.\r\n\r\n\r\nhttps://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1\r\n\r\n##
References\r\n\r\nFixes #198502 \r\n\r\n## Release note\r\n\r\nFix race
condition in alerting rules data view
selector","sha":"713d4bbcb2d9f5e707d06c1d298287edd3e694d0"}}]}]
BACKPORT-->

Co-authored-by: Umberto Pepato <umbopepato@users.noreply.github.com>
@mistic
Copy link
Copy Markdown
Contributor

mistic commented Dec 17, 2024

This PR didn't make it on time to be in the latest 8.16.2 BC. Updating the labels.

@mistic mistic added v8.16.3 and removed v8.16.2 labels Dec 17, 2024
JoseLuisGJ pushed a commit to JoseLuisGJ/kibana that referenced this pull request Dec 19, 2024
…ctor (elastic#203654)

## Summary

Introduces a loading state in the data views select popover and renders
a loading indicator when DVs are not available yet. This makes sure that
even if the `savedObjectsClient.find` call of the data views service
takes a long time, we don't show an empty popover in the meantime.


https://github.com/user-attachments/assets/5bbe0c68-3ceb-4d7f-91fd-357db4caa5c1

## References

Fixes elastic#198502 

## Release note

Fix race condition in alerting rules data view selector
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:all-open Backport to all branches that could still receive a release bug Fixes for quality problems that affect the customer experience release_note:fix Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.16.3 v8.17.1 v8.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ResponseOps][Rules] Race condition in ESQuery rule data view selector

5 participants