monitoring

package
v0.10.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 12, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func EnrichLoggerWithTrace(ctx context.Context) context.Context

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

func ExtractTraceContext(annotations map[string]string) (context.Context, bool)

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

func InjectTraceContext(ctx context.Context, annotations map[string]string)

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

func RecordSpanError(span trace.Span, err error)

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

func RecordWebhookRequest(operation, resource string, err error, duration time.Duration)

RecordWebhookRequest records a webhook admission request's result and duration.

func SetCellGatewayReplicas

func SetCellGatewayReplicas(cell, namespace string, desired, ready int32)

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

func SetClusterTopology(cluster, namespace string, cells, shards int)

SetClusterTopology sets the cell and shard count gauges for a cluster.

func SetLastBackupAge

func SetLastBackupAge(cluster, shard, namespace string, age time.Duration)

SetLastBackupAge sets the age of the most recent completed backup for a shard.

func SetPoolPodsDrifted

func SetPoolPodsDrifted(cluster, shard, pool, cell, namespace string, count int)

SetPoolPodsDrifted sets the count of pods with spec-hash mismatch in a pool/cell.

func SetRollingUpdateInProgress

func SetRollingUpdateInProgress(cluster, shard, pool, cell, namespace string, inProgress bool)

SetRollingUpdateInProgress sets whether a rolling update is currently in progress for a pool.

func SetShardPoolReplicas

func SetShardPoolReplicas(cluster, shard, pool, cell, namespace string, desired, ready int32)

SetShardPoolReplicas sets the desired and ready replica gauges for a shard pool.

func SetTopoServerReplicas

func SetTopoServerReplicas(name, namespace string, desired, ready int32)

SetTopoServerReplicas sets the desired and ready replica gauges for a TopoServer.

func StartChildSpan

func StartChildSpan(ctx context.Context, spanName string) (context.Context, trace.Span)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL