Only register prometheus metrics if requested

This commit is contained in:
Neil Alexander 2022-07-07 14:39:51 +01:00
parent 56b2672f92
commit 1437ac42e3
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -28,20 +28,22 @@ func MustCreateCache(maxCost config.DataUnit, enablePrometheus bool) *ristretto.
if err != nil { if err != nil {
panic(err) panic(err)
} }
promauto.NewGaugeFunc(prometheus.GaugeOpts{ if enablePrometheus {
Namespace: "dendrite", promauto.NewGaugeFunc(prometheus.GaugeOpts{
Subsystem: "caching_ristretto", Namespace: "dendrite",
Name: "ratio", Subsystem: "caching_ristretto",
}, func() float64 { Name: "ratio",
return float64(cache.Metrics.Ratio()) }, func() float64 {
}) return float64(cache.Metrics.Ratio())
promauto.NewGaugeFunc(prometheus.GaugeOpts{ })
Namespace: "dendrite", promauto.NewGaugeFunc(prometheus.GaugeOpts{
Subsystem: "caching_ristretto", Namespace: "dendrite",
Name: "cost", Subsystem: "caching_ristretto",
}, func() float64 { Name: "cost",
return float64(cache.Metrics.CostAdded() - cache.Metrics.CostEvicted()) }, func() float64 {
}) return float64(cache.Metrics.CostAdded() - cache.Metrics.CostEvicted())
})
}
return cache return cache
} }