Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ private void run() throws NoSuchFieldException, IllegalAccessException {
histogram.observe(observation);
}
}
Metrics.MetricFamily protobufData =
Metrics.MetricFamily.Builder protobufData =
new PrometheusProtobufWriterImpl()
.convert(histogram.collect(), EscapingScheme.ALLOW_UTF8);
.convert(histogram.collect(), EscapingScheme.ALLOW_UTF8).toBuilder();
// The client_golang test cases don't include the created timestamp.
assertThat(protobufData.getMetric(0).getHistogram().hasCreatedTimestamp()).isTrue();
protobufData.getMetricBuilder(0).getHistogramBuilder().clearCreatedTimestamp();
String expectedWithMetadata =
"name: \"test\" type: HISTOGRAM metric { histogram { " + expected + " } }";
assertThat(ProtobufUtil.shortDebugString(protobufData))
Expand Down Expand Up @@ -978,8 +981,11 @@ void testDefaults() throws IOException {
""";

// protobuf
Metrics.MetricFamily protobufData =
new PrometheusProtobufWriterImpl().convert(snapshot, EscapingScheme.ALLOW_UTF8);
Metrics.MetricFamily.Builder protobufData =
new PrometheusProtobufWriterImpl().convert(snapshot, EscapingScheme.ALLOW_UTF8).toBuilder();
assertThat(protobufData.getMetric(0).getHistogram().getCreatedTimestamp().getSeconds())
.isEqualTo(snapshot.getDataPoints().get(0).getCreatedTimestampMillis() / 1000);
protobufData.getMetricBuilder(0).getHistogramBuilder().clearCreatedTimestamp();
assertThat(ProtobufUtil.shortDebugString(protobufData)).isEqualTo(expectedProtobuf);

// text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ private Metrics.Metric.Builder convert(
if (data.hasSum()) {
histogramBuilder.setSampleSum(data.getSum());
}
if (data.hasCreatedTimestamp()) {
histogramBuilder.setCreatedTimestamp(
ProtobufUtil.timestampFromMillis(data.getCreatedTimestampMillis()));
}
metricBuilder.setHistogram(histogramBuilder.build());
return metricBuilder;
}
Expand All @@ -241,6 +245,10 @@ private Metrics.Metric.Builder convert(
.setValue(quantiles.get(i).getValue())
.build());
}
if (data.hasCreatedTimestamp()) {
summaryBuilder.setCreatedTimestamp(
ProtobufUtil.timestampFromMillis(data.getCreatedTimestampMillis()));
}
Metrics.Metric.Builder metricBuilder = Metrics.Metric.newBuilder();
addLabels(metricBuilder, data.getLabels(), scheme);
metricBuilder.setSummary(summaryBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ void testSummaryComplete() throws IOException {
+ "quantile { quantile: 0.5 value: 225.3 } "
+ "quantile { quantile: 0.9 value: 240.7 } "
+ "quantile { quantile: 0.95 value: 245.1 } "
+ "created_timestamp { seconds: 1672850385 nanos: 800000000 } "
+ "} "
+ "timestamp_ms: 1672850685829 "
+ "} metric { "
Expand All @@ -1024,6 +1025,7 @@ void testSummaryComplete() throws IOException {
+ "quantile { quantile: 0.5 value: 225.3 } "
+ "quantile { quantile: 0.9 value: 240.7 } "
+ "quantile { quantile: 0.95 value: 245.1 } "
+ "created_timestamp { seconds: 1672850285 } "
+ "} "
+ "timestamp_ms: 1672850585820 "
+ "}";
Expand Down Expand Up @@ -1587,6 +1589,7 @@ void testClassicHistogramComplete() throws Exception {
+ exemplar2protoString
+ " "
+ "} "
+ "created_timestamp { seconds: 1672850385 nanos: 800000000 } "
+ "} "
+ "} metric { "
+ "label { name: \"status\" value: \"500\" } "
Expand All @@ -1608,6 +1611,7 @@ void testClassicHistogramComplete() throws Exception {
+ exemplar2protoString
+ " "
+ "} "
+ "created_timestamp { seconds: 1672850285 } "
+ "} "
+ "}";
// @formatter:on
Expand Down Expand Up @@ -2016,6 +2020,7 @@ void testClassicGaugeHistogramComplete() throws IOException {
+ exemplar2protoString
+ " "
+ "} "
+ "created_timestamp { seconds: 1672850385 nanos: 800000000 } "
+ "} "
+ "} metric { "
+ "label { name: \"db\" value: \"options\" } "
Expand All @@ -2034,6 +2039,7 @@ void testClassicGaugeHistogramComplete() throws IOException {
+ exemplar2protoString
+ " "
+ "} "
+ "created_timestamp { seconds: 1672850285 } "
+ "} "
+ "}";
// @formatter:on
Expand Down Expand Up @@ -2435,6 +2441,7 @@ void testNativeHistogramComplete() throws IOException {
+ "zero_count: 0 "
+ "positive_span { offset: 0 length: 1 } "
+ "positive_delta: 2 "
+ "created_timestamp { seconds: 1672850385 nanos: 800000000 } "
+ "} "
+ "} metric { "
+ "label { name: \"status\" value: \"500\" } "
Expand Down Expand Up @@ -2500,7 +2507,8 @@ void testNativeHistogramComplete() throws IOException {
+ // index 46, count 2
"positive_delta: -1 "
+ // index 47, count 1
"} "
"created_timestamp { seconds: 1672850285 } "
+ "} "
+ "}";
// @formatter:on
HistogramSnapshot nativeHistogram =
Expand Down