zhaohai666 opened a new pull request, #925:
URL: https://github.com/apache/rocketmq-dashboard/pull/925
# feat(metrics): support multiple Prometheus-compatible metrics backends
(METRICS-01)
> Branch: `feature/studio-metrics-multi-source`
> Base: `rocketmq-studio`
> Scope: METRICS-01 — *Metrics collection from multiple backends (≥5
backends)*
## Summary
RocketMQ Studio previously shipped a single hard-coded Prometheus metrics
backend. This
change introduces a pluggable **metrics data-source registry** so the
dashboard can read
RocketMQ Prometheus metrics from several compatible backends behind one
unified query API.
Six Prometheus-compatible backend types are supported out of the box, plus a
free-form
`CUSTOM` type, satisfying the "≥5 backends" requirement:
| Backend | Query path |
|---|---|
| `PROMETHEUS` | `/api/v1/query_range` |
| `VICTORIA_METRICS` | `/select/0/prometheus/api/v1/query_range` |
| `THANOS` | `/api/v1/query_range` |
| `CORTEX` | `/api/v1/query_range` |
| `MIMIR` | `/prometheus/api/v1/query_range` |
| `ARMS` (Alibaba Cloud Managed Prometheus) | `/api/v1/query_range` |
| `CUSTOM` | user-supplied base path |
All backends share one `AbstractPrometheusCompatibleMetricsSource` base
class; concrete
sources only override the query path, so adding a new Prometheus-compatible
backend is a
~30-line class.
## Changes
### Backend (`server/.../cluster/metrics`)
- `MetricsBackendType` — enum of supported backends with their PromQL
`query_range` paths.
- `MetricsSourceSettings` / `MetricsDataSourceConfig` — data-source
configuration model
(name, type, base URL, auth, scrape interval, etc.).
- `AbstractPrometheusCompatibleMetricsSource` — shared HTTP query
implementation.
- `PrometheusMetricsSource` (refactored), `VictoriaMetricsMetricsSource`,
`ThanosMetricsSource`, `CortexMetricsSource`, `MimirMetricsSource`,
`ArmsMetricsSource`
— concrete sources.
- `MetricsSourceFactory` — builds a source instance from a config.
- `MetricsDataSourceRepository` + `InMemoryMetricsDataSourceRepository` —
registry store.
- `MetricsDataSourceService` — CRUD + query orchestration.
- `MetricsDataSourceController` — REST endpoints.
### Frontend (`web/...`)
- `api/metrics.ts` — added data-source CRUD + query client functions.
- `services/metricsService.ts` — service layer with mock/real data-mode
support.
- `mock/metricsDataSources.ts` — sample data sources for mock mode.
- `components/MetricsDataSourceManager.tsx` — table + create/edit modal
manager.
- `pages/studio/MetricsDataSources.tsx` — page wired into the studio nav.
- `layouts/MainLayout.tsx`, `App.tsx` — navigation entry + lazy route.
- `i18n/translations.ts` — `metricsDataSource.*` keys (zh/en).
## API
```
GET /api/metrics/datasources # list configured data sources
POST /api/metrics/datasources/create # create a data source
POST /api/metrics/datasources/update # update a data source
DELETE /api/metrics/datasources?name=... # delete a data source
POST /api/metrics/datasources/query # run a PromQL query against a
source
```
## Testing
- **Backend** (`server/src/test/.../cluster/metrics`):
- `MetricsBackendTypeTest` — enum parsing / query-path mapping.
- `MetricsDataSourceServiceTest` — CRUD + repository behavior.
- `MetricsDataSourceControllerTest` — WebMvc endpoint coverage.
- `MultiBackendMetricsSourceTest` — verifies all 6 backends issue correct
queries.
- All pass; Checkstyle clean.
- **Frontend** (`web/src`):
- `api/metrics.test.ts` (data-source cases),
`services/metricsService.test.ts`,
`components/__tests__/MetricsDataSourceManager.test.tsx`.
- `tsc --noEmit` clean; ESLint clean.
## Notes / Follow-ups
- Store is in-memory (consistent with other studio modules); a persistent
store can be
added later behind the same `MetricsDataSourceRepository` interface.
- Frontend respects the existing mock/real data-mode toggle, so the UI is
demoable without
a live backend.
--
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]