zhaohai666 opened a new pull request, #933:
URL: https://github.com/apache/rocketmq-dashboard/pull/933
# feat(metrics): bundle Prometheus alert rule YAML templates (METRICS-01)
> Branch: `feature/studio-alert-rules-yaml`
> Base: `rocketmq-studio`
> Scope: METRICS-01 — *Built-in Prometheus alert-rule YAML assets (≥20
templates)*
## Summary
RocketMQ Studio now bundles a library of **Prometheus alert-rule YAML
templates** as
classpath resources. They can be listed, previewed, and exported as files to
drop into a
Prometheus / Alertmanager setup. Crucially, these bundled templates also
become the
**default seed** for the existing in-memory alert-rule store, so a fresh
deployment starts
with a meaningful baseline set of rules without changing the existing REST
contract.
Twenty-three alert templates are included (≥20 requirement met), grouped by
domain
(`rocketmq-broker.rules`, `rocketmq-consumer.rules`, `rocketmq-client.rules`,
`rocketmq-topic.rules`, `rocketmq-proxy.rules`, `rocketmq-errors.rules`),
each with `severity`
and `team` labels and `summary` / `description` annotations.
## Bundled alert templates
`rocketmq-broker-down`, `rocketmq-broker-cpu-high`,
`rocketmq-broker-memory-high`,
`rocketmq-broker-disk-high`, `rocketmq-broker-replication-lag`,
`rocketmq-consumer-lag-high`,
`rocketmq-consumer-lag-critical`, `rocketmq-consumer-rebalance`,
`rocketmq-consumer-group-empty`,
`rocketmq-producer-latency-high`, `rocketmq-producer-failure`,
`rocketmq-producer-tps-drop`,
`rocketmq-topic-in-drop`, `rocketmq-topic-accumulation`,
`rocketmq-topic-dispatch-latency`,
`rocketmq-client-connection-drop`, `rocketmq-client-timeout`,
`rocketmq-proxy-down`,
`rocketmq-proxy-latency-high`, `rocketmq-exception-rate`,
`rocketmq-dlq-resend-high`,
`rocketmq-threadpool-reject`, `rocketmq-jvm-gc-cpu-high`
Generation is reproducible via `server/scripts/gen_alert_rule_yaml.py`.
## Changes
### Backend (`server/.../ops/alert`)
- `PrometheusAlertRule` — promoted to a **public** record (`group, alert,
expr, duration,
severity, team, summary, description`) so it can be reused by the asset
service.
- `AlertRuleAssetInfo` — metadata record (`name, group, ruleCount,
severities`).
- `AlertRuleAssetService` — loads `classpath*:alerts/*.yaml` via
`PathMatchingResourcePatternResolver` + Jackson `YAMLFactory`;
`listAssets()`,
`getAssetYaml(name)` (404 if missing), `loadDefaultRules()` →
`List<PrometheusAlertRule>`.
- `AlertRuleAssetController` — REST endpoints.
- `AlertService` — `defaultPrometheusRules()` now seeds from
`AlertRuleAssetService
.loadDefaultRules()` when the in-memory repository is empty (was a
hard-coded 7-rule list).
- `server/scripts/gen_alert_rule_yaml.py` — generator for the 23 YAML assets.
- `server/src/main/resources/alerts/*.yaml` — the 23 alert templates.
### Frontend (`web/...`)
- `api/alertRuleAssets.ts` — `AlertRuleAssetInfo`, `listAlertRuleAssets`,
`getAlertRuleAsset`,
`exportAlertRuleAsset` (blob export). Paths are **relative**
(`/alert-rules/assets/...`)
because `API_BASE_URL` already equals `/api`.
- `services/alertRuleAssetService.ts` — service layer with mock/real
data-mode support.
- `mock/alertRuleAssets.ts` — 14 mock assets mirroring the bundled templates.
- `components/AlertRuleAssetList.tsx` — table with severity tags +
view-modal (renders YAML)
+ export download.
- `pages/studio/AlertRuleAssets.tsx` — page wired into the studio nav.
- `layouts/MainLayout.tsx`, `App.tsx` — navigation entry
(`/ops/alert-rule-templates`) + lazy route.
- `i18n/translations.ts` — `alertAssets.*` keys (zh/en) +
`nav.alertRuleAssets`.
## API
```
GET /api/alert-rules/assets # list asset metadata
GET /api/alert-rules/assets/{name} # raw YAML for one asset (404 if
missing)
GET /api/alert-rules/assets/{name}/export # YAML file,
Content-Disposition: attachment
```
## Testing
- **Backend** (`server/src/test/.../ops/alert`):
- `AlertRuleAssetServiceTest` — list ≥10 assets, `loadDefaultRules()` ≥20
rules, raw YAML,
404 handling, severity/team parsing.
- `AlertRuleAssetControllerTest` — WebMvc coverage incl.
`Content-Disposition` on export.
- `AlertServiceDefaultRulesTest` — verifies `exportPrometheusRulesYaml`
uses the bundled
assets (≥20 rules) when the repository is empty.
- All pass; Checkstyle clean.
- **Frontend** (`web/src`):
- `api/alertRuleAssets.test.ts`, `services/alertRuleAssetService.test.ts`,
`components/__tests__/AlertRuleAssetList.test.tsx`.
- `tsc --noEmit` clean; ESLint clean.
## Notes / Follow-ups
- The "load as default" behavior intentionally reuses
`AlertService.exportPrometheusRulesYaml`,
so no existing alert endpoint signature changes.
- Export returns `application/x-yaml` with an `attachment` disposition for
one-click download.
--
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]