-
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
[Security Solution] Invalidate updated rules instead of marking them instantly stale #153529
[Security Solution] Invalidate updated rules instead of marking them instantly stale #153529
Conversation
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Unknown metric groupsESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @maximpn |
Pinging @elastic/security-detections-response (Team:Detections and Resp) |
Pinging @elastic/security-solution (Team: SecuritySolution) |
} else { | ||
// We failed to receive the list of update rules, invalidate all | ||
invalidateFindRulesQuery(); | ||
} | ||
invalidateFindRulesQuery({ refetchType: 'none' }); |
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.
It introduces a high probability that we will display stale data eventually. Refetch type none
prevents hooks that are currently rendered to refetch their data. Therefore if there is no updatedRules
in the response, they will continue to display outdated data.
@@ -35,9 +35,6 @@ export const useFetchRuleByIdQuery = (id: string, options?: UseQueryOptions<Rule | |||
{ | |||
...DEFAULT_QUERY_OPTIONS, | |||
...options, | |||
// Mark this query as immediately stale helps to avoid problems related to filtering. | |||
// e.g. enabled and disabled state filter require data update which happens at the backend side | |||
staleTime: 0, |
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 gave it another thought, and keeping the stale time to 0 seems more appropriate. Rules contain dynamic data, such as "last run", "status", etc., that we may not know when it updates. As a result, we should consider the data as always stale and fetch updates each time a data fetching hook mounts. This approach helps avoid inconsistencies when a single rule is displayed under different filters, which could lead to conflicting information. For example, a rule might appear to have been executed 6 minutes ago in one view while displaying an execution time 1 minute ago in another. We can ensure that the information displayed remains consistent and accurate by fetching updates every time a hook mounts.
After the careful investigation and discussion with @xcrzx the problem described in this comment was reproduced. To do that the following should be done
This way |
Addresses: #151151
Summary
It's an improved fix of #151151. It helps to reduce the number of fetch data requests by reusing cache data when it's possible.
Before:
Screen.Recording.2023-03-23.at.14.33.35.mov
After:
Screen.Recording.2023-03-23.at.14.35.38.mov