Skip to content

fix(alert): consolidate rule authoring correctness - #2965

Merged
lizhimins merged 3 commits into
apache:rocketmq-studiofrom
Aias00:consolidate/studio-alert-rule-correctness
Sep 2, 2026
Merged

fix(alert): consolidate rule authoring correctness#2965
lizhimins merged 3 commits into
apache:rocketmq-studiofrom
Aias00:consolidate/studio-alert-rule-correctness

Conversation

@Aias00

@Aias00 Aias00 commented Sep 2, 2026

Copy link
Copy Markdown

Summary

Consolidates the alert rule authoring correctness fixes from the existing focused PRs:

This keeps the fixes together because they all affect alert rule authoring/export correctness:

  • use a triggerable signed delta() expression for the bundled producer connection-drop rule in the generator, generated YAML, and frontend mock data
  • normalize legacy metric display labels and duration labels before create/update/test payload submission
  • share the Prometheus duration grammar between request validation and YAML export so composite durations such as 1h30m round-trip correctly

Closes #2614
Closes #2603
Closes #2604

Verification

  • JAVA_HOME=$(/usr/libexec/java_home -v 21) mvn -Dtest=AlertRuleAssetServiceTest,AlertRuleRequestDTOTest,AlertServiceTest test -> 87 tests passed
  • npm test -- alertRuleAssetService.test.ts alerts.test.ts AlertsPage.test.tsx -> 4 files / 43 tests passed
  • npm run build -> passed (tsc -b && vite build)
  • JAVA_HOME=$(/usr/libexec/java_home -v 21) mvn -DskipTests package -> passed
  • python3 -m py_compile server/scripts/gen_alert_rule_yaml.py -> passed
  • git diff --check -> passed
  • TypeScript diagnostics for web/ -> 0 errors / 0 warnings

Known baseline note

JAVA_HOME=$(/usr/libexec/java_home -v 21) mvn -Dtest='org.apache.rocketmq.studio.ops.alert.*Test' test currently fails on the latest clean origin/rocketmq-studio as well: AlertSchemaMigrationTest tries to alter rmq_instance_message.result_snapshot when the table is absent. This PR does not modify that migration path; the targeted rule-authoring tests pass.

@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

Fixes alert rule authoring correctness: switches changes() to delta() for the client connection drop rule (the old expression could never trigger since changes() counts transitions, not signed deltas), normalizes legacy Chinese display labels to machine-readable metric names before backend submission, and supports composite Prometheus durations like 1h30m. Good test coverage across all three fixes.

LGTM 👍


Automated review by github-manager-bot

Use a signed gauge delta for the bundled producer connection-drop rule so a drop of more than five producers can satisfy the PromQL expression. Keep the generated YAML and frontend mock aligned with the generator and lock the expression in backend and frontend regression tests.

Constraint: changes() reports transition count and is non-negative, so changes(...) < -5 can never fire.

Rejected: keep changes() and invert threshold | PromQL changes() cannot represent signed drops.

Directive: keep server/scripts/gen_alert_rule_yaml.py, generated alert YAML, and web mock expression synchronized for bundled rules.

Confidence: high

Scope-risk: narrow

Tested: JAVA_HOME=/Users/aias/Library/Java/JavaVirtualMachines/openjdk-21.0.2/Contents/Home mvn -Dtest=AlertRuleAssetServiceTest,AlertRuleRequestDTOTest,AlertServiceTest test; npm test -- alertRuleAssetService.test.ts alerts.test.ts AlertsPage.test.tsx; npm run build; python3 -m py_compile server/scripts/gen_alert_rule_yaml.py; git diff --check
Signed-off-by: liuhy <liuhongyu@apache.org>
Normalize legacy display metric and duration values before submitting alert rules so old saved rules and copied rules keep the backend API contract. Keep threshold unit derivation keyed by canonical metric names and cover legacy conversion in the page tests.

Constraint: existing stored rules may still contain older display labels, but new submissions should use canonical metric and Prometheus duration values.

Rejected: only changing select option values | edit and duplicate flows can still replay legacy stored labels without explicit normalization.

Confidence: high

Scope-risk: narrow

Tested: JAVA_HOME=/Users/aias/Library/Java/JavaVirtualMachines/openjdk-21.0.2/Contents/Home mvn -Dtest=AlertRuleAssetServiceTest,AlertRuleRequestDTOTest,AlertServiceTest test; npm test -- alertRuleAssetService.test.ts alerts.test.ts AlertsPage.test.tsx; npm run build; git diff --check
Signed-off-by: liuhy <liuhongyu@apache.org>
Share the alert rule request Prometheus duration grammar with export validation so composite durations such as 1h30m round-trip into generated YAML instead of falling back to 5m.

Constraint: keep existing fallback behavior for invalid or missing durations.

Rejected: duplicating a wider regex in AlertService | would let DTO validation and export validation drift again.

Confidence: high

Scope-risk: narrow

Tested: JAVA_HOME=/Users/aias/Library/Java/JavaVirtualMachines/openjdk-21.0.2/Contents/Home mvn -Dtest=AlertRuleAssetServiceTest,AlertRuleRequestDTOTest,AlertServiceTest test; JAVA_HOME=/Users/aias/Library/Java/JavaVirtualMachines/openjdk-21.0.2/Contents/Home mvn -DskipTests package; git diff --check
Signed-off-by: liuhy <liuhongyu@apache.org>
@lizhimins
lizhimins force-pushed the consolidate/studio-alert-rule-correctness branch from 1d528e5 to 83ac164 Compare September 2, 2026 07:08
@lizhimins
lizhimins merged commit 714eda5 into apache:rocketmq-studio Sep 2, 2026

@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

New commits address alert rule correctness and duration validation. Changes look good.

Review of New Changes

Correctness

  • changes()delta() fix is correct: changes() counts value transitions and cannot produce negative values, making the original alert rule non-triggerable. delta() computes the actual signed difference.
  • Duration regex update to accept composite Prometheus durations (e.g., 1h30m) aligns with Prometheus spec.
  • Extracting PROMETHEUS_DURATION_REGEXP to a shared constant avoids divergence between DTO validation and service logic.

Tests

  • Good coverage: tests verify both the bundled YAML rule and the generator script use the correct expression.
  • Composite duration validation test ensures 1h30m is accepted.

Compatibility

  • No breaking changes to public APIs.

LGTM.


Automated review by github-manager-bot

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.

3 participants