@@ -82,10 +82,15 @@ func InstrumentMetrics(rdb redis.UniversalClient, opts ...MetricsOption) error {
8282 }
8383}
8484
85+ func poolStatsAttrs (conf * config ) (poolAttrs , idleAttrs , usedAttrs attribute.Set ) {
86+ poolAttrs = attribute .NewSet (conf .attrs ... )
87+ idleAttrs = attribute .NewSet (append (poolAttrs .ToSlice (), attribute .String ("state" , "idle" ))... )
88+ usedAttrs = attribute .NewSet (append (poolAttrs .ToSlice (), attribute .String ("state" , "used" ))... )
89+ return
90+ }
91+
8592func reportPoolStats (rdb * redis.Client , conf * config ) error {
86- labels := conf .attrs
87- idleAttrs := append (labels , attribute .String ("state" , "idle" ))
88- usedAttrs := append (labels , attribute .String ("state" , "used" ))
93+ poolAttrs , idleAttrs , usedAttrs := poolStatsAttrs (conf )
8994
9095 idleMax , err := conf .meter .Int64ObservableUpDownCounter (
9196 "db.client.connections.idle.max" ,
@@ -148,16 +153,16 @@ func reportPoolStats(rdb *redis.Client, conf *config) error {
148153 func (ctx context.Context , o metric.Observer ) error {
149154 stats := rdb .PoolStats ()
150155
151- o .ObserveInt64 (idleMax , int64 (redisConf .MaxIdleConns ), metric .WithAttributes ( labels ... ))
152- o .ObserveInt64 (idleMin , int64 (redisConf .MinIdleConns ), metric .WithAttributes ( labels ... ))
153- o .ObserveInt64 (connsMax , int64 (redisConf .PoolSize ), metric .WithAttributes ( labels ... ))
156+ o .ObserveInt64 (idleMax , int64 (redisConf .MaxIdleConns ), metric .WithAttributeSet ( poolAttrs ))
157+ o .ObserveInt64 (idleMin , int64 (redisConf .MinIdleConns ), metric .WithAttributeSet ( poolAttrs ))
158+ o .ObserveInt64 (connsMax , int64 (redisConf .PoolSize ), metric .WithAttributeSet ( poolAttrs ))
154159
155- o .ObserveInt64 (usage , int64 (stats .IdleConns ), metric .WithAttributes (idleAttrs ... ))
156- o .ObserveInt64 (usage , int64 (stats .TotalConns - stats .IdleConns ), metric .WithAttributes (usedAttrs ... ))
160+ o .ObserveInt64 (usage , int64 (stats .IdleConns ), metric .WithAttributeSet (idleAttrs ))
161+ o .ObserveInt64 (usage , int64 (stats .TotalConns - stats .IdleConns ), metric .WithAttributeSet (usedAttrs ))
157162
158- o .ObserveInt64 (timeouts , int64 (stats .Timeouts ), metric .WithAttributes ( labels ... ))
159- o .ObserveInt64 (hits , int64 (stats .Hits ), metric .WithAttributes ( labels ... ))
160- o .ObserveInt64 (misses , int64 (stats .Misses ), metric .WithAttributes ( labels ... ))
163+ o .ObserveInt64 (timeouts , int64 (stats .Timeouts ), metric .WithAttributeSet ( poolAttrs ))
164+ o .ObserveInt64 (hits , int64 (stats .Hits ), metric .WithAttributeSet ( poolAttrs ))
165+ o .ObserveInt64 (misses , int64 (stats .Misses ), metric .WithAttributeSet ( poolAttrs ))
161166 return nil
162167 },
163168 idleMax ,
0 commit comments