zjncs opened a new pull request, #4186: URL: https://github.com/apache/rocketmq-dashboard/pull/4186
## Motivation One alert rule without a metric makes `rmq.alert.rule.list` fail for the **entire** listing: ``` IllegalStateException: Alert rule metric is unavailable ``` A blank metric is a legal stored state, creatable through the public REST API: - `AlertRuleRequestDTO.metric` has no `@NotBlank` (only `name` is validated); - `AlertService.createRule`/`updateRule` only require the name; - `NativeAlertRulePolicy.validate` **deliberately returns early** when the metric is blank — blank-metric rules pass validation by design; - the DB column is nullable (`metric VARCHAR(128)`), and `MybatisPlusAlertRepository` copies it straight into the VO. The YAML transfer import is the only creation path that validates the metric (`AlertRuleTransferService` → `metricCatalogService.validate`), so REST-created rules can lack one. `AlertRuleListToolHandler.safeProjection` then projects every row with `require(rule.getMetric(), "metric")`, and the first such row kills the whole tool call — the AI can no longer list alert rules at all. ## Modification Degrade the metric to blank via the handler's existing `blankIfNull` helper — exactly how `operator`, `thresholdUnit`, `duration` and `description` are already projected. The output schema (`rmq-tools.yaml`) types `metric` as a plain `string` with no `minLength`, so an empty string is a valid value for AI consumers. ## Verification Fail-before (handler change stashed, test kept): ``` [ERROR] Tests run: 33, Errors: 1 ToolGatewayServiceTest.executesAlertRuleListWhenARuleHasNoMetric » IllegalStateException: Alert rule metric is unavailable ``` Pass-after (fix applied): ``` ToolGatewayServiceTest Tests run: 34, Failures: 0, Errors: 0 ``` New test `executesAlertRuleListWhenARuleHasNoMetric` lists a mixed page (one rule with a metric, one without) and asserts the call succeeds, the metric-less row is present with `metric: ""`, and other rows are unaffected. -- 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]
