File tree 2 files changed +7
-3
lines changed
implementations/micrometer-registry-otlp/src
main/java/io/micrometer/registry/otlp
test/java/io/micrometer/registry/otlp
2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -309,7 +309,7 @@ Metric writeGauge(Gauge gauge) {
309
309
return getMetricBuilder (gauge .getId ())
310
310
.setGauge (io .opentelemetry .proto .metrics .v1 .Gauge .newBuilder ()
311
311
.addDataPoints (NumberDataPoint .newBuilder ()
312
- .setTimeUnixNano (getTimeUnixNano ( ))
312
+ .setTimeUnixNano (TimeUnit . MILLISECONDS . toNanos ( clock . wallTime () ))
313
313
.setAsDouble (gauge .value ())
314
314
.addAllAttributes (getTagsForId (gauge .getId ()))
315
315
.build ()))
Original file line number Diff line number Diff line change @@ -78,7 +78,9 @@ void gauge() {
78
78
Metric metric = writeToMetric (gauge );
79
79
assertThat (metric .getGauge ()).isNotNull ();
80
80
assertThat (metric .getGauge ().getDataPoints (0 ).getAsDouble ()).isEqualTo (5 );
81
- assertThat (metric .getGauge ().getDataPoints (0 ).getTimeUnixNano ()).isEqualTo (TimeUnit .MINUTES .toNanos (1 ));
81
+ assertThat (metric .getGauge ().getDataPoints (0 ).getTimeUnixNano ())
82
+ .describedAs ("Gauges should have timestamp of the instant when data is sampled" )
83
+ .isEqualTo (otlpConfig ().step ().plus (Duration .ofMillis (1 )).toNanos ());
82
84
}
83
85
84
86
@ Test
@@ -88,7 +90,9 @@ void timeGauge() {
88
90
Metric metric = writeToMetric (timeGauge );
89
91
assertThat (metric .getGauge ()).isNotNull ();
90
92
assertThat (metric .getGauge ().getDataPoints (0 ).getAsDouble ()).isEqualTo (0.024 );
91
- assertThat (metric .getGauge ().getDataPoints (0 ).getTimeUnixNano ()).isEqualTo (TimeUnit .MINUTES .toNanos (1 ));
93
+ assertThat (metric .getGauge ().getDataPoints (0 ).getTimeUnixNano ())
94
+ .describedAs ("Gauges should have timestamp of the instant when data is sampled" )
95
+ .isEqualTo (otlpConfig ().step ().plus (Duration .ofMillis (1 )).toNanos ());
92
96
}
93
97
94
98
@ Test
You can’t perform that action at this time.
0 commit comments