Documentation
¶
Index ¶
- Constants
- type Component
- type Metrics
- func (m *Metrics) AddTimeAsLeader(seconds float64)
- func (m *Metrics) RecordConfigRejected(validator string)
- func (m *Metrics) RecordDeployment(durationSeconds float64, success bool)
- func (m *Metrics) RecordDeploymentOperations(reloads, apiOperations int)
- func (m *Metrics) RecordEvent()
- func (m *Metrics) RecordEventDrop(subscriberName, eventType string)
- func (m *Metrics) RecordHAProxyPodRejected(reason string)
- func (m *Metrics) RecordLeadershipTransition()
- func (m *Metrics) RecordQueueWait(seconds float64)
- func (m *Metrics) RecordReconciliation(durationSeconds float64, success bool)
- func (m *Metrics) RecordRuntimeFastPath(serverUpdates int, failed bool)
- func (m *Metrics) RecordValidation(success bool)
- func (m *Metrics) RecordWebhookRequest(gvk, result string, durationSeconds float64)
- func (m *Metrics) RecordWebhookValidation(gvk, result string)
- func (m *Metrics) SetBuildInfo(version, haproxyVersion, goVersion string)
- func (m *Metrics) SetEventSubscribers(count int)
- func (m *Metrics) SetIsLeader(isLeader bool)
- func (m *Metrics) SetObservabilityDrops(count uint64)
- func (m *Metrics) SetResourceCount(resourceType string, count int)
Constants ¶
const ComponentName = "metrics"
ComponentName is the unique identifier for the metrics component.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Component ¶
type Component struct {
// contains filtered or unexported fields
}
Component is an event-driven metrics collector.
Subscribes to controller events and updates metrics via the Metrics struct. This is an event adapter that bridges domain events to Prometheus metrics.
IMPORTANT: Instance-based, created fresh per application iteration. When the iteration ends (context cancelled), the component stops and the metrics it was updating become eligible for garbage collection.
func New ¶
New creates a new metrics component that listens to events.
Parameters:
- metrics: The Metrics instance to update (created with metrics.NewMetrics)
- eventBus: The EventBus to subscribe to for events
Usage:
registry := prometheus.NewRegistry() metrics := metrics.NewMetrics(registry) component := metrics.New(metrics, eventBus) go component.Start(ctx) eventBus.Start()
type Metrics ¶
type Metrics struct {
// Reconciliation metrics
ReconciliationDuration prometheus.Histogram
ReconciliationTotal prometheus.Counter
ReconciliationErrors prometheus.Counter
// Deployment metrics
DeploymentDuration prometheus.Histogram
DeploymentTotal prometheus.Counter
DeploymentErrors prometheus.Counter
// HAProxy reload + DataPlane API operation counters, populated from
// DeploymentCompletedEvent. Reloads are the canonical capacity/SLO signal: a
// reload momentarily forks the HAProxy process, so a high reload rate (vs
// runtime-API updates) is what to capacity-plan and alert on. The data is
// already carried on the event; these surface it as cumulative counters.
HAProxyReloadsTotal prometheus.Counter
DataplaneAPIOperationsTotal prometheus.Counter
// Runtime-eligible fast-path metrics. Fires counts every fast-path attempt
// (one per pod per reconcile); Applies counts the subset that actually
// applied >=1 runtime-eligible server update. Applies stuck at 0 while
// Fires climbs means the fast path runs but the render diff never carries a
// runtime-eligible change.
RuntimeFastPathFires prometheus.Counter
RuntimeFastPathApplies prometheus.Counter
RuntimeFastPathFailures prometheus.Counter
RuntimeFastPathServerUpdates prometheus.Counter
// Validation metrics
ValidationTotal prometheus.Counter
ValidationErrors prometheus.Counter
// Resource metrics
ResourceCount *prometheus.GaugeVec
// Event metrics
EventSubscribers prometheus.Gauge
EventsPublished prometheus.Counter
EventsDropped prometheus.Counter // Total drops (backwards compatible)
EventsDroppedCritical prometheus.Counter // Drops from critical subscribers (alert-worthy)
EventsDroppedBySubscriber *prometheus.CounterVec // Drops by subscriber and event type
EventsDroppedObservability prometheus.Gauge // Drops from observability subscribers (polled, expected)
// Queue wait metrics - time events spend waiting in channels before processing
ReconciliationQueueWait prometheus.Histogram
// Webhook metrics
WebhookRequestsTotal *prometheus.CounterVec
WebhookRequestDuration prometheus.Histogram
WebhookValidationTotal *prometheus.CounterVec
// Leader election metrics
LeaderElectionIsLeader prometheus.Gauge
LeaderElectionTransitionsTotal prometheus.Counter
LeaderElectionTimeAsLeaderSeconds prometheus.Counter
// Parser cache metrics. Registered as CounterFuncs that report the
// parser package's cumulative hit/miss counters directly on each scrape,
// so there is no readback or delta tracking to keep them in sync.
ParserCacheHits prometheus.CounterFunc
ParserCacheMisses prometheus.CounterFunc
// Discovery metrics — surfaces rejection of HAProxy pods that the
// controller refuses to talk to (most commonly version-incompatible).
// Without this counter, a misconfigured cluster (e.g., controller image
// bundling HAProxy 3.3 while chart deploys 3.2) presents only as
// "deployment.skipped" in the pipeline status, masking a real fault.
HAProxyPodsRejectedTotal *prometheus.CounterVec
// ConfigRejectedTotal counts HAProxyTemplateConfig loads refused by the
// config-validation gate, labelled by the validator that rejected it
// (basic / template / jsonpath / validationtests), or "coordinator" when the
// scatter-gather itself failed — a validator timed out or didn't respond —
// rather than a specific validator refusing the config. Persistent growth
// means the controller is repeatedly refusing a new config and continuing to
// serve the last-good one — the operator's config never took effect.
ConfigRejectedTotal *prometheus.CounterVec
// Build info metric
BuildInfo *prometheus.GaugeVec
}
Metrics holds all controller-specific Prometheus metrics.
IMPORTANT: Create one instance per application iteration. When the iteration ends (e.g., on config reload), metrics are garbage collected. This prevents stale state from surviving across reinitialization cycles.
func NewMetrics ¶
func NewMetrics(registry prometheus.Registerer) *Metrics
New creates all controller metrics and registers them with the provided registry.
IMPORTANT: Pass an instance-based registry (prometheus.NewRegistry()), NOT prometheus.DefaultRegisterer. Metrics are scoped to the registry's lifetime. When the registry is garbage collected (iteration ends), metrics are freed.
This is critical for supporting application reinitialization on configuration changes without leaking metrics or accumulating stale state.
Example:
registry := prometheus.NewRegistry() // Create per iteration metrics := metrics.NewMetrics(registry) // Metrics tied to iteration // ... use metrics ... // When iteration ends, both registry and metrics are GC'd
func (*Metrics) AddTimeAsLeader ¶
AddTimeAsLeader adds time spent as leader to the cumulative counter.
Parameters:
- seconds: Time spent as leader in seconds
func (*Metrics) RecordConfigRejected ¶
RecordConfigRejected increments the config-rejection counter for the given validator (the one whose check failed).
func (*Metrics) RecordDeployment ¶
RecordDeployment records a deployment attempt.
Parameters:
- durationSeconds: Time spent deploying (use time.Since(start).Seconds())
- success: Whether the deployment completed successfully
func (*Metrics) RecordDeploymentOperations ¶
RecordDeploymentOperations records the HAProxy reload count and DataPlane API operation count from a completed deployment. Both are cumulative; reloads is the headline capacity/SLO signal (see the metric help text). Zero values are skipped so a no-op deployment doesn't perturb the counters.
func (*Metrics) RecordEvent ¶
func (m *Metrics) RecordEvent()
RecordEvent records an event publication. Call this for every event published to the EventBus.
func (*Metrics) RecordEventDrop ¶
RecordEventDrop records an event drop due to full subscriber buffer. This increments both aggregate counters and per-subscriber counters. Call this from the drop callback registered with EventBus.SetDropCallback().
Parameters:
- subscriberName: The name of the subscriber that dropped the event
- eventType: The event type that was dropped
func (*Metrics) RecordHAProxyPodRejected ¶
RecordHAProxyPodRejected increments the rejection counter for a stable reason label (e.g. "version_mismatch_older", "version_check_failed"). Discovery publishes HAProxyPodRejectedEvent; the metrics component translates each event into a counter increment.
func (*Metrics) RecordLeadershipTransition ¶
func (m *Metrics) RecordLeadershipTransition()
RecordLeadershipTransition records a leadership state change. Call this whenever leadership is gained or lost.
func (*Metrics) RecordQueueWait ¶
RecordQueueWait records how long a reconciliation event waited in the coordinator queue before processing started.
func (*Metrics) RecordReconciliation ¶
RecordReconciliation records a completed reconciliation cycle.
Parameters:
- durationSeconds: Time spent in reconciliation (use time.Since(start).Seconds())
- success: Whether the reconciliation completed successfully
func (*Metrics) RecordRuntimeFastPath ¶
RecordRuntimeFastPath records one runtime-eligible fast-path apply attempt: serverUpdates is how many server updates it applied (0 = fired but nothing to do), failed reports whether it errored.
func (*Metrics) RecordValidation ¶
RecordValidation records a validation attempt.
Parameters:
- success: Whether the validation passed
func (*Metrics) RecordWebhookRequest ¶
RecordWebhookRequest records a webhook admission request.
Parameters:
- gvk: The GVK of the resource being validated (e.g., "v1.ConfigMap")
- result: The result of the request ("allowed", "denied", or "error")
- durationSeconds: Time spent processing the request
func (*Metrics) RecordWebhookValidation ¶
RecordWebhookValidation records a webhook validation result.
Parameters:
- gvk: The GVK of the resource being validated
- result: The validation result ("allowed", "denied", or "error")
func (*Metrics) SetBuildInfo ¶
SetBuildInfo sets the build info metric with version labels. Call once at startup with the version information for this binary.
Parameters:
- version: The controller version (e.g., "0.1.0-alpha.10")
- haproxyVersion: The HAProxy major.minor version (e.g., "3.2")
- goVersion: The Go runtime version (e.g., "go1.26.1")
func (*Metrics) SetEventSubscribers ¶
SetEventSubscribers sets the number of active event subscribers.
Parameters:
- count: The current number of event subscribers
func (*Metrics) SetIsLeader ¶
SetIsLeader sets whether this replica is the leader.
Parameters:
- isLeader: true if this replica is the leader, false otherwise
func (*Metrics) SetObservabilityDrops ¶
SetObservabilityDrops sets the observability drop gauge from EventBus statistics. This should be called periodically since observability drops don't trigger callbacks.
func (*Metrics) SetResourceCount ¶
SetResourceCount sets the count for a specific resource type.
Parameters:
- resourceType: The type of resource (e.g., "ingresses", "services")
- count: The current number of resources of this type