feat(redis): register prometheus metrics

This commit is contained in:
Trong Huu Nguyen
2025-03-04 14:54:46 +01:00
parent cd3bd4bdeb
commit 12f6ce57aa
3 changed files with 8 additions and 0 deletions

1
go.mod
View File

@@ -20,6 +20,7 @@ require (
github.com/nais/liberator v0.0.0-20241220102102-462db3a4a1dd
github.com/prometheus/client_golang v1.21.0
github.com/redis/go-redis/extra/redisotel/v9 v9.7.1
github.com/redis/go-redis/extra/redisprometheus/v9 v9.7.1
github.com/redis/go-redis/v9 v9.7.1
github.com/riandyrn/otelchi v0.12.1
github.com/rs/cors v1.11.1

2
go.sum
View File

@@ -108,6 +108,8 @@ github.com/redis/go-redis/extra/rediscmd/v9 v9.7.1 h1:+o7rrBoj54t8fqQSmnwRLdLzp5
github.com/redis/go-redis/extra/rediscmd/v9 v9.7.1/go.mod h1:bWIjbxmrAk9eKGg9LSko3oQefoYGyWV4xzNS55PgL60=
github.com/redis/go-redis/extra/redisotel/v9 v9.7.1 h1:LJF39lvUagUpKfL2/gZIp5vHv3AwXt9zOZ/Xual/CzI=
github.com/redis/go-redis/extra/redisotel/v9 v9.7.1/go.mod h1:VAY1vDpD/dLwfw/wU5SsexXNhCO9DjhRoGkmJeFONoE=
github.com/redis/go-redis/extra/redisprometheus/v9 v9.7.1 h1:sCa0InGc1p6nNEFIaugn0ZGApaIfAmIziL4vWfNKEGc=
github.com/redis/go-redis/extra/redisprometheus/v9 v9.7.1/go.mod h1:6dQINZSQOMI/fnlPGqF7J2etW13KFzr+6kZOxy/wWpQ=
github.com/redis/go-redis/v9 v9.7.1 h1:4LhKRCIduqXqtvCUlaq9c8bdHOkICjDMrr1+Zb3osAc=
github.com/redis/go-redis/v9 v9.7.1/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw=
github.com/riandyrn/otelchi v0.12.1 h1:FdRKK3/RgZ/T+d+qTH5Uw3MFx0KwRF38SkdfTMMq/m8=

View File

@@ -5,7 +5,9 @@ import (
"fmt"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/redis/go-redis/extra/redisotel/v9"
"github.com/redis/go-redis/extra/redisprometheus/v9"
log "github.com/sirupsen/logrus"
"github.com/nais/wonderwall/pkg/config"
@@ -31,6 +33,9 @@ func NewStore(cfg *config.Config) (Store, error) {
return nil, fmt.Errorf("failed to create Redis Client: %w", err)
}
collector := redisprometheus.NewCollector("wonderwall", "", redisClient)
prometheus.Register(collector)
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()