Skip to content

Commit 2a1c274

Browse files
authored
update prom client (#6857)
1 parent 6c3725d commit 2a1c274

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

dependencyManagement/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ val DEPENDENCIES = listOf(
7272
"io.opentelemetry.proto:opentelemetry-proto:1.3.2-alpha",
7373
"io.opentracing:opentracing-api:0.33.0",
7474
"io.opentracing:opentracing-noop:0.33.0",
75-
"io.prometheus:prometheus-metrics-exporter-httpserver:1.3.2",
75+
"io.prometheus:prometheus-metrics-exporter-httpserver:1.3.3",
7676
"junit:junit:4.13.2",
7777
"nl.jqno.equalsverifier:equalsverifier:3.17.2",
7878
"org.awaitility:awaitility:4.2.2",

exporters/prometheus/src/main/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverter.java

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import io.prometheus.metrics.model.snapshots.ClassicHistogramBuckets;
3434
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
3535
import io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot;
36-
import io.prometheus.metrics.model.snapshots.DataPointSnapshot;
3736
import io.prometheus.metrics.model.snapshots.Exemplar;
3837
import io.prometheus.metrics.model.snapshots.Exemplars;
3938
import io.prometheus.metrics.model.snapshots.GaugeSnapshot;
@@ -110,11 +109,11 @@ MetricSnapshots convert(@Nullable Collection<MetricData> metricDataCollection) {
110109
if (metricDataCollection == null || metricDataCollection.isEmpty()) {
111110
return MetricSnapshots.of();
112111
}
113-
Map<String, MetricSnapshot<?>> snapshotsByName = new HashMap<>(metricDataCollection.size());
112+
Map<String, MetricSnapshot> snapshotsByName = new HashMap<>(metricDataCollection.size());
114113
Resource resource = null;
115114
Set<InstrumentationScopeInfo> scopes = new LinkedHashSet<>();
116115
for (MetricData metricData : metricDataCollection) {
117-
MetricSnapshot<?> snapshot = convert(metricData);
116+
MetricSnapshot snapshot = convert(metricData);
118117
if (snapshot == null) {
119118
continue;
120119
}
@@ -136,7 +135,7 @@ MetricSnapshots convert(@Nullable Collection<MetricData> metricDataCollection) {
136135
}
137136

138137
@Nullable
139-
private MetricSnapshot<?> convert(MetricData metricData) {
138+
private MetricSnapshot convert(MetricData metricData) {
140139

141140
// Note that AggregationTemporality.DELTA should never happen
142141
// because PrometheusMetricReader#getAggregationTemporality returns CUMULATIVE.
@@ -549,10 +548,10 @@ private static MetricMetadata convertMetadata(MetricData metricData) {
549548
}
550549

551550
private static void putOrMerge(
552-
Map<String, MetricSnapshot<?>> snapshotsByName, MetricSnapshot<?> snapshot) {
551+
Map<String, MetricSnapshot> snapshotsByName, MetricSnapshot snapshot) {
553552
String name = snapshot.getMetadata().getPrometheusName();
554553
if (snapshotsByName.containsKey(name)) {
555-
MetricSnapshot<?> merged = merge(snapshotsByName.get(name), snapshot);
554+
MetricSnapshot merged = merge(snapshotsByName.get(name), snapshot);
556555
if (merged != null) {
557556
snapshotsByName.put(name, merged);
558557
}
@@ -568,9 +567,7 @@ private static void putOrMerge(
568567
* type. If the type differs, we log a message and drop one of them.
569568
*/
570569
@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) {
574571
MetricMetadata metadata = mergeMetadata(a.getMetadata(), b.getMetadata());
575572
if (metadata == null) {
576573
return null;
@@ -580,27 +577,27 @@ private static <T extends DataPointSnapshot> MetricSnapshot<T> merge(
580577
List<GaugeDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
581578
dataPoints.addAll(((GaugeSnapshot) a).getDataPoints());
582579
dataPoints.addAll(((GaugeSnapshot) b).getDataPoints());
583-
return (MetricSnapshot<T>) new GaugeSnapshot(metadata, dataPoints);
580+
return new GaugeSnapshot(metadata, dataPoints);
584581
} else if (a instanceof CounterSnapshot && b instanceof CounterSnapshot) {
585582
List<CounterDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
586583
dataPoints.addAll(((CounterSnapshot) a).getDataPoints());
587584
dataPoints.addAll(((CounterSnapshot) b).getDataPoints());
588-
return (MetricSnapshot<T>) new CounterSnapshot(metadata, dataPoints);
585+
return new CounterSnapshot(metadata, dataPoints);
589586
} else if (a instanceof HistogramSnapshot && b instanceof HistogramSnapshot) {
590587
List<HistogramDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
591588
dataPoints.addAll(((HistogramSnapshot) a).getDataPoints());
592589
dataPoints.addAll(((HistogramSnapshot) b).getDataPoints());
593-
return (MetricSnapshot<T>) new HistogramSnapshot(metadata, dataPoints);
590+
return new HistogramSnapshot(metadata, dataPoints);
594591
} else if (a instanceof SummarySnapshot && b instanceof SummarySnapshot) {
595592
List<SummaryDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
596593
dataPoints.addAll(((SummarySnapshot) a).getDataPoints());
597594
dataPoints.addAll(((SummarySnapshot) b).getDataPoints());
598-
return (MetricSnapshot<T>) new SummarySnapshot(metadata, dataPoints);
595+
return new SummarySnapshot(metadata, dataPoints);
599596
} else if (a instanceof InfoSnapshot && b instanceof InfoSnapshot) {
600597
List<InfoDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
601598
dataPoints.addAll(((InfoSnapshot) a).getDataPoints());
602599
dataPoints.addAll(((InfoSnapshot) b).getDataPoints());
603-
return (MetricSnapshot<T>) new InfoSnapshot(metadata, dataPoints);
600+
return new InfoSnapshot(metadata, dataPoints);
604601
} else {
605602
THROTTLING_LOGGER.log(
606603
Level.WARNING,
@@ -641,7 +638,7 @@ private static MetricMetadata mergeMetadata(MetricMetadata a, MetricMetadata b)
641638
return new MetricMetadata(name, help, unit);
642639
}
643640

644-
private static String typeString(MetricSnapshot<?> snapshot) {
641+
private static String typeString(MetricSnapshot snapshot) {
645642
// Simple helper for a log message.
646643
return snapshot.getClass().getSimpleName().replace("Snapshot", "").toLowerCase(Locale.ENGLISH);
647644
}

exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/PrometheusHttpServerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import io.prometheus.metrics.exporter.httpserver.MetricsHandler;
4545
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
4646
import io.prometheus.metrics.model.registry.PrometheusRegistry;
47-
import io.prometheus.metrics.shaded.com_google_protobuf_4_28_2.TextFormat;
47+
import io.prometheus.metrics.shaded.com_google_protobuf_4_28_3.TextFormat;
4848
import java.io.ByteArrayInputStream;
4949
import java.io.IOException;
5050
import java.net.ServerSocket;

0 commit comments

Comments
 (0)