@@ -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" ,
@@ -148,16 +153,16 @@ func reportPoolStats(rdb *redis.Client, conf *config) error {
148
153
func (ctx context.Context , o metric.Observer ) error {
149
154
stats := rdb .PoolStats ()
150
155
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 ))
154
159
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 ))
157
162
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 ))
161
166
return nil
162
167
},
163
168
idleMax ,
0 commit comments