Documentation
¶
Overview ¶
Package observability provides OpenTelemetry instrumentation for OmniProxy.
Index ¶
- func ListenAndServe(addr string, handler http.Handler) error
- func NewHealthMux(health *HealthChecker, provider *Provider) *http.ServeMux
- type BackendMetrics
- type CommonChecks
- type Config
- type HealthCheck
- type HealthChecker
- func (h *HealthChecker) Handler() http.Handler
- func (h *HealthChecker) IsReady() bool
- func (h *HealthChecker) LivenessHandler() http.Handler
- func (h *HealthChecker) ReadinessHandler() http.Handler
- func (h *HealthChecker) RegisterCheck(name string, check HealthCheck)
- func (h *HealthChecker) SetReady(ready bool)
- type HealthStatus
- type Metrics
- func (m *Metrics) ConnectionClosed(ctx context.Context)
- func (m *Metrics) ConnectionOpened(ctx context.Context)
- func (m *Metrics) MetricsMiddleware(next http.Handler) http.Handler
- func (m *Metrics) RecordCertCacheHit(ctx context.Context)
- func (m *Metrics) RecordCertCacheMiss(ctx context.Context)
- func (m *Metrics) RecordCertGenerated(ctx context.Context, host string)
- func (m *Metrics) RecordRequest(ctx context.Context, method, host string, statusCode int, ...)
- func (m *Metrics) RecordTrafficStoreError(ctx context.Context)
- func (m *Metrics) RecordTrafficStored(ctx context.Context)
- func (m *Metrics) RegisterQueueDepthCallback(meterProvider metric.MeterProvider, fn func() int64) error
- func (m *Metrics) RequestEnd(ctx context.Context)
- func (m *Metrics) RequestStart(ctx context.Context)
- type Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe starts an HTTP server on the given address.
func NewHealthMux ¶
func NewHealthMux(health *HealthChecker, provider *Provider) *http.ServeMux
NewHealthMux creates an http.ServeMux with health and metrics endpoints.
Types ¶
type BackendMetrics ¶
type BackendMetrics struct {
// contains filtered or unexported fields
}
BackendMetrics adapts the observability.Metrics to the backend.Metrics interface.
func NewBackendMetrics ¶
func NewBackendMetrics(m *Metrics) *BackendMetrics
NewBackendMetrics creates a backend.Metrics adapter.
func (*BackendMetrics) IncCacheHit ¶
func (b *BackendMetrics) IncCacheHit()
IncCacheHit increments cache hit counter.
func (*BackendMetrics) IncCacheMiss ¶
func (b *BackendMetrics) IncCacheMiss()
IncCacheMiss increments cache miss counter.
func (*BackendMetrics) IncStoreError ¶
func (b *BackendMetrics) IncStoreError()
IncStoreError increments store error counter.
func (*BackendMetrics) IncStoreSuccess ¶
func (b *BackendMetrics) IncStoreSuccess()
IncStoreSuccess increments successful store counter.
func (*BackendMetrics) ObserveStoreDuration ¶
func (b *BackendMetrics) ObserveStoreDuration(d time.Duration)
ObserveStoreDuration records store operation duration. Note: Currently not implemented in metrics, could add if needed.
func (*BackendMetrics) SetQueueDepth ¶
func (b *BackendMetrics) SetQueueDepth(n int)
SetQueueDepth sets the current queue depth gauge. Note: Queue depth is handled via callback in the main metrics.
type CommonChecks ¶
type CommonChecks struct{}
CommonChecks provides factory functions for common health checks.
func (CommonChecks) DatabaseCheck ¶
func (CommonChecks) DatabaseCheck(pingFunc func() error) HealthCheck
DatabaseCheck returns a health check for database connectivity.
func (CommonChecks) KafkaCheck ¶
func (CommonChecks) KafkaCheck(pingFunc func() error) HealthCheck
KafkaCheck returns a health check for Kafka connectivity.
func (CommonChecks) RedisCheck ¶
func (CommonChecks) RedisCheck(pingFunc func() error) HealthCheck
RedisCheck returns a health check for Redis connectivity.
type Config ¶
type Config struct {
// ServiceName is the name of the service for telemetry.
ServiceName string
// ServiceVersion is the version of the service.
ServiceVersion string
// EnablePrometheus enables the Prometheus metrics exporter.
EnablePrometheus bool
}
Config configures the observability provider.
type HealthCheck ¶
type HealthCheck func() error
HealthCheck is a function that returns nil if healthy, error if not.
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker manages health check state and endpoints.
func NewHealthChecker ¶
func NewHealthChecker() *HealthChecker
NewHealthChecker creates a new health checker.
func (*HealthChecker) Handler ¶
func (h *HealthChecker) Handler() http.Handler
Handler returns an http.Handler that serves both health endpoints. Routes:
- /healthz - liveness probe
- /readyz - readiness probe
- /health - alias for /healthz
func (*HealthChecker) IsReady ¶
func (h *HealthChecker) IsReady() bool
IsReady returns whether the service is ready.
func (*HealthChecker) LivenessHandler ¶
func (h *HealthChecker) LivenessHandler() http.Handler
LivenessHandler returns an http.Handler for the /healthz endpoint. Returns 200 if the process is alive, used by Kubernetes liveness probe.
func (*HealthChecker) ReadinessHandler ¶
func (h *HealthChecker) ReadinessHandler() http.Handler
ReadinessHandler returns an http.Handler for the /readyz endpoint. Returns 200 if ready to receive traffic, 503 if not. Used by Kubernetes readiness probe and load balancers.
func (*HealthChecker) RegisterCheck ¶
func (h *HealthChecker) RegisterCheck(name string, check HealthCheck)
RegisterCheck registers a named health check.
func (*HealthChecker) SetReady ¶
func (h *HealthChecker) SetReady(ready bool)
SetReady marks the service as ready to receive traffic.
type HealthStatus ¶
type HealthStatus struct {
Status string `json:"status"`
Timestamp string `json:"timestamp"`
Uptime string `json:"uptime,omitempty"`
Checks map[string]string `json:"checks,omitempty"`
}
HealthStatus represents the health status response.
type Metrics ¶
type Metrics struct {
// Request metrics
RequestsTotal metric.Int64Counter
RequestDuration metric.Float64Histogram
ActiveRequests metric.Int64UpDownCounter
// Response metrics
ResponseSize metric.Int64Histogram
// Certificate metrics
CertsGenerated metric.Int64Counter
CertsCacheHits metric.Int64Counter
CertsCacheMiss metric.Int64Counter
// Traffic store metrics
TrafficStored metric.Int64Counter
TrafficStoreErrors metric.Int64Counter
TrafficQueueDepth metric.Int64ObservableGauge
// Connection metrics
ActiveConnections metric.Int64UpDownCounter
// contains filtered or unexported fields
}
Metrics holds all OmniProxy metrics.
func NewMetrics ¶
func NewMetrics(meterProvider metric.MeterProvider) (*Metrics, error)
NewMetrics creates a new Metrics instance with all instruments registered.
func (*Metrics) ConnectionClosed ¶
ConnectionClosed should be called when a connection is closed.
func (*Metrics) ConnectionOpened ¶
ConnectionOpened should be called when a connection is opened.
func (*Metrics) MetricsMiddleware ¶
MetricsMiddleware wraps an http.Handler with metrics collection.
func (*Metrics) RecordCertCacheHit ¶
RecordCertCacheHit records a certificate cache hit.
func (*Metrics) RecordCertCacheMiss ¶
RecordCertCacheMiss records a certificate cache miss.
func (*Metrics) RecordCertGenerated ¶
RecordCertGenerated records a certificate generation.
func (*Metrics) RecordRequest ¶
func (m *Metrics) RecordRequest(ctx context.Context, method, host string, statusCode int, duration time.Duration, responseSize int64)
RecordRequest records metrics for a completed request.
func (*Metrics) RecordTrafficStoreError ¶
RecordTrafficStoreError records a traffic store error.
func (*Metrics) RecordTrafficStored ¶
RecordTrafficStored records a successful traffic store.
func (*Metrics) RegisterQueueDepthCallback ¶
func (m *Metrics) RegisterQueueDepthCallback(meterProvider metric.MeterProvider, fn func() int64) error
RegisterQueueDepthCallback registers a callback to observe queue depth.
func (*Metrics) RequestEnd ¶
RequestEnd should be called when a request ends.
func (*Metrics) RequestStart ¶
RequestStart should be called when a request starts.
type Provider ¶
type Provider struct {
MeterProvider *sdkmetric.MeterProvider
Metrics *Metrics
// contains filtered or unexported fields
}
Provider holds the OpenTelemetry providers and exporters.
func NewProvider ¶
NewProvider creates a new observability provider.
func (*Provider) PrometheusHandler ¶
PrometheusHandler returns an http.Handler for the /metrics endpoint.