@@ -280,6 +280,18 @@ func createInt64Counter(setOfMetrics map[string]bool, metricName string, meter o
280
280
return ret
281
281
}
282
282
283
+ func createInt64UpDownCounter (setOfMetrics map [string ]bool , metricName string , meter otelmetric.Meter , options ... otelmetric.Int64UpDownCounterOption ) otelmetric.Int64UpDownCounter {
284
+ if _ , ok := setOfMetrics [metricName ]; ! ok {
285
+ return noop.Int64UpDownCounter {}
286
+ }
287
+ ret , err := meter .Int64UpDownCounter (string (metricName ), options ... )
288
+ if err != nil {
289
+ logger .Errorf ("failed to register metric \" %v\" , will not record: %v" , metricName , err )
290
+ return noop.Int64UpDownCounter {}
291
+ }
292
+ return ret
293
+ }
294
+
283
295
func createFloat64Counter (setOfMetrics map [string ]bool , metricName string , meter otelmetric.Meter , options ... otelmetric.Float64CounterOption ) otelmetric.Float64Counter {
284
296
if _ , ok := setOfMetrics [metricName ]; ! ok {
285
297
return noop.Float64Counter {}
@@ -350,11 +362,12 @@ func optionFromLabels(labelKeys []string, optionalLabelKeys []string, optionalLa
350
362
// registryMetrics implements MetricsRecorder for the client and server stats
351
363
// handlers.
352
364
type registryMetrics struct {
353
- intCounts map [* estats.MetricDescriptor ]otelmetric.Int64Counter
354
- floatCounts map [* estats.MetricDescriptor ]otelmetric.Float64Counter
355
- intHistos map [* estats.MetricDescriptor ]otelmetric.Int64Histogram
356
- floatHistos map [* estats.MetricDescriptor ]otelmetric.Float64Histogram
357
- intGauges map [* estats.MetricDescriptor ]otelmetric.Int64Gauge
365
+ intCounts map [* estats.MetricDescriptor ]otelmetric.Int64Counter
366
+ floatCounts map [* estats.MetricDescriptor ]otelmetric.Float64Counter
367
+ intHistos map [* estats.MetricDescriptor ]otelmetric.Int64Histogram
368
+ floatHistos map [* estats.MetricDescriptor ]otelmetric.Float64Histogram
369
+ intGauges map [* estats.MetricDescriptor ]otelmetric.Int64Gauge
370
+ intUpDownCounts map [* estats.MetricDescriptor ]otelmetric.Int64UpDownCounter
358
371
359
372
optionalLabels []string
360
373
}
@@ -365,6 +378,7 @@ func (rm *registryMetrics) registerMetrics(metrics *stats.MetricSet, meter otelm
365
378
rm .intHistos = make (map [* estats.MetricDescriptor ]otelmetric.Int64Histogram )
366
379
rm .floatHistos = make (map [* estats.MetricDescriptor ]otelmetric.Float64Histogram )
367
380
rm .intGauges = make (map [* estats.MetricDescriptor ]otelmetric.Int64Gauge )
381
+ rm .intUpDownCounts = make (map [* estats.MetricDescriptor ]otelmetric.Int64UpDownCounter )
368
382
369
383
for metric := range metrics .Metrics () {
370
384
desc := estats .DescriptorForMetric (metric )
@@ -385,6 +399,8 @@ func (rm *registryMetrics) registerMetrics(metrics *stats.MetricSet, meter otelm
385
399
rm .floatHistos [desc ] = createFloat64Histogram (metrics .Metrics (), desc .Name , meter , otelmetric .WithUnit (desc .Unit ), otelmetric .WithDescription (desc .Description ), otelmetric .WithExplicitBucketBoundaries (desc .Bounds ... ))
386
400
case estats .MetricTypeIntGauge :
387
401
rm .intGauges [desc ] = createInt64Gauge (metrics .Metrics (), desc .Name , meter , otelmetric .WithUnit (desc .Unit ), otelmetric .WithDescription (desc .Description ))
402
+ case estats .MetricTypeIntUpDownCount :
403
+ rm .intUpDownCounts [desc ] = createInt64UpDownCounter (metrics .Metrics (), desc .Name , meter , otelmetric .WithUnit (desc .Unit ), otelmetric .WithDescription (desc .Description ))
388
404
}
389
405
}
390
406
}
@@ -397,6 +413,14 @@ func (rm *registryMetrics) RecordInt64Count(handle *estats.Int64CountHandle, inc
397
413
}
398
414
}
399
415
416
+ func (rm * registryMetrics ) RecordInt64UpDownCount (handle * estats.Int64UpDownCountHandle , incr int64 , labels ... string ) {
417
+ desc := handle .Descriptor ()
418
+ if ic , ok := rm .intUpDownCounts [desc ]; ok {
419
+ ao := optionFromLabels (desc .Labels , desc .OptionalLabels , rm .optionalLabels , labels ... )
420
+ ic .Add (context .TODO (), incr , ao )
421
+ }
422
+ }
423
+
400
424
func (rm * registryMetrics ) RecordFloat64Count (handle * estats.Float64CountHandle , incr float64 , labels ... string ) {
401
425
desc := handle .Descriptor ()
402
426
if fc , ok := rm .floatCounts [desc ]; ok {
0 commit comments