@@ -82,10 +82,15 @@ func InstrumentMetrics(rdb redis.UniversalClient, opts ...MetricsOption) error {
82
82
}
83
83
}
84
84
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
+
85
92
func 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 )
89
94
90
95
idleMax , err := conf .meter .Int64ObservableUpDownCounter (
91
96
"db.client.connections.idle.max" ,
@@ -132,14 +137,14 @@ func reportPoolStats(rdb *redis.Client, conf *config) error {
132
137
func (ctx context.Context , o metric.Observer ) error {
133
138
stats := rdb .PoolStats ()
134
139
135
- o .ObserveInt64 (idleMax , int64 (redisConf .MaxIdleConns ), metric .WithAttributes ( labels ... ))
136
- o .ObserveInt64 (idleMin , int64 (redisConf .MinIdleConns ), metric .WithAttributes ( labels ... ))
137
- o .ObserveInt64 (connsMax , int64 (redisConf .PoolSize ), metric .WithAttributes ( labels ... ))
140
+ o .ObserveInt64 (idleMax , int64 (redisConf .MaxIdleConns ), metric .WithAttributeSet ( poolAttrs ))
141
+ o .ObserveInt64 (idleMin , int64 (redisConf .MinIdleConns ), metric .WithAttributeSet ( poolAttrs ))
142
+ o .ObserveInt64 (connsMax , int64 (redisConf .PoolSize ), metric .WithAttributeSet ( poolAttrs ))
138
143
139
- o .ObserveInt64 (usage , int64 (stats .IdleConns ), metric .WithAttributes (idleAttrs ... ))
140
- o .ObserveInt64 (usage , int64 (stats .TotalConns - stats .IdleConns ), metric .WithAttributes (usedAttrs ... ))
144
+ o .ObserveInt64 (usage , int64 (stats .IdleConns ), metric .WithAttributeSet (idleAttrs ))
145
+ o .ObserveInt64 (usage , int64 (stats .TotalConns - stats .IdleConns ), metric .WithAttributeSet (usedAttrs ))
141
146
142
- o .ObserveInt64 (timeouts , int64 (stats .Timeouts ), metric .WithAttributes ( labels ... ))
147
+ o .ObserveInt64 (timeouts , int64 (stats .Timeouts ), metric .WithAttributeSet ( poolAttrs ))
143
148
return nil
144
149
},
145
150
idleMax ,
0 commit comments