Skip to content
Snippets Groups Projects
Commit 1cd9f9a8 authored by ensiouel's avatar ensiouel
Browse files

убрана метрика cache_requests_total

parent d5f1daad
No related branches found
No related tags found
No related merge requests found
......@@ -6,52 +6,48 @@ import (
)
var (
cacheRequestsTotal = promauto.With(prometheus.DefaultRegisterer).NewCounterVec(prometheus.CounterOpts{
Name: "cache_requests_total",
Help: "Количество обращений к кэшу",
}, []string{"cache_id"})
cacheHitsTotal = promauto.With(prometheus.DefaultRegisterer).NewCounterVec(prometheus.CounterOpts{
Name: "cache_hits_total",
Help: "Количество попаданий в кэш",
Help: "Количество попаданий в кэш.",
}, []string{"cache_id"})
cacheMissesTotal = promauto.With(prometheus.DefaultRegisterer).NewCounterVec(prometheus.CounterOpts{
Name: "cache_misses_total",
Help: "Количество пропусков в кэш",
Help: "Количество пропусков в кэш.",
}, []string{"cache_id"})
)
var _ Cache = &MetricsCache{}
var _ Cache = &metricsCache{}
type MetricsCache struct {
cacheID string
type metricsCache struct {
cache Cache
cacheID string
}
func WrapMetrics(cacheID string, cache Cache) *MetricsCache {
return &MetricsCache{
// WithMetrics возвращает обертку над кэшем, которая используется для отслеживания количества хитов и промахов в кэше.
// Помимо этого, в функцию WithMetrics передается параметр cacheID, который используется в метке метрик для идентификации конкретного кэша.
//
// Метрики записываются в prometheus.DefaultRegisterer
func WithMetrics(cache Cache, cacheID string) Cache {
return &metricsCache{
cacheID: cacheID,
cache: cache,
}
}
func (c *MetricsCache) Set(key, value any) error {
func (c *metricsCache) Set(key, value any) error {
return c.cache.Set(key, value)
}
func (c *MetricsCache) Get(key any) (any, error) {
cacheRequestsTotal.WithLabelValues(c.cacheID).Inc()
func (c *metricsCache) Get(key any) (any, error) {
value, err := c.cache.Get(key)
if err != nil {
cacheMissesTotal.WithLabelValues(c.cacheID).Inc()
return nil, err
}
cacheHitsTotal.WithLabelValues(c.cacheID).Inc()
return value, nil
}
func (c *MetricsCache) Remove(key any) error {
func (c *metricsCache) Remove(key any) error {
return c.cache.Remove(key)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment