feat: add metric server performance metrics - #7903
Conversation
Expose Prometheus and OpenTelemetry metrics for HPA external metric requests on the metrics adapter and GetMetrics gRPC handling on the operator, with unit and e2e coverage. Fixes kedacore#3120 Signed-off-by: kshitizlohia1994 <kshitizlohia1994@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
|
Thank you for your contribution! 🙏 Please understand that we will do our best to review your PR and give you feedback as soon as possible, but please bear with us if it takes a little longer as expected. While you are waiting, make sure to:
Once the initial tests are successful, a KEDA member will ensure that the e2e tests are run. Once the e2e tests have been successfully completed, the PR may be merged at a later date. Please be patient. Learn more about our contribution guide. |
Signed-off-by: kshitizlohia1994 <kshitizlohia1994@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR adds performance-focused metrics around KEDA’s “metric server” flow: HPA external metrics requests handled by keda-metrics-apiserver and GetMetrics gRPC calls handled by keda-operator, with both Prometheus and optional OpenTelemetry coverage.
Changes:
- Instrument
GetExternalMetric(adapter) andGetMetrics(operator) with request-count and duration metrics (Prometheus + optional OTEL). - Add unit tests for the new metrics collectors and extend sequential e2e metric assertions for both Prometheus and OpenTelemetry scenarios.
- Document the user-visible change in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/sequential/prometheus_metrics/prometheus_metrics_test.go | Adds assertions for new Prometheus performance metrics (adapter + operator). |
| tests/sequential/opentelemetry_metrics/opentelemetry_metrics_test.go | Adds assertions for OpenTelemetry-exported (Prometheus-exposed) operator GetMetrics metrics. |
| pkg/provider/provider.go | Instruments adapter external metrics requests and records duration/outcome. |
| pkg/metricsservice/server.go | Instruments operator GetMetrics gRPC handler and records duration/outcome. |
| pkg/metricscollector/prommetrics.go | Defines/registers new Prometheus metrics and records GetMetrics request metrics in operator collector. |
| pkg/metricscollector/opentelemetry.go | Defines OTEL instruments and records GetMetrics request metrics in operator OTEL collector. |
| pkg/metricscollector/opentelemetry_test.go | Adds unit test coverage for the new OTEL GetMetrics instruments. |
| pkg/metricscollector/metricserver_performance.go | Introduces adapter-side performance metrics (Prometheus + optional OTEL exporter init). |
| pkg/metricscollector/metricserver_performance_test.go | Adds unit tests for adapter performance metrics and shared request-result labeling. |
| pkg/metricscollector/metricscollectors.go | Extends the collector interface and adds a package-level recording helper for operator GetMetrics. |
| pkg/metricscollector/export_test.go | Exposes test helpers for adapter OTEL performance metrics initialization/reset. |
| cmd/adapter/main.go | Registers adapter performance metrics and adds --enable-opentelemetry-metrics flag. |
| CHANGELOG.md | Adds an “Unreleased” Improvements entry for the new performance metrics. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
/run-e2e sequential passed tests: 5failed tests: 0 |
…nc.Once doc Signed-off-by: kshitizlohia1994 <kshitizlohia1994@gmail.com>
|
/run-e2e sequential passed tests: 5failed tests: 0 |
|
@rickbrouwer @JorTurFer can you please review when you get a chance? |
Add Prometheus and OpenTelemetry performance metrics for the HPA external metrics path on keda-metrics-apiserver and GetMetrics gRPC handling on keda-operator.
Checklist
make generate-scalers-schemahas been run to update any outdated generated filesFixes #3120
Relates to kedacore/keda-docs#1804
Summary
keda_external_metrics_provider_*Prometheus metrics (and optional OTEL via--enable-opentelemetry-metrics) for each HPA external metric requestkeda_metricsservice_get_metrics_*Prometheus/OTEL metrics for each GetMetrics gRPC callpkg/metricscollectorand e2e assertions in prometheus/opentelemetry metrics testsTest plan
go test ./pkg/metricscollector/...make fmt,make vet,make golangci,make test(CI)prometheus_metricsandopentelemetry_metrics