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
- func InitializeLogging(level string, format string) *slog.Logger
- type AppMetrics
- type CacheCollector
- type MockAppMetrics
- func (m *MockAppMetrics) GetCacheEntryMissing() int64
- func (m *MockAppMetrics) GetCacheEntryMissingByRepo(repository string) int64
- func (m *MockAppMetrics) GetCacheEvictions() int64
- func (m *MockAppMetrics) GetCacheEvictionsByReason(reason string) int64
- func (m *MockAppMetrics) GetCacheHits() int64
- func (m *MockAppMetrics) GetCacheHitsByRepo(repository string) int64
- func (m *MockAppMetrics) GetCacheMisses() int64
- func (m *MockAppMetrics) GetCacheMissesByRepo(repository string) int64
- func (m *MockAppMetrics) GetCoalescedRequests() int64
- func (m *MockAppMetrics) GetCoalescedRequestsByRepo(repository string) int64
- func (m *MockAppMetrics) GetErrors(errorType string) int64
- func (m *MockAppMetrics) GetFetchDurations(result string) []float64
- func (m *MockAppMetrics) GetNonCacheableRequests() int64
- func (m *MockAppMetrics) IncCacheEntryMissing(repository string)
- func (m *MockAppMetrics) IncCacheEvictions(reason string)
- func (m *MockAppMetrics) IncCacheHits(repository string)
- func (m *MockAppMetrics) IncCacheMisses(repository string)
- func (m *MockAppMetrics) IncCoalescedRequests(repository string)
- func (m *MockAppMetrics) IncErrors(errorType string)
- func (m *MockAppMetrics) IncNonCacheableRequests(reason string)
- func (m *MockAppMetrics) ObserveFetchDuration(result string, seconds float64)
- func (m *MockAppMetrics) Reset()
- type NullAppMetrics
- func (m *NullAppMetrics) IncCacheEntryMissing(repository string)
- func (m *NullAppMetrics) IncCacheEvictions(reason string)
- func (m *NullAppMetrics) IncCacheHits(repository string)
- func (m *NullAppMetrics) IncCacheMisses(repository string)
- func (m *NullAppMetrics) IncCoalescedRequests(repository string)
- func (m *NullAppMetrics) IncErrors(errorType string)
- func (m *NullAppMetrics) IncNonCacheableRequests(reason string)
- func (m *NullAppMetrics) ObserveFetchDuration(result string, seconds float64)
- type PrometheusAppMetrics
- func (m *PrometheusAppMetrics) IncCacheEntryMissing(repository string)
- func (m *PrometheusAppMetrics) IncCacheEvictions(reason string)
- func (m *PrometheusAppMetrics) IncCacheHits(repository string)
- func (m *PrometheusAppMetrics) IncCacheMisses(repository string)
- func (m *PrometheusAppMetrics) IncCoalescedRequests(repository string)
- func (m *PrometheusAppMetrics) IncErrors(errorType string)
- func (m *PrometheusAppMetrics) IncNonCacheableRequests(reason string)
- func (m *PrometheusAppMetrics) ObserveFetchDuration(result string, seconds float64)
- type PrometheusManager
Constants ¶
const ( // FetchResultHit is a request served directly from the cache. FetchResultHit = "hit" // FetchResultMiss is a request that fetched from upstream and cached the result. FetchResultMiss = "miss" // FetchResultCoalesce is a request that coalesced onto an in-flight upstream fetch. FetchResultCoalesce = "coalesce" // FetchResultBypass is a cacheable-path request that was proxied without caching. FetchResultBypass = "bypass" )
Fetch result label values for ObserveFetchDuration.
const ( // EvictionReasonTTL is a sliding-TTL expiration. EvictionReasonTTL = "ttl" // EvictionReasonSize is an LFU-driven eviction under size/cost pressure. EvictionReasonSize = "size" // EvictionReasonReject is an admission-policy rejection on Set. EvictionReasonReject = "reject" )
Eviction reason label values for IncCacheEvictions.
const ( // ErrorTypeUpstream is a failure talking to the upstream Git server. ErrorTypeUpstream = "upstream" // ErrorTypeCache is a failure reading from or writing to the cache. ErrorTypeCache = "cache" // ErrorTypeInternal is a failure parsing, decompressing, or serializing a request. ErrorTypeInternal = "internal" // ErrorTypeUpstreamInBand is an upstream response that returned HTTP 200 but // carried an in-band git error or a truncated packfile, so it was served to // the client but not cached. ErrorTypeUpstreamInBand = "upstream_in_band" )
Error type label values for IncErrors.
const RepositoryLabelDisabled = "_disabled"
RepositoryLabelDisabled is the sentinel repository label value used when the allowlist is disabled, so that per-repository cache metrics stay bounded in cardinality (all traffic collapses into one series) while totals remain visible.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AppMetrics ¶
type AppMetrics interface {
// IncCacheHits increments the cache hits counter for the given repository.
IncCacheHits(repository string)
// IncCacheMisses increments the cache misses counter for the given repository.
IncCacheMisses(repository string)
// IncCoalescedRequests increments the counter of requests served by coalescing
// onto an in-flight upstream fetch, for the given repository.
IncCoalescedRequests(repository string)
// IncCacheEntryMissing increments the counter of serve-time cache misses for
// the given repository: a fetch that stored or coalesced successfully but
// found its entry gone when it went to serve it, and had to re-fetch.
IncCacheEntryMissing(repository string)
// IncNonCacheableRequests increments the non-cacheable requests counter for the given reason.
IncNonCacheableRequests(reason string)
// IncCacheEvictions increments the cache-evictions counter for the given reason
// (ttl, size, reject). Reason distinguishes sliding-TTL expiration from
// size-driven LFU eviction from admission-policy rejection.
IncCacheEvictions(reason string)
// ObserveFetchDuration records the end-to-end duration of a cacheable fetch,
// labelled by result (hit, miss, coalesce, bypass).
ObserveFetchDuration(result string, seconds float64)
// IncErrors increments the error counter for the given type (upstream, cache, internal).
IncErrors(errorType 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 CacheCollector ¶ added in v1.25.0
type CacheCollector struct {
// contains filtered or unexported fields
}
CacheCollector is a prometheus.Collector that reports cache storage gauges by reading on-disk state at scrape time. Reading on scrape keeps them accurate without in-memory counters that would drift as entries are evicted.
func NewCacheCollector ¶ added in v1.25.0
func NewCacheCollector(manager *cache.Manager) *CacheCollector
NewCacheCollector creates a CacheCollector for the given cache manager.
func (*CacheCollector) Collect ¶ added in v1.25.0
func (c *CacheCollector) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector.
func (*CacheCollector) Describe ¶ added in v1.25.0
func (c *CacheCollector) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector.
type MockAppMetrics ¶
type MockAppMetrics struct {
// contains filtered or unexported fields
}
MockAppMetrics is a thread-safe mock implementation of the AppMetrics interface for testing.
func NewMockAppMetrics ¶
func NewMockAppMetrics() *MockAppMetrics
NewMockAppMetrics creates a new MockAppMetrics instance.
func (*MockAppMetrics) GetCacheEntryMissing ¶ added in v1.28.2
func (m *MockAppMetrics) GetCacheEntryMissing() int64
GetCacheEntryMissing returns the total serve-time cache-miss count.
func (*MockAppMetrics) GetCacheEntryMissingByRepo ¶ added in v1.28.2
func (m *MockAppMetrics) GetCacheEntryMissingByRepo(repository string) int64
GetCacheEntryMissingByRepo returns the serve-time cache-miss count for the given repository.
func (*MockAppMetrics) GetCacheEvictions ¶ added in v1.38.0
func (m *MockAppMetrics) GetCacheEvictions() int64
GetCacheEvictions returns the total cache-evictions count.
func (*MockAppMetrics) GetCacheEvictionsByReason ¶ added in v1.38.0
func (m *MockAppMetrics) GetCacheEvictionsByReason(reason string) int64
GetCacheEvictionsByReason returns the cache-evictions count for the given reason.
func (*MockAppMetrics) GetCacheHits ¶
func (m *MockAppMetrics) GetCacheHits() int64
GetCacheHits returns the total cache hits count.
func (*MockAppMetrics) GetCacheHitsByRepo ¶ added in v1.25.0
func (m *MockAppMetrics) GetCacheHitsByRepo(repository string) int64
GetCacheHitsByRepo returns the cache hits count for the given repository.
func (*MockAppMetrics) GetCacheMisses ¶
func (m *MockAppMetrics) GetCacheMisses() int64
GetCacheMisses returns the total cache misses count.
func (*MockAppMetrics) GetCacheMissesByRepo ¶ added in v1.25.0
func (m *MockAppMetrics) GetCacheMissesByRepo(repository string) int64
GetCacheMissesByRepo returns the cache misses count for the given repository.
func (*MockAppMetrics) GetCoalescedRequests ¶ added in v1.25.0
func (m *MockAppMetrics) GetCoalescedRequests() int64
GetCoalescedRequests returns the total coalesced requests count.
func (*MockAppMetrics) GetCoalescedRequestsByRepo ¶ added in v1.25.0
func (m *MockAppMetrics) GetCoalescedRequestsByRepo(repository string) int64
GetCoalescedRequestsByRepo returns the coalesced requests count for the given repository.
func (*MockAppMetrics) GetErrors ¶ added in v1.25.0
func (m *MockAppMetrics) GetErrors(errorType string) int64
GetErrors returns the error count for the given type.
func (*MockAppMetrics) GetFetchDurations ¶ added in v1.25.0
func (m *MockAppMetrics) GetFetchDurations(result string) []float64
GetFetchDurations returns the recorded fetch duration observations for the given result.
func (*MockAppMetrics) GetNonCacheableRequests ¶
func (m *MockAppMetrics) GetNonCacheableRequests() int64
GetNonCacheableRequests returns the current non-cacheable requests count.
func (*MockAppMetrics) IncCacheEntryMissing ¶ added in v1.28.2
func (m *MockAppMetrics) IncCacheEntryMissing(repository string)
IncCacheEntryMissing increments the serve-time cache-miss counter for the given repository.
func (*MockAppMetrics) IncCacheEvictions ¶ added in v1.38.0
func (m *MockAppMetrics) IncCacheEvictions(reason string)
IncCacheEvictions increments the cache-evictions counter for the given reason.
func (*MockAppMetrics) IncCacheHits ¶
func (m *MockAppMetrics) IncCacheHits(repository string)
IncCacheHits increments the cache hits counter for the given repository.
func (*MockAppMetrics) IncCacheMisses ¶
func (m *MockAppMetrics) IncCacheMisses(repository string)
IncCacheMisses increments the cache misses counter for the given repository.
func (*MockAppMetrics) IncCoalescedRequests ¶ added in v1.25.0
func (m *MockAppMetrics) IncCoalescedRequests(repository string)
IncCoalescedRequests increments the coalesced requests counter for the given repository.
func (*MockAppMetrics) IncErrors ¶ added in v1.25.0
func (m *MockAppMetrics) IncErrors(errorType string)
IncErrors increments the error counter for the given type.
func (*MockAppMetrics) IncNonCacheableRequests ¶
func (m *MockAppMetrics) IncNonCacheableRequests(reason string)
IncNonCacheableRequests increments the non-cacheable requests counter.
func (*MockAppMetrics) ObserveFetchDuration ¶ added in v1.25.0
func (m *MockAppMetrics) ObserveFetchDuration(result string, seconds float64)
ObserveFetchDuration records a fetch duration observation by result.
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) IncCacheEntryMissing ¶ added in v1.28.2
func (m *NullAppMetrics) IncCacheEntryMissing(repository string)
IncCacheEntryMissing is a no-op.
func (*NullAppMetrics) IncCacheEvictions ¶ added in v1.38.0
func (m *NullAppMetrics) IncCacheEvictions(reason string)
IncCacheEvictions is a no-op.
func (*NullAppMetrics) IncCacheHits ¶
func (m *NullAppMetrics) IncCacheHits(repository string)
IncCacheHits is a no-op.
func (*NullAppMetrics) IncCacheMisses ¶
func (m *NullAppMetrics) IncCacheMisses(repository string)
IncCacheMisses is a no-op.
func (*NullAppMetrics) IncCoalescedRequests ¶ added in v1.25.0
func (m *NullAppMetrics) IncCoalescedRequests(repository string)
IncCoalescedRequests is a no-op.
func (*NullAppMetrics) IncErrors ¶ added in v1.25.0
func (m *NullAppMetrics) IncErrors(errorType string)
IncErrors is a no-op.
func (*NullAppMetrics) IncNonCacheableRequests ¶
func (m *NullAppMetrics) IncNonCacheableRequests(reason string)
IncNonCacheableRequests is a no-op.
func (*NullAppMetrics) ObserveFetchDuration ¶ added in v1.25.0
func (m *NullAppMetrics) ObserveFetchDuration(result string, seconds float64)
ObserveFetchDuration 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) IncCacheEntryMissing ¶ added in v1.28.2
func (m *PrometheusAppMetrics) IncCacheEntryMissing(repository string)
IncCacheEntryMissing increments the serve-time cache-miss counter for the given repository.
func (*PrometheusAppMetrics) IncCacheEvictions ¶ added in v1.38.0
func (m *PrometheusAppMetrics) IncCacheEvictions(reason string)
IncCacheEvictions increments the cache-evictions counter for the given reason.
func (*PrometheusAppMetrics) IncCacheHits ¶
func (m *PrometheusAppMetrics) IncCacheHits(repository string)
IncCacheHits increments the cache hits counter for the given repository.
func (*PrometheusAppMetrics) IncCacheMisses ¶
func (m *PrometheusAppMetrics) IncCacheMisses(repository string)
IncCacheMisses increments the cache misses counter for the given repository.
func (*PrometheusAppMetrics) IncCoalescedRequests ¶ added in v1.25.0
func (m *PrometheusAppMetrics) IncCoalescedRequests(repository string)
IncCoalescedRequests increments the coalesced requests counter for the given repository.
func (*PrometheusAppMetrics) IncErrors ¶ added in v1.25.0
func (m *PrometheusAppMetrics) IncErrors(errorType string)
IncErrors increments the error counter for the given type.
func (*PrometheusAppMetrics) IncNonCacheableRequests ¶
func (m *PrometheusAppMetrics) IncNonCacheableRequests(reason string)
IncNonCacheableRequests increments the non-cacheable requests counter for the given reason.
func (*PrometheusAppMetrics) ObserveFetchDuration ¶ added in v1.25.0
func (m *PrometheusAppMetrics) ObserveFetchDuration(result string, seconds float64)
ObserveFetchDuration records the end-to-end duration of a cacheable fetch by result.
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. It registers the Go runtime and process collectors so the binary exposes baseline goroutine, memory, GC, file-descriptor, and CPU metrics for itself.
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.