feat: add Prometheus metrics for operator reconciliation#793
Merged
Conversation
Add a pkg/metrics package that registers reconciliation metrics with the
controller-runtime registry, so they are exposed automatically on the
manager's existing metrics endpoint (default :8080/metrics):
- meshery_operator_reconcile_total{controller}
- meshery_operator_reconcile_errors_total{controller}
- meshery_operator_reconcile_duration_seconds{controller}
Instrument the Broker and MeshSync reconcilers via a deferred closure that
records count, duration, and (on a non-nil error) the error counter. Named
return values keep the instrumentation out of the reconciliation control
flow without rewriting each return site.
Tests assert that all three metrics are registered with the
controller-runtime registry and that counters and the histogram record
values as expected.
This rebases the instrumentation onto the post-Kubebuilder-go/v4 (WS-1)
layout: the test tooling and contributor docs are now provided by the
Makefile test target and docs/testing.md, so no Makefile or CONTRIBUTING
changes are needed here.
Signed-off-by: Lee Calcote <lee.calcote@layer5.io>
1 task
Member
|
/gemini review |
There was a problem hiding this comment.
Pull request overview
This PR adds first-class Prometheus reconciliation observability to Meshery Operator by defining and registering controller-runtime metrics and instrumenting the Broker and MeshSync controllers to record reconcile counts, errors, and latency.
Changes:
- Introduces a new
pkg/metricspackage that registers reconcile metrics with the controller-runtime metrics registry (auto-exposed on the manager metrics endpoint). - Instruments
BrokerReconcilerandMeshSyncReconcilerreconcile loops using a single top-leveldeferto consistently record total reconciles, duration, and error counts. - Adds unit tests validating metric registration and basic counter/histogram behavior; updates
go.modto add a direct Prometheus client dependency.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/metrics/metrics.go | Defines and registers reconcile counters/histogram with controller-runtime’s metrics registry. |
| pkg/metrics/metrics_test.go | Verifies metrics are registered and that counters/histogram accept observations. |
| controllers/broker_controller.go | Adds deferred reconcile instrumentation (total/errors/duration) to Broker controller. |
| controllers/meshsync_controller.go | Adds deferred reconcile instrumentation (total/errors/duration) to MeshSync controller. |
| go.mod | Adds prometheus/client_golang as a direct dependency and updates indirect deps accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add docs/metrics.md describing the three Prometheus reconciliation metrics added in this PR (meshery_operator_reconcile_total, _errors_total, _duration_seconds), how they register with the controller-runtime registry and surface on the manager's :8080/metrics endpoint, the defer-based named-return instrumentation pattern in both controllers, how to add a new metric, and the test conventions. Note the WS-5 follow-ups (metrics TLS, ServiceMonitor). Link it from the docs README index. Signed-off-by: Lee Calcote <lee.calcote@layer5.io>
jamieplu
approved these changes
Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fDescription
This PR fixes #779.
Adds reconciliation observability to the operator and continues the work started in #780 by @Chaithanya5gif, rebased onto the post-Kubebuilder-go/v4 (WS-1) layout per the request on that PR.
A new
pkg/metricspackage registers three metrics with the controller-runtime registry, so they are exposed automatically on the manager's existing metrics endpoint (default:8080/metrics) with no extra wiring:meshery_operator_reconcile_total{controller}meshery_operator_reconcile_errors_total{controller}meshery_operator_reconcile_duration_seconds{controller}The
BrokerReconcilerandMeshSyncReconcilerare instrumented via a deferred closure that records the count and duration on every reconcile and increments the error counter only when a non-nil error is returned.Notes for Reviewers
Carried over from #780 (metric naming and the defer-based timing pattern), with the following review changes applied:
CONTRIBUTING.mdchanges from feat: add Prometheus metrics for operator reconciliation #780 — WS-1 already provides the envtest-awaremake testtarget and contributor docs (docs/testing.md), so those edits are now obsolete and would conflict.result,reconcileErr) keep the instrumentation in a singledeferat the top ofReconcileinstead of rewriting every return site, minimizing churn in the control flow.goconst, grouped imports forgci/goimports, added the Apache license headers, and renamed an innerresultto avoid shadowing undergovet's shadow analyzer.Verified locally:
gofmt,go vet,go build ./...,golangci-lint v2.12.2 run ./...(0 issues), and the full unit/envtest suite (make test) all pass.Signed commits