33
33
import io .prometheus .metrics .model .snapshots .ClassicHistogramBuckets ;
34
34
import io .prometheus .metrics .model .snapshots .CounterSnapshot ;
35
35
import io .prometheus .metrics .model .snapshots .CounterSnapshot .CounterDataPointSnapshot ;
36
- import io .prometheus .metrics .model .snapshots .DataPointSnapshot ;
37
36
import io .prometheus .metrics .model .snapshots .Exemplar ;
38
37
import io .prometheus .metrics .model .snapshots .Exemplars ;
39
38
import io .prometheus .metrics .model .snapshots .GaugeSnapshot ;
@@ -110,11 +109,11 @@ MetricSnapshots convert(@Nullable Collection<MetricData> metricDataCollection) {
110
109
if (metricDataCollection == null || metricDataCollection .isEmpty ()) {
111
110
return MetricSnapshots .of ();
112
111
}
113
- Map <String , MetricSnapshot <?> > snapshotsByName = new HashMap <>(metricDataCollection .size ());
112
+ Map <String , MetricSnapshot > snapshotsByName = new HashMap <>(metricDataCollection .size ());
114
113
Resource resource = null ;
115
114
Set <InstrumentationScopeInfo > scopes = new LinkedHashSet <>();
116
115
for (MetricData metricData : metricDataCollection ) {
117
- MetricSnapshot <?> snapshot = convert (metricData );
116
+ MetricSnapshot snapshot = convert (metricData );
118
117
if (snapshot == null ) {
119
118
continue ;
120
119
}
@@ -136,7 +135,7 @@ MetricSnapshots convert(@Nullable Collection<MetricData> metricDataCollection) {
136
135
}
137
136
138
137
@ Nullable
139
- private MetricSnapshot <?> convert (MetricData metricData ) {
138
+ private MetricSnapshot convert (MetricData metricData ) {
140
139
141
140
// Note that AggregationTemporality.DELTA should never happen
142
141
// because PrometheusMetricReader#getAggregationTemporality returns CUMULATIVE.
@@ -549,10 +548,10 @@ private static MetricMetadata convertMetadata(MetricData metricData) {
549
548
}
550
549
551
550
private static void putOrMerge (
552
- Map <String , MetricSnapshot <?>> snapshotsByName , MetricSnapshot <?> snapshot ) {
551
+ Map <String , MetricSnapshot > snapshotsByName , MetricSnapshot snapshot ) {
553
552
String name = snapshot .getMetadata ().getPrometheusName ();
554
553
if (snapshotsByName .containsKey (name )) {
555
- MetricSnapshot <?> merged = merge (snapshotsByName .get (name ), snapshot );
554
+ MetricSnapshot merged = merge (snapshotsByName .get (name ), snapshot );
556
555
if (merged != null ) {
557
556
snapshotsByName .put (name , merged );
558
557
}
@@ -568,9 +567,7 @@ private static void putOrMerge(
568
567
* type. If the type differs, we log a message and drop one of them.
569
568
*/
570
569
@ Nullable
571
- @ SuppressWarnings ("unchecked" )
572
- private static <T extends DataPointSnapshot > MetricSnapshot <T > merge (
573
- MetricSnapshot <?> a , MetricSnapshot <?> b ) {
570
+ private static MetricSnapshot merge (MetricSnapshot a , MetricSnapshot b ) {
574
571
MetricMetadata metadata = mergeMetadata (a .getMetadata (), b .getMetadata ());
575
572
if (metadata == null ) {
576
573
return null ;
@@ -580,27 +577,27 @@ private static <T extends DataPointSnapshot> MetricSnapshot<T> merge(
580
577
List <GaugeDataPointSnapshot > dataPoints = new ArrayList <>(numberOfDataPoints );
581
578
dataPoints .addAll (((GaugeSnapshot ) a ).getDataPoints ());
582
579
dataPoints .addAll (((GaugeSnapshot ) b ).getDataPoints ());
583
- return ( MetricSnapshot < T >) new GaugeSnapshot (metadata , dataPoints );
580
+ return new GaugeSnapshot (metadata , dataPoints );
584
581
} else if (a instanceof CounterSnapshot && b instanceof CounterSnapshot ) {
585
582
List <CounterDataPointSnapshot > dataPoints = new ArrayList <>(numberOfDataPoints );
586
583
dataPoints .addAll (((CounterSnapshot ) a ).getDataPoints ());
587
584
dataPoints .addAll (((CounterSnapshot ) b ).getDataPoints ());
588
- return ( MetricSnapshot < T >) new CounterSnapshot (metadata , dataPoints );
585
+ return new CounterSnapshot (metadata , dataPoints );
589
586
} else if (a instanceof HistogramSnapshot && b instanceof HistogramSnapshot ) {
590
587
List <HistogramDataPointSnapshot > dataPoints = new ArrayList <>(numberOfDataPoints );
591
588
dataPoints .addAll (((HistogramSnapshot ) a ).getDataPoints ());
592
589
dataPoints .addAll (((HistogramSnapshot ) b ).getDataPoints ());
593
- return ( MetricSnapshot < T >) new HistogramSnapshot (metadata , dataPoints );
590
+ return new HistogramSnapshot (metadata , dataPoints );
594
591
} else if (a instanceof SummarySnapshot && b instanceof SummarySnapshot ) {
595
592
List <SummaryDataPointSnapshot > dataPoints = new ArrayList <>(numberOfDataPoints );
596
593
dataPoints .addAll (((SummarySnapshot ) a ).getDataPoints ());
597
594
dataPoints .addAll (((SummarySnapshot ) b ).getDataPoints ());
598
- return ( MetricSnapshot < T >) new SummarySnapshot (metadata , dataPoints );
595
+ return new SummarySnapshot (metadata , dataPoints );
599
596
} else if (a instanceof InfoSnapshot && b instanceof InfoSnapshot ) {
600
597
List <InfoDataPointSnapshot > dataPoints = new ArrayList <>(numberOfDataPoints );
601
598
dataPoints .addAll (((InfoSnapshot ) a ).getDataPoints ());
602
599
dataPoints .addAll (((InfoSnapshot ) b ).getDataPoints ());
603
- return ( MetricSnapshot < T >) new InfoSnapshot (metadata , dataPoints );
600
+ return new InfoSnapshot (metadata , dataPoints );
604
601
} else {
605
602
THROTTLING_LOGGER .log (
606
603
Level .WARNING ,
@@ -641,7 +638,7 @@ private static MetricMetadata mergeMetadata(MetricMetadata a, MetricMetadata b)
641
638
return new MetricMetadata (name , help , unit );
642
639
}
643
640
644
- private static String typeString (MetricSnapshot <?> snapshot ) {
641
+ private static String typeString (MetricSnapshot snapshot ) {
645
642
// Simple helper for a log message.
646
643
return snapshot .getClass ().getSimpleName ().replace ("Snapshot" , "" ).toLowerCase (Locale .ENGLISH );
647
644
}
0 commit comments