2727 operationsFailureTotal * prometheus.CounterVec
2828 operationLatencySeconds * prometheus.HistogramVec
2929
30+ retryAttempts * prometheus.GaugeVec
3031 retryAttemptsTotal * prometheus.CounterVec
3132 retriesSuccessTotal * prometheus.CounterVec
3233 retriesFailureTotal * prometheus.CounterVec
@@ -107,6 +108,14 @@ func New(url, ref, label, jobName string) (*Metrics, error) {
107108 []string {"operation_type" , "operation_status" },
108109 )
109110
111+ m .retryAttempts = prometheus .NewGaugeVec (
112+ prometheus.GaugeOpts {
113+ Name : "sdk_retry_attempts" ,
114+ Help : "Current retry attempts, categorized by operation type." ,
115+ },
116+ []string {"operation_type" },
117+ )
118+
110119 m .retryAttemptsTotal = prometheus .NewCounterVec (
111120 prometheus.CounterOpts {
112121 Name : "sdk_retry_attempts_total" ,
@@ -147,6 +156,7 @@ func New(url, ref, label, jobName string) (*Metrics, error) {
147156 Collector (m .operationsSuccessTotal ).
148157 Collector (m .operationsFailureTotal ).
149158 Collector (m .operationLatencySeconds ).
159+ Collector (m .retryAttempts ).
150160 Collector (m .retryAttemptsTotal ).
151161 Collector (m .retriesSuccessTotal ).
152162 Collector (m .retriesFailureTotal ).
@@ -167,6 +177,7 @@ func (m *Metrics) Reset() error {
167177 m .operationsFailureTotal .Reset ()
168178 m .operationLatencySeconds .Reset ()
169179
180+ m .retryAttempts .Reset ()
170181 m .retryAttemptsTotal .Reset ()
171182 m .retriesSuccessTotal .Reset ()
172183 m .retriesFailureTotal .Reset ()
@@ -192,17 +203,18 @@ func (j Span) Finish(err error, attempts int) {
192203 latency := time .Since (j .start )
193204 j .m .pendingOperations .WithLabelValues (j .name ).Sub (1 )
194205
206+ j .m .retryAttempts .WithLabelValues (j .name ).Set (float64 (attempts ))
195207 j .m .operationsTotal .WithLabelValues (j .name ).Add (1 )
196208 j .m .retryAttemptsTotal .WithLabelValues (j .name ).Add (float64 (attempts ))
197209
198210 if err != nil {
199211 j .m .errorsTotal .WithLabelValues (err .Error ()).Add (1 )
200- // j.m.retriesFailureTotal.WithLabelValues(j.name).Add(1 )
212+ j .m .retriesFailureTotal .WithLabelValues (j .name ).Add (float64 ( attempts ) )
201213 j .m .operationsFailureTotal .WithLabelValues (j .name ).Add (1 )
202214 j .m .operationLatencySeconds .WithLabelValues (j .name , OperationStatusFailue ).Observe (latency .Seconds ())
203215 } else {
216+ j .m .retriesSuccessTotal .WithLabelValues (j .name ).Add (float64 (attempts ))
204217 j .m .operationsSuccessTotal .WithLabelValues (j .name ).Add (1 )
205- // j.m.retriesSuccessTotal.WithLabelValues(j.name).Add(1)
206218 j .m .operationLatencySeconds .WithLabelValues (j .name , OperationStatusSuccess ).Observe (latency .Seconds ())
207219 }
208220}
0 commit comments