Files
pixa/internal/imgcache/counters.go
T
sneak c3a6799763
check / check (push) Canceled after 0s
Count hits, misses, fetches and transforms as Prometheus counters (closes #311)
The five counts the cache_stats table held are now Prometheus counters in
memory, in internal/imgcache/counters.go, on the default registry that
/metrics serves. The Increment methods add to them, so counting makes no
database call.

cache_stats, Cache.Stats, Service.Stats, CacheStats and the pending counts
are gone, with their tests. The background goroutine now writes only access
times, and its names say so: StartPendingAccessTimeWrites,
StopPendingAccessTimeWrites and pendingaccesstimes.go.

The counters count for the whole process, so the tests that check how much
they rose do not call t.Parallel. Two stop tests whose write under way was a
hit count now use an access time.

Model: opus-5-5
2026-10-26 08:50:41 +00:00

36 lines
1.3 KiB
Go

package imgcache
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
// The counts of what the image cache does, kept in memory as Prometheus
// counters. They are registered on Prometheus' default registry, which
// /metrics serves. Adding to one waits for nothing and makes no database
// call. Each counts for the whole process since it started.
//
//nolint:gochecknoglobals // Prometheus registers each counter once per process
var (
cacheHits = promauto.NewCounter(prometheus.CounterOpts{
Name: "pixa_cache_hits_total",
Help: "Image requests served from the cache.",
})
cacheMisses = promauto.NewCounter(prometheus.CounterOpts{
Name: "pixa_cache_misses_total",
Help: "Image requests not served from the cache.",
})
upstreamFetches = promauto.NewCounter(prometheus.CounterOpts{
Name: "pixa_upstream_fetches_total",
Help: "Fetches of a source image from upstream that read any bytes.",
})
upstreamFetchBytes = promauto.NewCounter(prometheus.CounterOpts{
Name: "pixa_upstream_fetch_bytes_total",
Help: "Bytes read from upstream by fetches of source images.",
})
transforms = promauto.NewCounter(prometheus.CounterOpts{
Name: "pixa_transforms_total",
Help: "Images the image processor transformed.",
})
)