observability

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: Apache-2.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// RequestCounter counts all HTTP requests
	RequestCounter = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "cdn_http_requests_total",
			Help: "Total number of HTTP requests",
		},
		[]string{"method", "endpoint", "status"},
	)

	// RequestDuration measures request duration
	RequestDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "cdn_http_request_duration_seconds",
			Help:    "HTTP request duration in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"method", "endpoint"},
	)

	// ImageProcessingDuration measures image processing duration
	ImageProcessingDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "cdn_image_processing_duration_seconds",
			Help:    "Image processing duration in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"operation"},
	)

	// StorageOperationDuration measures storage operation duration
	StorageOperationDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "cdn_storage_operation_duration_seconds",
			Help:    "Storage operation duration in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"operation", "provider"},
	)

	// Health Check Metrics
	ServiceHealth = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "service_health_status",
			Help: "Current health status of services (1 for healthy, 0 for unhealthy)",
		},
		[]string{"service"},
	)

	ServiceHealthCheckDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "service_health_check_duration_seconds",
			Help:    "Duration of health checks in seconds",
			Buckets: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5},
		},
		[]string{"service"},
	)

	LastHealthCheckTimestamp = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "service_last_health_check_timestamp",
			Help: "Timestamp of the last health check",
		},
		[]string{"service"},
	)

	// Worker Pool Metrics
	WorkerPoolQueueSize = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "worker_pool_queue_size",
			Help: "Current number of jobs in the worker pool queue",
		},
	)

	WorkerPoolActiveWorkers = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "worker_pool_active_workers",
			Help: "Current number of active workers in the pool",
		},
	)

	WorkerJobProcessingDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "worker_job_processing_duration_seconds",
			Help:    "Duration of job processing in seconds",
			Buckets: []float64{.001, .005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5},
		},
		[]string{"status"},
	)

	WorkerJobRetries = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "worker_job_retries_total",
			Help: "Total number of job retries",
		},
		[]string{"job_type"},
	)

	// Batch Processor Metrics
	BatchProcessorQueueSize = promauto.NewGauge(
		prometheus.GaugeOpts{
			Name: "batch_processor_queue_size",
			Help: "Current number of items in the batch processor queue",
		},
	)

	BatchProcessingDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "batch_processing_duration_seconds",
			Help:    "Duration of batch processing in seconds",
			Buckets: []float64{.01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10},
		},
		[]string{"status"},
	)

	BatchItemsProcessed = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "batch_items_processed_total",
			Help: "Total number of items processed by the batch processor",
		},
		[]string{"status"},
	)

	BatchRetries = promauto.NewCounter(
		prometheus.CounterOpts{
			Name: "batch_retries_total",
			Help: "Total number of batch retries",
		},
	)

	// Cache Metrics
	CacheOperations = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "cache_operations_total",
			Help: "The total number of cache operations",
		},
		[]string{"operation", "status"},
	)

	CacheOperationDuration = promauto.NewHistogramVec(
		prometheus.HistogramOpts{
			Name:    "cache_operation_duration_seconds",
			Help:    "Duration of cache operations in seconds",
			Buckets: prometheus.DefBuckets,
		},
		[]string{"operation", "status"},
	)

	CacheSize = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "cache_size_bytes",
			Help: "Current size of cached data in bytes",
		},
		[]string{"type"},
	)

	CacheHitRatio = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "cache_hit_ratio",
			Help: "Cache hit ratio",
		},
		[]string{"operation"},
	)

	// Circuit Breaker metrics
	CircuitBreakerState = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "circuit_breaker_state",
			Help: "Current state of circuit breaker (0: Closed, 1: Open, 2: Half-Open)",
		},
		[]string{"name"},
	)

	CircuitBreakerFailures = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "circuit_breaker_failures",
			Help: "Number of consecutive failures in circuit breaker",
		},
		[]string{"name"},
	)

	CircuitBreakerSuccesses = promauto.NewGaugeVec(
		prometheus.GaugeOpts{
			Name: "circuit_breaker_successes",
			Help: "Number of consecutive successes in circuit breaker",
		},
		[]string{"name"},
	)

	CircuitBreakerRequests = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Name: "circuit_breaker_requests_total",
			Help: "Total number of requests handled by circuit breaker",
		},
		[]string{"name", "result"},
	)
)

Functions

func InitLogger

func InitLogger()

InitLogger configures zerolog

func InitTracer

func InitTracer(serviceName, jaegerEndpoint string) (func(), error)

InitTracer configures the Jaeger tracer

func Logger

func Logger() zerolog.Logger

Logger returns the configured logger

func MetricsHandler

func MetricsHandler() http.Handler

MetricsHandler exposes the Prometheus metrics in the standard exposition format. It delegates to promhttp with ContinueOnError so that a single inconsistent metric family does not turn the whole endpoint into a 500 (the previous behaviour); valid metrics are still served.

The exposition is buffered and sent with a Content-Length, as fiber's adaptor did; written straight through it would go out chunked.

func PrometheusMiddleware

func PrometheusMiddleware(endpoint func(*http.Request) string) func(http.Handler) http.Handler

PrometheusMiddleware counts requests and their duration.

The endpoint label is the matched ROUTE PATTERN (e.g. "/:bucket/*"), never the raw path: on a CDN the raw path is effectively unbounded, one series per object URL. endpoint returns the pattern after the request was routed; status comes from w, which must report the status it wrote.

func Tracer

func Tracer(name string) trace.Tracer

Tracer returns a new tracer instance

Types

This section is empty.

Jump to

Keyboard shortcuts

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