Skip to content

Commit 0794e78

Browse files
committed
fix prometheus test
1 parent 7e337f6 commit 0794e78

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -972,29 +972,23 @@ void createdTimestamp() throws IOException {
972972

973973
LongCounter counter = meter.counterBuilder("requests").build();
974974
testClock.advance(Duration.ofMillis(1));
975+
long bearStartNanos = testClock.now();
975976
counter.add(3, Attributes.builder().put("animal", "bear").build());
976977
testClock.advance(Duration.ofMillis(1));
978+
long mouseStartNanos = testClock.now();
977979
counter.add(2, Attributes.builder().put("animal", "mouse").build());
978980
testClock.advance(Duration.ofMillis(1));
979981

980-
// There is a curious difference between Prometheus and OpenTelemetry:
981-
// In Prometheus metrics the _created timestamp is per data point,
982-
// i.e. the _created timestamp says when this specific set of label values
983-
// was first observed.
984-
// In the OTel Java SDK the _created timestamp is the initialization time
985-
// of the SdkMeterProvider, i.e. all data points will have the same _created timestamp.
986-
// So we expect the _created timestamp to be the start time of the application,
987-
// not the timestamp when the counter or an individual data point was created.
988982
String expected =
989983
""
990984
+ "# TYPE requests counter\n"
991985
+ "requests_total{animal=\"bear\",otel_scope_name=\"test\"} 3.0\n"
992986
+ "requests_created{animal=\"bear\",otel_scope_name=\"test\"} "
993-
+ createdTimestamp
987+
+ convertTimestamp(bearStartNanos)
994988
+ "\n"
995989
+ "requests_total{animal=\"mouse\",otel_scope_name=\"test\"} 2.0\n"
996990
+ "requests_created{animal=\"mouse\",otel_scope_name=\"test\"} "
997-
+ createdTimestamp
991+
+ convertTimestamp(mouseStartNanos)
998992
+ "\n"
999993
+ "# TYPE target info\n"
1000994
+ "target_info{service_name=\"unknown_service:java\",telemetry_sdk_language=\"java\",telemetry_sdk_name=\"opentelemetry\",telemetry_sdk_version=\"1.x.x\"} 1\n"

0 commit comments

Comments
 (0)