Skip to content

Commit

Permalink
update prom client (#6857)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitlinger authored Nov 8, 2024
1 parent 6c3725d commit 2a1c274
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 1 addition & 1 deletion dependencyManagement/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ val DEPENDENCIES = listOf(
"io.opentelemetry.proto:opentelemetry-proto:1.3.2-alpha",
"io.opentracing:opentracing-api:0.33.0",
"io.opentracing:opentracing-noop:0.33.0",
"io.prometheus:prometheus-metrics-exporter-httpserver:1.3.2",
"io.prometheus:prometheus-metrics-exporter-httpserver:1.3.3",
"junit:junit:4.13.2",
"nl.jqno.equalsverifier:equalsverifier:3.17.2",
"org.awaitility:awaitility:4.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.prometheus.metrics.model.snapshots.ClassicHistogramBuckets;
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
import io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot;
import io.prometheus.metrics.model.snapshots.DataPointSnapshot;
import io.prometheus.metrics.model.snapshots.Exemplar;
import io.prometheus.metrics.model.snapshots.Exemplars;
import io.prometheus.metrics.model.snapshots.GaugeSnapshot;
Expand Down Expand Up @@ -110,11 +109,11 @@ MetricSnapshots convert(@Nullable Collection<MetricData> metricDataCollection) {
if (metricDataCollection == null || metricDataCollection.isEmpty()) {
return MetricSnapshots.of();
}
Map<String, MetricSnapshot<?>> snapshotsByName = new HashMap<>(metricDataCollection.size());
Map<String, MetricSnapshot> snapshotsByName = new HashMap<>(metricDataCollection.size());
Resource resource = null;
Set<InstrumentationScopeInfo> scopes = new LinkedHashSet<>();
for (MetricData metricData : metricDataCollection) {
MetricSnapshot<?> snapshot = convert(metricData);
MetricSnapshot snapshot = convert(metricData);
if (snapshot == null) {
continue;
}
Expand All @@ -136,7 +135,7 @@ MetricSnapshots convert(@Nullable Collection<MetricData> metricDataCollection) {
}

@Nullable
private MetricSnapshot<?> convert(MetricData metricData) {
private MetricSnapshot convert(MetricData metricData) {

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

private static void putOrMerge(
Map<String, MetricSnapshot<?>> snapshotsByName, MetricSnapshot<?> snapshot) {
Map<String, MetricSnapshot> snapshotsByName, MetricSnapshot snapshot) {
String name = snapshot.getMetadata().getPrometheusName();
if (snapshotsByName.containsKey(name)) {
MetricSnapshot<?> merged = merge(snapshotsByName.get(name), snapshot);
MetricSnapshot merged = merge(snapshotsByName.get(name), snapshot);
if (merged != null) {
snapshotsByName.put(name, merged);
}
Expand All @@ -568,9 +567,7 @@ private static void putOrMerge(
* type. If the type differs, we log a message and drop one of them.
*/
@Nullable
@SuppressWarnings("unchecked")
private static <T extends DataPointSnapshot> MetricSnapshot<T> merge(
MetricSnapshot<?> a, MetricSnapshot<?> b) {
private static MetricSnapshot merge(MetricSnapshot a, MetricSnapshot b) {
MetricMetadata metadata = mergeMetadata(a.getMetadata(), b.getMetadata());
if (metadata == null) {
return null;
Expand All @@ -580,27 +577,27 @@ private static <T extends DataPointSnapshot> MetricSnapshot<T> merge(
List<GaugeDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
dataPoints.addAll(((GaugeSnapshot) a).getDataPoints());
dataPoints.addAll(((GaugeSnapshot) b).getDataPoints());
return (MetricSnapshot<T>) new GaugeSnapshot(metadata, dataPoints);
return new GaugeSnapshot(metadata, dataPoints);
} else if (a instanceof CounterSnapshot && b instanceof CounterSnapshot) {
List<CounterDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
dataPoints.addAll(((CounterSnapshot) a).getDataPoints());
dataPoints.addAll(((CounterSnapshot) b).getDataPoints());
return (MetricSnapshot<T>) new CounterSnapshot(metadata, dataPoints);
return new CounterSnapshot(metadata, dataPoints);
} else if (a instanceof HistogramSnapshot && b instanceof HistogramSnapshot) {
List<HistogramDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
dataPoints.addAll(((HistogramSnapshot) a).getDataPoints());
dataPoints.addAll(((HistogramSnapshot) b).getDataPoints());
return (MetricSnapshot<T>) new HistogramSnapshot(metadata, dataPoints);
return new HistogramSnapshot(metadata, dataPoints);
} else if (a instanceof SummarySnapshot && b instanceof SummarySnapshot) {
List<SummaryDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
dataPoints.addAll(((SummarySnapshot) a).getDataPoints());
dataPoints.addAll(((SummarySnapshot) b).getDataPoints());
return (MetricSnapshot<T>) new SummarySnapshot(metadata, dataPoints);
return new SummarySnapshot(metadata, dataPoints);
} else if (a instanceof InfoSnapshot && b instanceof InfoSnapshot) {
List<InfoDataPointSnapshot> dataPoints = new ArrayList<>(numberOfDataPoints);
dataPoints.addAll(((InfoSnapshot) a).getDataPoints());
dataPoints.addAll(((InfoSnapshot) b).getDataPoints());
return (MetricSnapshot<T>) new InfoSnapshot(metadata, dataPoints);
return new InfoSnapshot(metadata, dataPoints);
} else {
THROTTLING_LOGGER.log(
Level.WARNING,
Expand Down Expand Up @@ -641,7 +638,7 @@ private static MetricMetadata mergeMetadata(MetricMetadata a, MetricMetadata b)
return new MetricMetadata(name, help, unit);
}

private static String typeString(MetricSnapshot<?> snapshot) {
private static String typeString(MetricSnapshot snapshot) {
// Simple helper for a log message.
return snapshot.getClass().getSimpleName().replace("Snapshot", "").toLowerCase(Locale.ENGLISH);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
import io.prometheus.metrics.exporter.httpserver.MetricsHandler;
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics;
import io.prometheus.metrics.model.registry.PrometheusRegistry;
import io.prometheus.metrics.shaded.com_google_protobuf_4_28_2.TextFormat;
import io.prometheus.metrics.shaded.com_google_protobuf_4_28_3.TextFormat;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.ServerSocket;
Expand Down

0 comments on commit 2a1c274

Please sign in to comment.