|
7 | 7 |
|
8 | 8 | package org.elasticsearch.xpack.oteldata.otlp.docbuilder; |
9 | 9 |
|
| 10 | +import com.google.protobuf.ByteString; |
10 | 11 | import io.opentelemetry.proto.common.v1.InstrumentationScope; |
11 | 12 | import io.opentelemetry.proto.common.v1.KeyValue; |
12 | 13 | import io.opentelemetry.proto.metrics.v1.AggregationTemporality; |
| 14 | +import io.opentelemetry.proto.metrics.v1.Metric; |
13 | 15 | import io.opentelemetry.proto.metrics.v1.NumberDataPoint; |
| 16 | +import io.opentelemetry.proto.metrics.v1.SummaryDataPoint; |
14 | 17 | import io.opentelemetry.proto.resource.v1.Resource; |
15 | | - |
16 | | -import com.google.protobuf.ByteString; |
17 | | - |
18 | 18 | import org.elasticsearch.common.bytes.BytesReference; |
19 | 19 | import org.elasticsearch.test.ESTestCase; |
20 | 20 | import org.elasticsearch.test.rest.ObjectPath; |
|
36 | 36 | import static org.elasticsearch.xpack.oteldata.otlp.OtlpUtils.createGaugeMetric; |
37 | 37 | import static org.elasticsearch.xpack.oteldata.otlp.OtlpUtils.createLongDataPoint; |
38 | 38 | import static org.elasticsearch.xpack.oteldata.otlp.OtlpUtils.createSumMetric; |
| 39 | +import static org.elasticsearch.xpack.oteldata.otlp.OtlpUtils.createSummaryMetric; |
39 | 40 | import static org.elasticsearch.xpack.oteldata.otlp.OtlpUtils.keyValue; |
40 | 41 | import static org.hamcrest.Matchers.equalTo; |
41 | 42 | import static org.hamcrest.Matchers.hasEntry; |
@@ -191,4 +192,36 @@ public void testEmptyFields() throws IOException { |
191 | 192 | assertThat(doc.evaluate("unit"), is(nullValue())); |
192 | 193 | } |
193 | 194 |
|
| 195 | + public void testSummary() throws Exception { |
| 196 | + Resource resource = Resource.newBuilder().build(); |
| 197 | + InstrumentationScope scope = InstrumentationScope.newBuilder().build(); |
| 198 | + |
| 199 | + SummaryDataPoint dataPoint = SummaryDataPoint.newBuilder() |
| 200 | + .setTimeUnixNano(timestamp) |
| 201 | + .setStartTimeUnixNano(startTimestamp) |
| 202 | + .setCount(1) |
| 203 | + .setSum(42.0) |
| 204 | + .build(); |
| 205 | + Metric metric = createSummaryMetric("summary", "", List.of()); |
| 206 | + List<DataPoint> dataPoints = List.of(new DataPoint.Summary(dataPoint, metric)); |
| 207 | + |
| 208 | + DataPointGroupingContext.DataPointGroup dataPointGroup = new DataPointGroupingContext.DataPointGroup( |
| 209 | + resource, |
| 210 | + null, |
| 211 | + scope, |
| 212 | + null, |
| 213 | + List.of(), |
| 214 | + "", |
| 215 | + dataPoints, |
| 216 | + "metrics-generic.otel-default" |
| 217 | + ); |
| 218 | + |
| 219 | + XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON); |
| 220 | + HashMap<String, String> dynamicTemplates = documentBuilder.buildMetricDocument(builder, dataPointGroup); |
| 221 | + |
| 222 | + ObjectPath doc = ObjectPath.createFromXContent(JsonXContent.jsonXContent, BytesReference.bytes(builder)); |
| 223 | + assertThat(doc.evaluate("metrics.summary.sum"), equalTo(42.0)); |
| 224 | + assertThat(doc.evaluate("metrics.summary.value_count"), equalTo(1)); |
| 225 | + assertThat(dynamicTemplates, hasEntry("metrics.summary", "summary")); |
| 226 | + } |
194 | 227 | } |
0 commit comments