chore: bumps go redis client 9.17.2 (#25643)

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Patroklos Papapetrou <ppapapetrou76@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
Papapetrou Patroklos
2025-12-17 09:25:04 +02:00
committed by GitHub
parent fee1c565c3
commit b2df60414c
4 changed files with 27 additions and 3 deletions

23
util/cache/redis.go vendored
View File

@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"net"
"strings"
"sync"
"time"
@@ -177,6 +178,23 @@ type redisHook struct {
registry MetricsRegistry
}
// ignoredRedisCommandNames are commands that go-redis may issue during connection setup / bookkeeping
// and which we don't want to count as application-level requests in metrics.
var ignoredRedisCommandNames = map[string]struct{}{
"hello": {},
"client": {},
// Optional: we can enable if we want also want to exclude other setup/noise commands.
// "auth": {},
// "select": {},
// "ping": {},
}
func shouldIgnoreRedisCmd(cmd redis.Cmder) bool {
name := strings.ToLower(strings.TrimSpace(cmd.Name()))
_, ok := ignoredRedisCommandNames[name]
return ok
}
func (rh *redisHook) DialHook(next redis.DialHook) redis.DialHook {
return func(ctx context.Context, network, addr string) (net.Conn, error) {
conn, err := next(ctx, network, addr)
@@ -189,6 +207,11 @@ func (rh *redisHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
startTime := time.Now()
err := next(ctx, cmd)
if shouldIgnoreRedisCmd(cmd) {
return err
}
rh.registry.IncRedisRequest(err != nil && !errors.Is(err, redis.Nil))
rh.registry.ObserveRedisRequestDuration(time.Since(startTime))

View File

@@ -133,6 +133,7 @@ func TestRedisMetrics(t *testing.T) {
ms := NewMockMetricsServer()
redisClient := redis.NewClient(&redis.Options{Addr: mr.Addr()})
faultyRedisClient := redis.NewClient(&redis.Options{Addr: "invalidredishost.invalid:12345"})
CollectMetrics(redisClient, ms, nil)
CollectMetrics(faultyRedisClient, ms, nil)