Skip to content

Commit 139b160

Browse files
author
cmaune
committed
feat: adds createdTimestamp to counters exposed via prometheus protobuf protocol
Signed-off-by: cmaune <[email protected]>
1 parent cc29829 commit 139b160

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ public void testTotalStrippedFromName(String name) {
120120
Metrics.MetricFamily protobufData =
121121
new PrometheusProtobufWriterImpl().convert(counter.collect(), EscapingScheme.ALLOW_UTF8);
122122
assertThat(ProtobufUtil.shortDebugString(protobufData))
123-
.isEqualTo(
124-
"name: \"my_counter_seconds_total\" type: COUNTER metric { counter { value: 0.0 } }");
123+
.matches(
124+
"^name: \"my_counter_seconds_total\" type: COUNTER metric \\{ counter \\{ value: 0.0 created_timestamp \\{ seconds: \\d+ nanos: \\d+ } } }$");
125125
}
126126

127127
@Test

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ private Metrics.Metric.Builder convert(CounterDataPointSnapshot data, EscapingSc
130130
if (data.getExemplar() != null) {
131131
counterBuilder.setExemplar(convert(data.getExemplar(), scheme));
132132
}
133+
if (data.hasCreatedTimestamp()) {
134+
counterBuilder.setCreatedTimestamp(
135+
ProtobufUtil.timestampFromMillis(data.getCreatedTimestampMillis()));
136+
}
133137
Metrics.Metric.Builder metricBuilder = Metrics.Metric.newBuilder();
134138
addLabels(metricBuilder, data.getLabels(), scheme);
135139
metricBuilder.setCounter(counterBuilder.build());

prometheus-metrics-exposition-textformats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ public void testCounterComplete() throws IOException {
192192
+ "value: 0.8 "
193193
+ exemplar1protoString
194194
+ " "
195+
+ "created_timestamp { seconds: 1672850385 nanos: 800000000 } "
195196
+ "} "
196197
+ "timestamp_ms: 1672850685829 "
197198
+ "} "
@@ -202,6 +203,7 @@ public void testCounterComplete() throws IOException {
202203
+ "value: 0.9 "
203204
+ exemplar2protoString
204205
+ " "
206+
+ "created_timestamp { seconds: 1672850285 } "
205207
+ "} "
206208
+ "timestamp_ms: 1672850585820 "
207209
+ "}";

0 commit comments

Comments
 (0)