Documentation
¶
Overview ¶
Package monitoring provides Prometheus metrics and recording helpers for the Multigres Operator. It exposes domain-specific gauges and counters that complement the generic controller-runtime metrics already registered by the framework.
All metrics follow the naming convention multigres_<component>_<metric>_<unit> and are registered against controller-runtime's default Prometheus registry on import.
Usage in controllers:
monitoring.SetClusterInfo(cluster.Name, cluster.Namespace, string(cluster.Status.Phase)) monitoring.SetCellGatewayReplicas(cell.Name, cell.Namespace, desired, ready)
Usage in webhooks:
monitoring.RecordWebhookRequest("CREATE", "MultigresCluster", err, elapsed)
Index ¶
- Variables
- func Collectors() []prometheus.Collector
- func EnrichLoggerWithTrace(ctx context.Context) context.Context
- func ExtractTraceContext(annotations map[string]string) (context.Context, bool)
- func IncrementDrainOperations(cluster, shard, result string)
- func InitTracing(ctx context.Context, serviceName, version string) (func(context.Context) error, error)
- func InjectTraceContext(ctx context.Context, annotations map[string]string)
- func RecordSpanError(span trace.Span, err error)
- func RecordWebhookRequest(operation, resource string, err error, duration time.Duration)
- func SetCellGatewayReplicas(cell, namespace string, desired, ready int32)
- func SetClusterInfo(name, namespace, phase string)
- func SetClusterTopology(cluster, namespace string, cells, shards int)
- func SetLastBackupAge(cluster, shard, namespace string, age time.Duration)
- func SetPoolPodsDrifted(cluster, shard, pool, cell, namespace string, count int)
- func SetRollingUpdateInProgress(cluster, shard, pool, cell, namespace string, inProgress bool)
- func SetShardPoolReplicas(cluster, shard, pool, cell, namespace string, desired, ready int32)
- func SetTopoServerReplicas(name, namespace string, desired, ready int32)
- func StartChildSpan(ctx context.Context, spanName string) (context.Context, trace.Span)
- func StartReconcileSpan(ctx context.Context, spanName, name, namespace, kind string) (context.Context, trace.Span)
Constants ¶
This section is empty.
Variables ¶
var Tracer = otel.Tracer(tracerName)
Tracer is the package-level OTel tracer for the operator. It returns a noop tracer when no TracerProvider is registered, making instrumentation zero-cost in the default configuration.
Functions ¶
func Collectors ¶
func Collectors() []prometheus.Collector
Collectors returns all registered metric collectors. This is useful for testing that metrics are properly registered.
func EnrichLoggerWithTrace ¶
EnrichLoggerWithTrace extracts the trace ID and span ID from the current span context and injects them as structured key-value pairs into the logr logger carried by ctx. All downstream log lines will automatically include these fields, enabling "click log → view trace" in Grafana.
func ExtractTraceContext ¶
ExtractTraceContext reads the traceparent annotation from a Kubernetes object and reconstructs the parent span context. The second return value is true when the annotation is older than staleThreshold (10 minutes), indicating the caller should create a new root span with a Link instead of a child span.
Returns (background context, false) if no valid annotation is found.
func IncrementDrainOperations ¶
func IncrementDrainOperations(cluster, shard, result string)
IncrementDrainOperations increments the counter for drain operations.
func InitTracing ¶
func InitTracing( ctx context.Context, serviceName, version string, ) (func(context.Context) error, error)
InitTracing initialises the OTel TracerProvider using autoexport. The transport protocol is determined by OTEL_EXPORTER_OTLP_PROTOCOL (default: "http/protobuf"). Supported values: "grpc", "http/protobuf". If OTEL_EXPORTER_OTLP_ENDPOINT is unset, tracing is left disabled and a noop shutdown function is returned.
func InjectTraceContext ¶
InjectTraceContext writes the current span's W3C traceparent and a Unix-second timestamp into the given annotations map. The webhook uses this to bridge the async gap between admission and reconciliation.
func RecordSpanError ¶
RecordSpanError records an error on a span and sets the span status to Error. If err is nil, this is a no-op.
func RecordWebhookRequest ¶
RecordWebhookRequest records a webhook admission request's result and duration.
func SetCellGatewayReplicas ¶
SetCellGatewayReplicas sets the desired and ready gateway replica gauges for a Cell.
func SetClusterInfo ¶
func SetClusterInfo(name, namespace, phase string)
SetClusterInfo sets the info-style gauge for a MultigresCluster. Old phase labels are automatically cleaned up via DeletePartialMatch.
func SetClusterTopology ¶
SetClusterTopology sets the cell and shard count gauges for a cluster.
func SetLastBackupAge ¶
SetLastBackupAge sets the age of the most recent completed backup for a shard.
func SetPoolPodsDrifted ¶
SetPoolPodsDrifted sets the count of pods with spec-hash mismatch in a pool/cell.
func SetRollingUpdateInProgress ¶
SetRollingUpdateInProgress sets whether a rolling update is currently in progress for a pool.
func SetShardPoolReplicas ¶
SetShardPoolReplicas sets the desired and ready replica gauges for a shard pool.
func SetTopoServerReplicas ¶
SetTopoServerReplicas sets the desired and ready replica gauges for a TopoServer.
func StartChildSpan ¶
StartChildSpan starts a child span under the current trace context. Use this for sub-operations within a reconciliation (e.g., ReconcileCells, UpdateStatus).
func StartReconcileSpan ¶
func StartReconcileSpan( ctx context.Context, spanName, name, namespace, kind string, ) (context.Context, trace.Span)
StartReconcileSpan starts a new span for a controller reconciliation. The span is annotated with the Kubernetes resource name, namespace, and kind. Callers must call span.End() when the operation completes.
Types ¶
This section is empty.