postgres controllers metrics#1811
Merged
limak9182 merged 7 commits intofeature/database-controllersfrom Apr 10, 2026
Merged
Conversation
Contributor
|
CLA Assistant Lite bot: I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request |
M4KIF
reviewed
Apr 9, 2026
mploski
reviewed
Apr 9, 2026
mploski
reviewed
Apr 9, 2026
mploski
reviewed
Apr 9, 2026
mploski
reviewed
Apr 9, 2026
DmytroPI-dev
approved these changes
Apr 10, 2026
67a0ed2
into
feature/database-controllers
13 of 29 checks passed
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description
Adds comprehensive Prometheus metrics for the PostgreSQL controllers using a hexagonal
(ports & adapters) pattern — the domain code depends only on a
Recorderinterface, neveron Prometheus directly.
New package:
pkg/postgresql/metrics/ports.go—Recorderinterface (the port). Core service packages import only this.prometheus.go—PrometheusRecorderadapter: 6 metric families withsplunk_operator_postgres_prefix, registered against the controller-runtime metrics registry.noop.go—NoopRecorderfor unit tests.collector.go—FleetCollectorthat recomputes fleet-state gauges from the informer cache after each reconcile.Three-layer metrics collection:
controller_runtime_reconcile_total,_time_seconds,_errors_totalFleetCollectorlists CRs from cache and sets gaugesIncStatusTransition()called automatically insidepersistStatus/setStatus— zero manual metric calls in service codeCustom metrics (6 families):
status_transitions_totalclustersdatabasesmanaged_userspoolerspooler_instancesDesign decisions:
IncStatusTransitionis called insidepersistStatus/setStatus, so every condition write is automatically captured with no explicit calls scattered through service codecontroller,condition,status,reason,phase) — no per-resourcename/namespacelabelsNoopRecorder) and adapter swappabilitypkg/splunk/client/metrics/is untouchedKey Changes
pkg/postgresql/metrics/— new package: port interface, Prometheus adapter, noop adapter, fleet collectorpkg/postgresql/cluster/core/cluster.go—setStatus,syncPoolerStatus,syncStatusnow acceptRecorderand emitIncStatusTransitionautomaticallypkg/postgresql/database/core/database.go—persistStatusnow acceptsRecorderand emitsIncStatusTransitionautomatically. Also adds 2 missingupdateStatuscalls on error paths (role patch failure, database reconcile failure)pkg/postgresql/{cluster,database}/core/types.go—Metrics pgmetrics.Recorderfield added toReconcileContextinternal/controller/postgres{cluster,database}_controller.go— injectMetricsintoReconcileContext, call fleet collector after each reconcilecmd/main.go— createPrometheusRecorder, register with controller-runtime metrics registry, pass to controllersTesting and Verification
Setting up Grafana + Prometheus on KIND
1. Install the monitoring stack
kubectl port-forward svc/kube-prometheus-grafana -n monitoring 3000:80
Open http://localhost:3000 — login: admin / admin
The Prometheus datasource is auto-configured. Query any metric with the splunk_operator_postgres_ prefix.
Related Issues
Jira tickets, GitHub issues, Support tickets...
PR Checklist