Commit 08329ba2 authored by Murphy Law's avatar Murphy Law Committed by GitHub

proxyd: Record latency of redis cache operations (#2442)

Co-authored-by: default avatarmergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 3956aecd
---
'@eth-optimism/proxyd': patch
---
proxyd: Record redis cache operation latency
...@@ -59,7 +59,10 @@ func newRedisCache(url string) (*redisCache, error) { ...@@ -59,7 +59,10 @@ func newRedisCache(url string) (*redisCache, error) {
} }
func (c *redisCache) Get(ctx context.Context, key string) (string, error) { func (c *redisCache) Get(ctx context.Context, key string) (string, error) {
start := time.Now()
val, err := c.rdb.Get(ctx, key).Result() val, err := c.rdb.Get(ctx, key).Result()
redisCacheDurationSumm.WithLabelValues("GET").Observe(float64(time.Since(start).Milliseconds()))
if err == redis.Nil { if err == redis.Nil {
return "", nil return "", nil
} else if err != nil { } else if err != nil {
...@@ -70,7 +73,10 @@ func (c *redisCache) Get(ctx context.Context, key string) (string, error) { ...@@ -70,7 +73,10 @@ func (c *redisCache) Get(ctx context.Context, key string) (string, error) {
} }
func (c *redisCache) Put(ctx context.Context, key string, value string) error { func (c *redisCache) Put(ctx context.Context, key string, value string) error {
start := time.Now()
err := c.rdb.SetEX(ctx, key, value, redisTTL).Err() err := c.rdb.SetEX(ctx, key, value, redisTTL).Err()
redisCacheDurationSumm.WithLabelValues("SETEX").Observe(float64(time.Since(start).Milliseconds()))
if err != nil { if err != nil {
RecordRedisError("CacheSet") RecordRedisError("CacheSet")
} }
......
...@@ -22,6 +22,7 @@ const ( ...@@ -22,6 +22,7 @@ const (
) )
var PayloadSizeBuckets = []float64{10, 50, 100, 500, 1000, 5000, 10000, 100000, 1000000} var PayloadSizeBuckets = []float64{10, 50, 100, 500, 1000, 5000, 10000, 100000, 1000000}
var MillisecondDurationBuckets = []float64{1, 10, 50, 100, 500, 1000, 5000, 10000, 100000}
var ( var (
rpcRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{ rpcRequestsTotal = promauto.NewCounter(prometheus.CounterOpts{
...@@ -198,6 +199,13 @@ var ( ...@@ -198,6 +199,13 @@ var (
"gas price too low", "gas price too low",
"invalid parameters", "invalid parameters",
} }
redisCacheDurationSumm = promauto.NewHistogramVec(prometheus.HistogramOpts{
Namespace: MetricsNamespace,
Name: "redis_cache_duration_milliseconds",
Help: "Histogram of Redis command durations, in milliseconds.",
Buckets: MillisecondDurationBuckets,
}, []string{"command"})
) )
func RecordRedisError(source string) { func RecordRedisError(source string) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment