Skip to content

Commit 2b51415

Browse files
committed
feat(metrics): add use labels in cache response
1 parent bf13891 commit 2b51415

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

modules/cache/cache.go

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,39 @@ import (
99
"time"
1010

1111
"code.gitea.io/gitea/modules/setting"
12+
1213
"github.com/prometheus/client_golang/prometheus"
1314
"github.com/prometheus/client_golang/prometheus/promauto"
1415

1516
_ "gitea.com/go-chi/cache/memcache" //nolint:depguard // memcache plugin for cache, it is required for config "ADAPTER=memcache"
1617
)
1718

18-
var defaultCache StringCache
19-
var hitCounter = promauto.NewCounter(prometheus.CounterOpts{
20-
Namespace: "gitea",
21-
Help: "Cache hit count",
22-
Subsystem: "cache",
23-
Name: "hit",
24-
})
25-
var missCounter = promauto.NewCounter(prometheus.CounterOpts{
26-
Namespace: "gitea",
27-
Help: "Cache miss count",
28-
Subsystem: "cache",
29-
Name: "miss",
30-
})
31-
var latencyHistogram = promauto.NewHistogram(
32-
prometheus.HistogramOpts{
33-
Namespace: "gitea",
34-
Help: "Cache latency",
35-
Subsystem: "cache",
36-
Name: "duration",
37-
},
19+
var (
20+
defaultCache StringCache
21+
22+
// TODO: Combine hit and miss into one
23+
hitCounter = promauto.NewCounter(prometheus.CounterOpts{
24+
Namespace: "gitea",
25+
Help: "Cache count",
26+
Subsystem: "cache",
27+
Name: "response",
28+
ConstLabels: prometheus.Labels{"state": "hit"},
29+
})
30+
missCounter = promauto.NewCounter(prometheus.CounterOpts{
31+
Namespace: "gitea",
32+
Help: "Cache count",
33+
Subsystem: "cache",
34+
Name: "response",
35+
ConstLabels: prometheus.Labels{"state": "miss"},
36+
})
37+
latencyHistogram = promauto.NewHistogram(
38+
prometheus.HistogramOpts{
39+
Namespace: "gitea",
40+
Help: "Cache latency",
41+
Subsystem: "cache",
42+
Name: "duration",
43+
},
44+
)
3845
)
3946

4047
// Init start cache service

0 commit comments

Comments
 (0)