observability

package
v0.0.0-...-b198e9d Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ComponentHealth

type ComponentHealth struct {
	Status  HealthStatus `json:"status"`
	Message string       `json:"message,omitempty"`
	Latency string       `json:"latency,omitempty"`
}

ComponentHealth represents the health of a single component.

type Health

type Health struct {
	// contains filtered or unexported fields
}

Health manages health check state and handlers.

func NewHealth

func NewHealth(version string) *Health

NewHealth creates a new health checker.

func (*Health) FullHealthHandler

func (h *Health) FullHealthHandler() http.HandlerFunc

FullHealthHandler returns a detailed health check of all components.

func (*Health) IsReady

func (h *Health) IsReady() bool

IsReady returns the current readiness state.

func (*Health) LivenessHandler

func (h *Health) LivenessHandler() http.HandlerFunc

LivenessHandler returns an HTTP handler for liveness checks. Liveness indicates the process is running and not deadlocked.

func (*Health) ReadinessHandler

func (h *Health) ReadinessHandler() http.HandlerFunc

ReadinessHandler returns an HTTP handler for readiness checks. Readiness indicates the service can accept traffic.

func (*Health) RegisterChecker

func (h *Health) RegisterChecker(name string, checker HealthChecker)

RegisterChecker adds a health check for a named component.

func (*Health) SetReady

func (h *Health) SetReady(ready bool)

SetReady sets the readiness state.

type HealthChecker

type HealthChecker func(ctx context.Context) ComponentHealth

HealthChecker defines a function that checks component health.

func DatabaseChecker

func DatabaseChecker(pingFunc func(ctx context.Context) error) HealthChecker

DatabaseChecker creates a health checker for database connectivity.

func PolicyEngineChecker

func PolicyEngineChecker(isReady func() bool) HealthChecker

PolicyEngineChecker creates a health checker for the policy engine.

func UpstreamChecker

func UpstreamChecker(isConnected func() bool) HealthChecker

UpstreamChecker creates a health checker for upstream connectivity.

type HealthResponse

type HealthResponse struct {
	Status     HealthStatus               `json:"status"`
	Timestamp  time.Time                  `json:"timestamp"`
	Version    string                     `json:"version,omitempty"`
	Components map[string]ComponentHealth `json:"components,omitempty"`
}

HealthResponse is returned by health check endpoints.

type HealthStatus

type HealthStatus string

HealthStatus represents the overall health status.

const (
	HealthStatusHealthy   HealthStatus = "healthy"
	HealthStatusDegraded  HealthStatus = "degraded"
	HealthStatusUnhealthy HealthStatus = "unhealthy"
)

type Metrics

type Metrics struct {
	// Request metrics
	RequestsTotal    *prometheus.CounterVec
	RequestDuration  *prometheus.HistogramVec
	RequestsInFlight prometheus.Gauge

	// Session metrics
	ActiveSessions  prometheus.Gauge
	SessionsTotal   *prometheus.CounterVec
	SessionDuration prometheus.Histogram

	// Policy metrics
	PolicyDecisions   *prometheus.CounterVec
	PolicyEvaluation  prometheus.Histogram
	PolicyCacheHits   prometheus.Counter
	PolicyCacheMisses prometheus.Counter

	// Upstream metrics
	UpstreamRequests  *prometheus.CounterVec
	UpstreamDuration  prometheus.Histogram
	UpstreamConnected prometheus.Gauge

	// Audit metrics
	AuditRecordsWritten prometheus.Counter
	AuditRecordsDropped prometheus.Counter
	AuditBufferSize     prometheus.Gauge
	AuditFlushes        prometheus.Counter
}

Metrics holds all Prometheus metrics for the proxy.

func NewMetrics

func NewMetrics(namespace string) *Metrics

NewMetrics creates and registers all Prometheus metrics.

func (*Metrics) IncrementAuditDropped

func (m *Metrics) IncrementAuditDropped(count int)

IncrementAuditDropped increments the audit records dropped counter.

func (*Metrics) IncrementAuditFlushes

func (m *Metrics) IncrementAuditFlushes()

IncrementAuditFlushes increments the audit flushes counter.

func (*Metrics) IncrementAuditWritten

func (m *Metrics) IncrementAuditWritten(count int)

IncrementAuditWritten increments the audit records written counter.

func (*Metrics) RecordPolicyDecision

func (m *Metrics) RecordPolicyDecision(allowed bool, rule, mode string, durationSeconds float64)

RecordPolicyDecision records a policy evaluation result.

func (*Metrics) RecordRequest

func (m *Metrics) RecordRequest(method, tool string, allowed bool, durationSeconds float64)

RecordRequest records metrics for a processed request.

func (*Metrics) RecordSession

func (m *Metrics) RecordSession(transport string, durationSeconds float64)

RecordSession records session metrics.

func (*Metrics) RecordUpstreamRequest

func (m *Metrics) RecordUpstreamRequest(status string, durationSeconds float64)

RecordUpstreamRequest records an upstream request result.

func (*Metrics) UpdateAuditStats

func (m *Metrics) UpdateAuditStats(bufferSize int, written, dropped, flushes int64)

UpdateAuditStats updates audit-related gauges.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server serves metrics and health check endpoints.

func NewServer

func NewServer(cfg ServerConfig, metrics *Metrics, health *Health) *Server

NewServer creates a new observability server.

func (*Server) Start

func (s *Server) Start(ctx context.Context) error

Start starts the observability servers.

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully stops the observability servers.

type ServerConfig

type ServerConfig struct {
	// Metrics configuration
	MetricsEnabled bool
	MetricsAddress string
	MetricsPort    int
	MetricsPath    string

	// Health configuration
	HealthEnabled bool
	HealthAddress string
	HealthPort    int
	LivenessPath  string
	ReadinessPath string
}

ServerConfig holds configuration for the observability server.

Jump to

Keyboard shortcuts

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