Skip to content

Commit 01d0434

Browse files
committed
fix test
1 parent 4a389b5 commit 01d0434

File tree

8 files changed

+19
-18
lines changed

8 files changed

+19
-18
lines changed

integration-tests/it-exporter/it-exporter-duplicate-metrics-sample/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,4 @@
5656
</build>
5757
</project>
5858

59+

integration-tests/it-exporter/it-exporter-duplicate-metrics-sample/src/main/java/io/prometheus/metrics/it/exporter/duplicatemetrics/DuplicateMetricsSample.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,3 @@ private static int parsePortOrExit(String port) {
9191
return 0; // this won't happen
9292
}
9393
}
94-

integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test/DuplicateMetricsIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44

55
import io.prometheus.client.it.common.ExporterTest;
6-
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_33_1.Metrics;
6+
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_33_2.Metrics;
77
import java.io.IOException;
88
import java.net.URISyntaxException;
99
import java.util.List;
@@ -98,7 +98,7 @@ void testDuplicateMetricsInOpenMetricsTextFormat() throws IOException {
9898

9999
@Test
100100
void testDuplicateMetricsInPrometheusProtobufFormat() throws IOException {
101-
start();2
101+
start();
102102
Response response =
103103
scrape(
104104
"GET",
@@ -196,4 +196,3 @@ private String nameParam() {
196196
return "name[]=" + "http_requests_total";
197197
}
198198
}
199-

prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/internal/PrometheusProtobufWriterImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.google.protobuf.TextFormat;
77
import io.prometheus.metrics.config.EscapingScheme;
88
import io.prometheus.metrics.expositionformats.ExpositionFormatWriter;
9+
import io.prometheus.metrics.expositionformats.TextFormatUtil;
910
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_33_2.Metrics;
1011
import io.prometheus.metrics.model.snapshots.ClassicHistogramBuckets;
1112
import io.prometheus.metrics.model.snapshots.CounterSnapshot;

prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/DuplicateNamesProtobufTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import static org.assertj.core.api.Assertions.assertThat;
44

55
import io.prometheus.metrics.config.EscapingScheme;
6-
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_33_1.Metrics;
6+
import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_33_2.Metrics;
77
import io.prometheus.metrics.expositionformats.internal.PrometheusProtobufWriterImpl;
88
import io.prometheus.metrics.model.registry.Collector;
99
import io.prometheus.metrics.model.registry.PrometheusRegistry;

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MetricType.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
package io.prometheus.metrics.model.registry;
22

33
/**
4-
* Represents the type of a Prometheus metric.
4+
* Represents the type of Prometheus metric.
55
*
66
* <p>This enum is used for early validation when registering collectors with duplicate Prometheus
77
* names. All collectors with the same Prometheus name must have the same metric type.
88
*/
99
public enum MetricType {
10-
/** Counter metric type - monotonically increasing value. */
1110
COUNTER,
1211

13-
/** Gauge metric type - value that can go up or down. */
1412
GAUGE,
1513

16-
/** Histogram metric type - samples observations and counts them in buckets. */
1714
HISTOGRAM,
1815

19-
/** Summary metric type - samples observations and calculates quantiles. */
2016
SUMMARY,
2117

22-
/** Info metric type - key-value pairs providing information about the entity. */
2318
INFO,
2419

25-
/** StateSet metric type - represents a set of boolean states. */
2620
STATESET,
2721

2822
/** Unknown metric type - for custom or legacy collectors. */

prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/registry/MultiCollector.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,21 @@ default List<String> getPrometheusNames() {
7676
*
7777
* <p>This is used during registration to validate that all collectors with the same Prometheus
7878
* name have the same metric type. If this method returns {@code null} for a given name, type
79-
* validation will be skipped for that metric.
79+
* validation at registration time will be skipped for that metric. Note that type validation will
80+
* still occur at scrape time when metrics are collected, but returning {@code null} means errors
81+
* won't be detected until then.
8082
*
81-
* <p>If your collector returns metrics with constant types that do not change at runtime, it is a
82-
* good idea to override this method to enable early type validation at registration time instead
83-
* of at scrape time.
83+
* <p>The default implementation returns {@code null}, which defers all type validation to scrape
84+
* time.
85+
*
86+
* <p>If your collector returns metrics with constant types that do not change at runtime, it is
87+
* recommended to override this method to enable early type validation at registration time
88+
* instead of at scrape time. This provides faster feedback when incompatible metrics are
89+
* registered.
8490
*
8591
* @param prometheusName the Prometheus name to get the type for
86-
* @return the metric type, or {@code null} if unknown
92+
* @return the metric type, or {@code null} if unknown or if validation should be deferred to
93+
* scrape time
8794
*/
8895
@Nullable
8996
default MetricType getMetricType(String prometheusName) {

prometheus-metrics-model/src/test/java/io/prometheus/metrics/model/registry/PrometheusRegistryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public MetricSnapshot collect() {
307307
.dataPoint(
308308
CounterSnapshot.CounterDataPointSnapshot.builder()
309309
.labels(Labels.of("uri", "/hello", "outcome", "SUCCESS"))
310-
.value(50) // Different value!
310+
.value(50) // different value
311311
.build())
312312
.build();
313313
}

0 commit comments

Comments
 (0)