zjncs opened a new pull request, #3987: URL: https://github.com/apache/rocketmq-dashboard/pull/3987
## Motivation `AlertService.exportPrometheusRulesYaml` validates each rule's metric against the Prometheus name pattern (`^[a-zA-Z_:][a-zA-Z0-9_:]*$`) and silently falls back to `rocketmq_consumer_lag_messages` when it does not match. Every native Studio metric name defined in `NativeAlertRulePolicy` (`consumer.lag.total`, `consumer.lag.max_queue`, `consumer.delay.seconds`, `topic.backlog.total`, `dlq.message.count`, …) contains dots, so **none** of them matches the pattern. Exporting a business rule such as: - `dlq.message.count > 100` - `topic.backlog.total > 50000` - `consumer.delay.seconds > 300` produces `expr: rocketmq_consumer_lag_messages > …` — the exported alert monitors **consumer lag** while the user configured a DLQ-size / topic-backlog / consumption-delay alert. The rule name, threshold and description all look right in Prometheus, so the retargeting is invisible and the intended condition is never alerted on. ## Modification - `consumer.lag.total` now translates to its exact rocketmq-exporter equivalent `rocketmq_consumer_lag_messages` through an explicit `NATIVE_METRIC_EXPORT_NAMES` mapping (this is the only native business metric with a direct exporter equivalent — e.g. `rocketmq_dlq_resend_count` measures resend rate, not DLQ size, so `dlq.message.count` cannot be mapped faithfully). - Rules whose native metric has no exporter equivalent are **skipped** from the export, and each skip is recorded as a trailing comment (`# Skipped "DLQ Flood": native metric 'dlq.message.count' has no equivalent in the rocketmq-exporter metric set`) so the omission is visible instead of silently wrong. - When every enabled business rule is skipped, the file emits `groups: []` so it stays loadable. - The existing fallback that replaces *malformed* metric strings (injection hardening, covered by `exportPrometheusRulesYamlShouldReplaceInvalidPrometheusFieldsTest`) is unchanged. - `NativeAlertRulePolicy` exposes `isNativeMetric` so the native metric catalog stays the single source of truth. ## Verification Added three tests to `AlertServiceTest`: - `exportPrometheusRulesYamlShouldSkipNativeMetricsWithoutExporterEquivalentTest` — a `dlq.message.count` rule next to a regular lag rule: the lag rule is exported, the DLQ rule is skipped with a comment, and no `rocketmq_consumer_lag_messages > 100` expr appears. **Fails on the current branch** (the DLQ rule is exported as a lag rule). - `exportPrometheusRulesYamlShouldTranslateNativeConsumerLagMetricTest` — `consumer.lag.total` exports as `rocketmq_consumer_lag_messages` with the consumer group/team naming. - `exportPrometheusRulesYamlShouldEmitEmptyGroupsWhenAllRulesUseUnexportableNativeMetricsTest` — a single `topic.backlog.total` rule yields `groups: []` plus the skip comment and no substituted metric. **Fails on the current branch.** `mvn -pl server test -Dtest='Alert*Test'` → all alert suites pass (AlertServiceTest 76/76). `NotificationOutboxServiceTest` fails 4F/1E identically on the base commit without this change (pre-existing). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
