@@ -213,8 +213,8 @@ public Counter newCounter(Meter.Id id) {
213
213
(conventionName ,
214
214
tagKeys ) -> Stream .of (new MicrometerCollector .Family <>(conventionName ,
215
215
family -> new CounterSnapshot (family .metadata , family .dataPointSnapshots ),
216
- getMetadata (id ) , new CounterDataPointSnapshot (counter . count (),
217
- Labels .of (tagKeys , tagValues ), counter .exemplar (), 0 ))));
216
+ getMetadata (conventionName , id . getDescription ()) , new CounterDataPointSnapshot (
217
+ counter . count (), Labels .of (tagKeys , tagValues ), counter .exemplar (), 0 ))));
218
218
});
219
219
return counter ;
220
220
}
@@ -246,9 +246,9 @@ public DistributionSummary newDistributionSummary(Meter.Id id,
246
246
247
247
Exemplars exemplars = summary .exemplars ();
248
248
families .add (new MicrometerCollector .Family <>(conventionName ,
249
- family -> new SummarySnapshot (family .metadata , family .dataPointSnapshots ), getMetadata ( id ),
250
- new SummaryDataPointSnapshot ( count , sum , quantiles , Labels . of ( tagKeys , tagValues ) ,
251
- exemplars , 0 )));
249
+ family -> new SummarySnapshot (family .metadata , family .dataPointSnapshots ),
250
+ getMetadata ( conventionName , id . getDescription ()), new SummaryDataPointSnapshot ( count , sum ,
251
+ quantiles , Labels . of ( tagKeys , tagValues ), exemplars , 0 )));
252
252
}
253
253
else {
254
254
List <Double > buckets = new ArrayList <>();
@@ -277,8 +277,9 @@ public DistributionSummary newDistributionSummary(Meter.Id id,
277
277
families .add (new MicrometerCollector .Family <>(conventionName ,
278
278
family -> new io .prometheus .metrics .model .snapshots .HistogramSnapshot (family .metadata ,
279
279
family .dataPointSnapshots ),
280
- getMetadata (id ), new HistogramDataPointSnapshot (ClassicHistogramBuckets .of (buckets , counts ),
281
- sum , Labels .of (tagKeys , tagValues ), exemplars , 0 )));
280
+ getMetadata (conventionName , id .getDescription ()),
281
+ new HistogramDataPointSnapshot (ClassicHistogramBuckets .of (buckets , counts ), sum ,
282
+ Labels .of (tagKeys , tagValues ), exemplars , 0 )));
282
283
283
284
// TODO: Add support back for VictoriaMetrics
284
285
// Previously we had low-level control so a histogram was just
@@ -292,7 +293,7 @@ public DistributionSummary newDistributionSummary(Meter.Id id,
292
293
293
294
families .add (new MicrometerCollector .Family <>(conventionName + "_max" ,
294
295
family -> new GaugeSnapshot (family .metadata , family .dataPointSnapshots ),
295
- getMetadata (id , "_max" ),
296
+ getMetadata (conventionName + "_max" , id . getDescription () ),
296
297
new GaugeDataPointSnapshot (summary .max (), Labels .of (tagKeys , tagValues ), null )));
297
298
298
299
return families .build ();
@@ -319,17 +320,18 @@ protected <T> io.micrometer.core.instrument.Gauge newGauge(Meter.Id id, @Nullabl
319
320
applyToCollector (id , (collector ) -> {
320
321
List <String > tagValues = tagValues (id );
321
322
if (id .getName ().endsWith (".info" )) {
322
- collector
323
- .add (tagValues ,
324
- (conventionName , tagKeys ) -> Stream .of (new MicrometerCollector .Family <>(conventionName ,
325
- family -> new InfoSnapshot (family .metadata , family .dataPointSnapshots ),
326
- getMetadata (id ), new InfoDataPointSnapshot (Labels .of (tagKeys , tagValues )))));
323
+ collector .add (tagValues ,
324
+ (conventionName ,
325
+ tagKeys ) -> Stream .of (new MicrometerCollector .Family <>(conventionName ,
326
+ family -> new InfoSnapshot (family .metadata , family .dataPointSnapshots ),
327
+ getMetadata (conventionName , id .getDescription ()),
328
+ new InfoDataPointSnapshot (Labels .of (tagKeys , tagValues )))));
327
329
}
328
330
else {
329
331
collector .add (tagValues ,
330
332
(conventionName , tagKeys ) -> Stream .of (new MicrometerCollector .Family <>(conventionName ,
331
333
family -> new GaugeSnapshot (family .metadata , family .dataPointSnapshots ),
332
- getMetadata (id ),
334
+ getMetadata (conventionName , id . getDescription () ),
333
335
new GaugeDataPointSnapshot (gauge .value (), Labels .of (tagKeys , tagValues ), null ))));
334
336
}
335
337
});
@@ -352,10 +354,12 @@ protected <T> FunctionTimer newFunctionTimer(Meter.Id id, T obj, ToLongFunction<
352
354
applyToCollector (id , (collector ) -> {
353
355
List <String > tagValues = tagValues (id );
354
356
collector .add (tagValues ,
355
- (conventionName , tagKeys ) -> Stream .of (new MicrometerCollector .Family <>(conventionName ,
356
- family -> new SummarySnapshot (family .metadata , family .dataPointSnapshots ), getMetadata (id ),
357
- new SummaryDataPointSnapshot ((long ) ft .count (), ft .totalTime (getBaseTimeUnit ()),
358
- Quantiles .EMPTY , Labels .of (tagKeys , tagValues ), null , 0 ))));
357
+ (conventionName ,
358
+ tagKeys ) -> Stream .of (new MicrometerCollector .Family <>(conventionName ,
359
+ family -> new SummarySnapshot (family .metadata , family .dataPointSnapshots ),
360
+ getMetadata (conventionName , id .getDescription ()),
361
+ new SummaryDataPointSnapshot ((long ) ft .count (), ft .totalTime (getBaseTimeUnit ()),
362
+ Quantiles .EMPTY , Labels .of (tagKeys , tagValues ), null , 0 ))));
359
363
});
360
364
return ft ;
361
365
}
@@ -365,10 +369,12 @@ protected <T> FunctionCounter newFunctionCounter(Meter.Id id, T obj, ToDoubleFun
365
369
FunctionCounter fc = new CumulativeFunctionCounter <>(id , obj , countFunction );
366
370
applyToCollector (id , (collector ) -> {
367
371
List <String > tagValues = tagValues (id );
368
- collector .add (tagValues ,
369
- (conventionName , tagKeys ) -> Stream .of (new MicrometerCollector .Family <>(conventionName ,
370
- family -> new CounterSnapshot (family .metadata , family .dataPointSnapshots ), getMetadata (id ),
371
- new CounterDataPointSnapshot (fc .count (), Labels .of (tagKeys , tagValues ), null , 0 ))));
372
+ collector
373
+ .add (tagValues ,
374
+ (conventionName , tagKeys ) -> Stream .of (new MicrometerCollector .Family <>(conventionName ,
375
+ family -> new CounterSnapshot (family .metadata , family .dataPointSnapshots ),
376
+ getMetadata (conventionName , id .getDescription ()),
377
+ new CounterDataPointSnapshot (fc .count (), Labels .of (tagKeys , tagValues ), null , 0 ))));
372
378
});
373
379
return fc ;
374
380
}
@@ -423,14 +429,16 @@ protected Meter newMeter(Meter.Id id, Meter.Type type, Iterable<Measurement> mea
423
429
private MicrometerCollector .Family <CounterDataPointSnapshot > customCounterFamily (Meter .Id id , String conventionName ,
424
430
String suffix , Labels labels , double value ) {
425
431
return new MicrometerCollector .Family <>(conventionName + suffix ,
426
- family -> new CounterSnapshot (family .metadata , family .dataPointSnapshots ), getMetadata (id , suffix ),
432
+ family -> new CounterSnapshot (family .metadata , family .dataPointSnapshots ),
433
+ getMetadata (conventionName + suffix , id .getDescription ()),
427
434
new CounterDataPointSnapshot (value , labels , null , 0 ));
428
435
}
429
436
430
437
private MicrometerCollector .Family <GaugeDataPointSnapshot > customGaugeFamily (Meter .Id id , String conventionName ,
431
438
String suffix , Labels labels , double value ) {
432
439
return new MicrometerCollector .Family <>(conventionName + suffix ,
433
- family -> new GaugeSnapshot (family .metadata , family .dataPointSnapshots ), getMetadata (id , suffix ),
440
+ family -> new GaugeSnapshot (family .metadata , family .dataPointSnapshots ),
441
+ getMetadata (conventionName + suffix , id .getDescription ()),
434
442
new GaugeDataPointSnapshot (value , labels , null ));
435
443
}
436
444
@@ -470,9 +478,9 @@ private void addDistributionStatisticSamples(Meter.Id id, MicrometerCollector co
470
478
471
479
Exemplars exemplars = createExemplarsWithScaledValues (exemplarsSupplier .get ());
472
480
families .add (new MicrometerCollector .Family <>(conventionName ,
473
- family -> new SummarySnapshot (family .metadata , family .dataPointSnapshots ), getMetadata ( id ),
474
- new SummaryDataPointSnapshot ( count , sum , quantiles , Labels . of ( tagKeys , tagValues ), exemplars ,
475
- 0 )));
481
+ family -> new SummarySnapshot (family .metadata , family .dataPointSnapshots ),
482
+ getMetadata ( conventionName , id . getDescription ()), new SummaryDataPointSnapshot ( count , sum ,
483
+ quantiles , Labels . of ( tagKeys , tagValues ), exemplars , 0 )));
476
484
}
477
485
else {
478
486
List <Double > buckets = new ArrayList <>();
@@ -501,8 +509,9 @@ private void addDistributionStatisticSamples(Meter.Id id, MicrometerCollector co
501
509
families .add (new MicrometerCollector .Family <>(conventionName ,
502
510
family -> new io .prometheus .metrics .model .snapshots .HistogramSnapshot (forLongTaskTimer ,
503
511
family .metadata , family .dataPointSnapshots ),
504
- getMetadata (id ), new HistogramDataPointSnapshot (ClassicHistogramBuckets .of (buckets , counts ),
505
- sum , Labels .of (tagKeys , tagValues ), exemplars , 0 )));
512
+ getMetadata (conventionName , id .getDescription ()),
513
+ new HistogramDataPointSnapshot (ClassicHistogramBuckets .of (buckets , counts ), sum ,
514
+ Labels .of (tagKeys , tagValues ), exemplars , 0 )));
506
515
507
516
// TODO: Add support back for VictoriaMetrics
508
517
// Previously we had low-level control so a histogram was just
@@ -515,9 +524,9 @@ private void addDistributionStatisticSamples(Meter.Id id, MicrometerCollector co
515
524
}
516
525
517
526
families .add (new MicrometerCollector .Family <>(conventionName + "_max" ,
518
- family -> new GaugeSnapshot (family .metadata , family .dataPointSnapshots ), getMetadata ( id , "_max" ),
519
- new GaugeDataPointSnapshot ( histogramSnapshot . max ( getBaseTimeUnit ( )), Labels . of ( tagKeys , tagValues ),
520
- null )));
527
+ family -> new GaugeSnapshot (family .metadata , family .dataPointSnapshots ),
528
+ getMetadata ( conventionName + "_max" , id . getDescription ( )), new GaugeDataPointSnapshot (
529
+ histogramSnapshot . max ( getBaseTimeUnit ()), Labels . of ( tagKeys , tagValues ), null )));
521
530
522
531
return families .build ();
523
532
});
@@ -549,13 +558,8 @@ private void onMeterRemoved(Meter meter) {
549
558
}
550
559
}
551
560
552
- private MetricMetadata getMetadata (Meter .Id id ) {
553
- return getMetadata (id , "" );
554
- }
555
-
556
- private MetricMetadata getMetadata (Meter .Id id , String suffix ) {
557
- String name = config ().namingConvention ().name (id .getName (), id .getType (), id .getBaseUnit ()) + suffix ;
558
- String help = prometheusConfig .descriptions () ? Optional .ofNullable (id .getDescription ()).orElse (" " ) : " " ;
561
+ private MetricMetadata getMetadata (String name , @ Nullable String description ) {
562
+ String help = prometheusConfig .descriptions () ? Optional .ofNullable (description ).orElse (" " ) : " " ;
559
563
// Unit is intentionally not set, see:
560
564
// https://github.com/OpenObservability/OpenMetrics/blob/1386544931307dff279688f332890c31b6c5de36/specification/OpenMetrics.md#unit
561
565
return new MetricMetadata (name , help , null );
0 commit comments