Skip to content

feat: add metric server performance metrics - #7903

Open
kshitizlohia1994 wants to merge 4 commits into
kedacore:mainfrom
kshitizlohia1994:feat/metric-server-performance-metrics-3120
Open

feat: add metric server performance metrics#7903
kshitizlohia1994 wants to merge 4 commits into
kedacore:mainfrom
kshitizlohia1994:feat/metric-server-performance-metrics-3120

Conversation

@kshitizlohia1994

@kshitizlohia1994 kshitizlohia1994 commented Jul 4, 2026

Copy link
Copy Markdown

Add Prometheus and OpenTelemetry performance metrics for the HPA external metrics path on keda-metrics-apiserver and GetMetrics gRPC handling on keda-operator.

Checklist

  • When introducing a new scaler, I agree with the scaling governance policy
  • I have verified that my change is according to the deprecations & breaking changes policy
  • Tests have been added (if applicable)
  • Ensure make generate-scalers-schema has been run to update any outdated generated files
  • Changelog has been updated and is aligned with our changelog requirements, only when the change impacts end users
  • A PR is opened to update our Helm chart (repo) (if applicable, ie. when deployment manifests are modified)
  • A PR is opened to update the documentation on (repo) (if applicable)
  • Commits are signed with Developer Certificate of Origin (DCO - learn more)

Fixes #3120

Relates to kedacore/keda-docs#1804

Summary

  • Metrics adapter: records keda_external_metrics_provider_* Prometheus metrics (and optional OTEL via --enable-opentelemetry-metrics) for each HPA external metric request
  • Operator: records keda_metricsservice_get_metrics_* Prometheus/OTEL metrics for each GetMetrics gRPC call
  • Adds unit tests in pkg/metricscollector and e2e assertions in prometheus/opentelemetry metrics tests

Test plan

  • go test ./pkg/metricscollector/...
  • make fmt, make vet, make golangci, make test (CI)
  • Sequential e2e: prometheus_metrics and opentelemetry_metrics

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>
@kshitizlohia1994
kshitizlohia1994 requested a review from a team as a code owner July 4, 2026 08:45
@snyk-io

snyk-io Bot commented Jul 4, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

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:

  • Add an entry in our changelog in alphabetical order and link related issue
  • Update the documentation, if needed
  • Add unit & e2e tests for your changes
  • GitHub checks are passing
  • Is the DCO check failing? Here is how you can fix DCO issues

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.

@keda-automation
keda-automation requested a review from a team July 4, 2026 08:45
Signed-off-by: kshitizlohia1994 <kshitizlohia1994@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and GetMetrics (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.

Comment thread pkg/metricscollector/metricscollectors.go
Comment thread pkg/metricscollector/metricserver_performance.go Outdated
@JorTurFer

JorTurFer commented Jul 5, 2026

Copy link
Copy Markdown
Member

/run-e2e sequential
Update: You can check the progress here

passed tests: 5
Execution of tests/sequential/prometheus_metrics/prometheus_metrics_test.go, has passed after "one" attempts
Execution of tests/sequential/disruption/disruption_test.go, has passed after "one" attempts
Execution of tests/sequential/datadog_dca/datadog_dca_test.go, has passed after "one" attempts
Execution of tests/sequential/opentelemetry_metrics/opentelemetry_metrics_test.go, has passed after "one" attempts
Execution of tests/sequential/broken_scaledobject_tolerancy/broken_scaledobject_tolerancy_test.go, has passed after "one" attempts
failed tests: 0

…nc.Once doc

Signed-off-by: kshitizlohia1994 <kshitizlohia1994@gmail.com>
@rickbrouwer

rickbrouwer commented Jul 6, 2026

Copy link
Copy Markdown
Member

/run-e2e sequential
Update: You can check the progress here

passed tests: 5
Execution of tests/sequential/prometheus_metrics/prometheus_metrics_test.go, has passed after "one" attempts
Execution of tests/sequential/broken_scaledobject_tolerancy/broken_scaledobject_tolerancy_test.go, has passed after "one" attempts
Execution of tests/sequential/opentelemetry_metrics/opentelemetry_metrics_test.go, has passed after "one" attempts
Execution of tests/sequential/datadog_dca/datadog_dca_test.go, has passed after "one" attempts
Execution of tests/sequential/disruption/disruption_test.go, has passed after "one" attempts
failed tests: 0

@kshitizlohia1994

Copy link
Copy Markdown
Author

@rickbrouwer @JorTurFer can you please review when you get a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide a metric for metric server performance

4 participants