observability

package
v1.23.2 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package observability provides logging and metrics instrumentation using GitLab LabKit.

This package initializes structured logging and exposes Prometheus metrics for monitoring cache hits, misses, upstream requests, and request coalescing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitializeLogging

func InitializeLogging(level string, format string) *slog.Logger

InitializeLogging sets up LabKit v2 structured logging and returns the configured logger. It also sets the logger as the default slog logger so package-level slog calls work.

Types

type AppMetrics

type AppMetrics interface {
	// IncCacheHits increments the cache hits counter.
	IncCacheHits()

	// IncCacheMisses increments the cache misses counter.
	IncCacheMisses()

	// IncNonCacheableRequests increments the non-cacheable requests counter for the given reason.
	IncNonCacheableRequests(reason string)
}

AppMetrics defines the interface for recording Packhorse application metrics. This abstraction allows for different implementations (e.g., Prometheus, mock for testing, null object).

type MockAppMetrics

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

MockAppMetrics is a thread-safe mock implementation of the AppMetrics interface for testing. It uses atomic operations to safely increment counters from multiple goroutines.

func NewMockAppMetrics

func NewMockAppMetrics() *MockAppMetrics

NewMockAppMetrics creates a new MockAppMetrics instance.

func (*MockAppMetrics) GetCacheHits

func (m *MockAppMetrics) GetCacheHits() int64

GetCacheHits returns the current cache hits count.

func (*MockAppMetrics) GetCacheMisses

func (m *MockAppMetrics) GetCacheMisses() int64

GetCacheMisses returns the current cache misses count.

func (*MockAppMetrics) GetNonCacheableRequests

func (m *MockAppMetrics) GetNonCacheableRequests() int64

GetNonCacheableRequests returns the current non-cacheable requests count.

func (*MockAppMetrics) IncCacheHits

func (m *MockAppMetrics) IncCacheHits()

IncCacheHits increments the cache hits counter atomically.

func (*MockAppMetrics) IncCacheMisses

func (m *MockAppMetrics) IncCacheMisses()

IncCacheMisses increments the cache misses counter atomically.

func (*MockAppMetrics) IncNonCacheableRequests

func (m *MockAppMetrics) IncNonCacheableRequests(reason string)

IncNonCacheableRequests increments the non-cacheable requests counter atomically.

func (*MockAppMetrics) Reset

func (m *MockAppMetrics) Reset()

Reset resets all counters to zero.

type NullAppMetrics

type NullAppMetrics struct{}

NullAppMetrics is a no-op implementation of the AppMetrics interface. It's used when metrics are not configured, eliminating the need for nil checks.

func NewNullAppMetrics

func NewNullAppMetrics() *NullAppMetrics

NewNullAppMetrics creates a new NullAppMetrics instance.

func (*NullAppMetrics) IncCacheHits

func (m *NullAppMetrics) IncCacheHits()

IncCacheHits is a no-op.

func (*NullAppMetrics) IncCacheMisses

func (m *NullAppMetrics) IncCacheMisses()

IncCacheMisses is a no-op.

func (*NullAppMetrics) IncNonCacheableRequests

func (m *NullAppMetrics) IncNonCacheableRequests(reason string)

IncNonCacheableRequests is a no-op.

type PrometheusAppMetrics

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

PrometheusAppMetrics holds all Prometheus metrics for Packhorse. It registers metrics with a PrometheusManager's registry.

func NewPrometheusAppMetrics

func NewPrometheusAppMetrics(manager *PrometheusManager) *PrometheusAppMetrics

NewPrometheusAppMetrics creates and registers all Prometheus metrics with a PrometheusManager.

func (*PrometheusAppMetrics) IncCacheHits

func (m *PrometheusAppMetrics) IncCacheHits()

IncCacheHits increments the cache hits counter.

func (*PrometheusAppMetrics) IncCacheMisses

func (m *PrometheusAppMetrics) IncCacheMisses()

IncCacheMisses increments the cache misses counter.

func (*PrometheusAppMetrics) IncNonCacheableRequests

func (m *PrometheusAppMetrics) IncNonCacheableRequests(reason string)

IncNonCacheableRequests increments the non-cacheable requests counter for the given reason.

type PrometheusManager

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

PrometheusManager manages the Prometheus registry and metrics HTTP server. This is separate from metrics recording, allowing the server to always expose a /metrics endpoint regardless of which AppMetrics implementation is used.

func NewPrometheusManager

func NewPrometheusManager() *PrometheusManager

NewPrometheusManager creates a new PrometheusManager with a new registry.

func NewPrometheusManagerWithRegistry

func NewPrometheusManagerWithRegistry(registry *prometheus.Registry) *PrometheusManager

NewPrometheusManagerWithRegistry creates a new PrometheusManager with a custom registry.

func (*PrometheusManager) Handler

func (m *PrometheusManager) Handler() http.Handler

Handler returns an HTTP handler for the /metrics endpoint.

func (*PrometheusManager) Registry

func (m *PrometheusManager) Registry() *prometheus.Registry

Registry returns the Prometheus registry.

func (*PrometheusManager) StartServer

func (m *PrometheusManager) StartServer(addr string)

StartServer starts the Prometheus metrics HTTP server. This is a blocking call and should typically be run in a goroutine.

Jump to

Keyboard shortcuts

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