NewRedisCache creates a new RedisCache
(name string, redisClient *RedisClient, reg prometheus.Registerer, logger log.Logger)
| 24 | |
| 25 | // NewRedisCache creates a new RedisCache |
| 26 | func NewRedisCache(name string, redisClient *RedisClient, reg prometheus.Registerer, logger log.Logger) *RedisCache { |
| 27 | cache := &RedisCache{ |
| 28 | name: name, |
| 29 | redis: redisClient, |
| 30 | logger: logger, |
| 31 | requestDuration: instr.NewHistogramCollector( |
| 32 | promauto.With(reg).NewHistogramVec(prometheus.HistogramOpts{ |
| 33 | Namespace: "cortex", |
| 34 | Name: "rediscache_request_duration_seconds", |
| 35 | Help: "Total time spent in seconds doing Redis requests.", |
| 36 | Buckets: prometheus.ExponentialBuckets(0.000016, 4, 8), |
| 37 | ConstLabels: prometheus.Labels{"name": name}, |
| 38 | }, []string{"method", "status_code"}), |
| 39 | ), |
| 40 | } |
| 41 | if err := cache.redis.Ping(context.Background()); err != nil { |
| 42 | level.Error(logger).Log("msg", "error connecting to redis", "name", name, "err", err) |
| 43 | } |
| 44 | return cache |
| 45 | } |
| 46 | |
| 47 | func redisStatusCode(err error) string { |
| 48 | // TODO: Figure out if there are more error types returned by Redis |