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 {
panic(err)
}
promauto.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "dendrite",
Subsystem: "caching_ristretto",
Name: "ratio",
}, func() float64 {
return float64(cache.Metrics.Ratio())
})
promauto.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "dendrite",
Subsystem: "caching_ristretto",
Name: "cost",
}, func() float64 {
return float64(cache.Metrics.CostAdded() - cache.Metrics.CostEvicted())
})
if enablePrometheus {
promauto.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "dendrite",
Subsystem: "caching_ristretto",
Name: "ratio",
}, func() float64 {
return float64(cache.Metrics.Ratio())
})
promauto.NewGaugeFunc(prometheus.GaugeOpts{
Namespace: "dendrite",
Subsystem: "caching_ristretto",
Name: "cost",
}, func() float64 {
return float64(cache.Metrics.CostAdded() - cache.Metrics.CostEvicted())
})
}
return cache
}