Instance Sidecar Metrics#
Overview#
The instance sidecar in plugin-barman-cloud exposes a Metrics gRPC service as part of its CNPG-I interface. The service is implemented in internal/cnpgi/instance/metrics.go and registered alongside the WAL, Backup, and health-check services when the sidecar starts .
The handler is entirely read-only: it never writes to Kubernetes, never acquires any lock, and has no synchronization with the CatalogMaintenanceRunnable retention cycle that runs concurrently in the same process.
Exposed Metrics#
Three Prometheus gauges are declared in Define and collected in Collect. All names are derived from the plugin name (sanitized to a valid Prometheus namespace) via buildFqName:
| Metric (suffix) | Help string |
|---|---|
first_recoverability_point | First point of recoverability for the cluster (unix timestamp) |
last_available_backup_timestamp | Last successful backup (unix timestamp) |
last_failed_backup_timestamp | Last failed backup (unix timestamp) |
All three are TYPE_GAUGE . Zero is returned for any metric whose source field is nil or when the server name is not yet present in the ObjectStore status .
How Collect Works#
On every scrape the handler :
- Parses the cluster definition from the gRPC request payload via
config.NewFromClusterJSONto determine the ObjectStore key and server name. - Fetches the
ObjectStoreCR from the Kubernetes API using a controller-runtime cached client β a singleclient.Getcall, no barman CLI invocation. - Reads
ObjectStore.Status.ServerRecoveryWindow[serverName]β a map populated by the backup and retention paths. - Returns the three timestamps as
float64Unix values, or zeros if the window entry is absent.
The cached client means the call reads from the in-memory informer cache rather than going to the API server on every scrape.
No Shared State with the Retention Cycle#
The metrics service has no mutex, channel, or other synchronization with CatalogMaintenanceRunnable . Both run concurrently as separate controller-runtime runnables registered in manager.go .
This is safe by design: the metrics handler is read-only and the retention cycle writes ObjectStore.Status via a Kubernetes API call with retry-on-conflict. Kubernetes optimistic concurrency is the only coordination mechanism. The worst-case outcome is that a scrape observes a slightly stale value from the informer cache between a retention cycle write and the cache refresh β not a crash or data race.
Registration#
metricsImpl is registered in CNPGI.Start:
metrics.RegisterMetricsServer(server, &metricsImpl{
Client: c.Client,
})
It receives only the controller-runtime client.Client; it holds no other state .
The GetCapabilities RPC advertises a single RPC_TYPE_METRICS capability , which tells the CNPG-I framework that this plugin provides custom metrics.
Key Source Files#
| File | Purpose |
|---|---|
internal/cnpgi/instance/metrics.go | Full metrics service implementation |
internal/cnpgi/instance/start.go | Service registration |
internal/cnpgi/instance/manager.go | Registers both the gRPC server and CatalogMaintenanceRunnable |
internal/cnpgi/instance/retention.go | Retention cycle that writes the ObjectStore status the metrics read |
internal/cnpgi/instance/recovery_window.go | updateRecoveryWindow β writes ObjectStore.Status.ServerRecoveryWindow |