[v9.5.x] Alerting: Fix state manager to not keep datasource_uid and ref_id labels in state after Error #77391
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Backport 78fc3bc from #72216
What is this feature?
This PR fixes a bug in the state manager that is described in #71467. It updates the state manager to clean up the labels sneaked after the cacheID was calculated. I added safety to remove only if the result does not contain these labels.
This is a temporary change to remediate the problem and will be changed in #68142
Before
before-no-sound.mp4
After
after-no-sound.mp4
Why do we need this feature?
This happens only in the case when the result does not have any labels, usually when the rule uses the classic condition. The normal evaluation uses labels from the rule only. When an error happens, the error result does not have labels either, and therefore it is matched to the normal state instead of being a new state (in multi-dimensional alerts when each normal result contains labels). The state manager adds extra labels after the state identifier is calculated. Therefore, this makes the normal result match the state that contains the extra labels, and therefore the extra labels (datasource_uid and ref_id) never go away from the state.
Who is this feature for?
Those who use classic condition and execution of Error as an error.
Which issue(s) does this PR fix?:
Fixes #71467
Special notes for your reviewer:
Please check that: