Skip to content

fix(alert): match padded stored instance ids in active state filters - #4372

Open
89799969 wants to merge 1 commit into
apache:masterfrom
89799969:fix/alert-state-trim-instance-id
Open

89799969 wants to merge 1 commit into
apache:masterfrom
89799969:fix/alert-state-trim-instance-id

Conversation

@89799969

Copy link
Copy Markdown
Contributor

Summary

Fixes #4297

A rule whose stored instanceId has surrounding whitespace fires via NativeAlertRuleScopeMatcher (trims) but was dropped from MybatisPlusAlertStateRepository.findActive and NativeAlertProcessor.reconcileMissingActiveStates. Operators saw "no active alert" while FIRING rows kept being written.

Trim the stored instance id in both filters, matching the metric filter on the previous line.

Testing

  • MybatisPlusAlertStateRepositoryTest#findsActiveStatesForRulesWithPaddedStoredInstanceIdTest (new)
  • MybatisPlusAlertStateRepositoryTest: 6 passed locally

AI disclosure

Implemented with the assistance of an AI coding agent.

Rules whose stored instanceId has surrounding whitespace fire via
NativeAlertRuleScopeMatcher (which trims) but were dropped from
findActive and reconcileMissingActiveStates, so the operator saw no
active alert while FIRING rows kept being written. Trim the stored
value in both filters, matching the metric filter on the line above.

Fixes apache#4297

Testing: MybatisPlusAlertStateRepositoryTest#findsActiveStatesForRulesWithPaddedStoredInstanceIdTest

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Correct fix for the inconsistency between NativeAlertRuleScopeMatcher (which trims) and the query/reconcile paths (which didn't). The trim is now applied consistently in both findActive and reconcileMissingActiveStates, matching the metric filter pattern on the preceding line.

One minor observation: in NativeAlertProcessor.java, the original code used rule.getInstanceId() == null as the guard, while the fix changes it to !StringUtils.hasText(rule.getInstanceId()). This is a slight behavioral broadening (also treats empty string as "no instance filter"), but it's consistent with the MybatisPlusAlertStateRepository change and is the safer choice — an empty instanceId would never match a real scope anyway.

LGTM — well-tested with a clear reproduction scenario.


Automated review by github-manager-bot

@89799969
89799969 changed the base branch from rocketmq-studio to master September 16, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Studio][Bug] A rule with a padded stored instance id fires but reports no active alert state

2 participants