mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
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:
committed by
GitHub
parent
fee1c565c3
commit
b2df60414c
23
util/cache/redis.go
vendored
23
util/cache/redis.go
vendored
@@ -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))
|
||||
|
||||
|
||||
1
util/cache/redis_test.go
vendored
1
util/cache/redis_test.go
vendored
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user