1
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-02-02 15:09:33 -05:00

feat(metrics): add use labels in cache response

This commit is contained in:
TheFox0x7 2025-01-16 21:33:22 +01:00
parent 3e06c39d2f
commit c666f4d9cc

View File

@ -9,26 +9,32 @@ import (
"time" "time"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto" "github.com/prometheus/client_golang/prometheus/promauto"
_ "gitea.com/go-chi/cache/memcache" //nolint:depguard // memcache plugin for cache, it is required for config "ADAPTER=memcache" _ "gitea.com/go-chi/cache/memcache" //nolint:depguard // memcache plugin for cache, it is required for config "ADAPTER=memcache"
) )
var defaultCache StringCache var (
var hitCounter = promauto.NewCounter(prometheus.CounterOpts{ defaultCache StringCache
// TODO: Combine hit and miss into one
hitCounter = promauto.NewCounter(prometheus.CounterOpts{
Namespace: "gitea", Namespace: "gitea",
Help: "Cache hit count", Help: "Cache count",
Subsystem: "cache", Subsystem: "cache",
Name: "hit", Name: "response",
ConstLabels: prometheus.Labels{"state": "hit"},
}) })
var missCounter = promauto.NewCounter(prometheus.CounterOpts{ missCounter = promauto.NewCounter(prometheus.CounterOpts{
Namespace: "gitea", Namespace: "gitea",
Help: "Cache miss count", Help: "Cache count",
Subsystem: "cache", Subsystem: "cache",
Name: "miss", Name: "response",
ConstLabels: prometheus.Labels{"state": "miss"},
}) })
var latencyHistogram = promauto.NewHistogram( latencyHistogram = promauto.NewHistogram(
prometheus.HistogramOpts{ prometheus.HistogramOpts{
Namespace: "gitea", Namespace: "gitea",
Help: "Cache latency", Help: "Cache latency",
@ -36,6 +42,7 @@ var latencyHistogram = promauto.NewHistogram(
Name: "duration", Name: "duration",
}, },
) )
)
// Init start cache service // Init start cache service
func Init() error { func Init() error {