1010import io .opentelemetry .proto .common .v1 .InstrumentationScope ;
1111import io .opentelemetry .proto .common .v1 .KeyValue ;
1212import io .opentelemetry .proto .metrics .v1 .AggregationTemporality ;
13- import io .opentelemetry .proto .metrics .v1 .NumberDataPoint ;
1413import io .opentelemetry .proto .resource .v1 .Resource ;
1514
1615import com .google .protobuf .ByteString ;
3029import java .util .ArrayList ;
3130import java .util .HashMap ;
3231import java .util .List ;
32+ import java .util .Set ;
3333import java .util .concurrent .TimeUnit ;
3434
3535import static org .elasticsearch .xpack .oteldata .otlp .OtlpUtils .createDoubleDataPoint ;
@@ -66,11 +66,24 @@ public void testBuildMetricDocument() throws IOException {
6666
6767 List <KeyValue > dataPointAttributes = List .of (keyValue ("operation" , "test" ), (keyValue ("environment" , "production" )));
6868
69- List <DataPoint > dataPoints = List .of (
69+ DataPointGroupingContext .DataPointGroup dataPointGroup = new DataPointGroupingContext .DataPointGroup (
70+ resource ,
71+ resourceSchemaUrl ,
72+ scope ,
73+ scopeSchemaUrl ,
74+ dataPointAttributes ,
75+ "{test}" ,
76+ "metrics-generic.otel-default"
77+ );
78+ dataPointGroup .addDataPoint (
79+ Set .of (),
7080 new DataPoint .Number (
7181 createDoubleDataPoint (timestamp , startTimestamp , dataPointAttributes ),
7282 createGaugeMetric ("system.cpu.usage" , "" , List .of ())
73- ),
83+ )
84+ );
85+ dataPointGroup .addDataPoint (
86+ Set .of (),
7487 new DataPoint .Number (
7588 createLongDataPoint (timestamp , startTimestamp , dataPointAttributes ),
7689 createSumMetric (
@@ -82,16 +95,6 @@ public void testBuildMetricDocument() throws IOException {
8295 )
8396 )
8497 );
85- DataPointGroupingContext .DataPointGroup dataPointGroup = new DataPointGroupingContext .DataPointGroup (
86- resource ,
87- resourceSchemaUrl ,
88- scope ,
89- scopeSchemaUrl ,
90- dataPointAttributes ,
91- "{test}" ,
92- dataPoints ,
93- "metrics-generic.otel-default"
94- );
9598
9699 XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
97100 HashMap <String , String > dynamicTemplates = documentBuilder .buildMetricDocument (builder , dataPointGroup );
@@ -129,20 +132,19 @@ public void testAttributeTypes() throws IOException {
129132 Resource resource = Resource .newBuilder ().addAllAttributes (resourceAttributes ).build ();
130133 InstrumentationScope scope = InstrumentationScope .newBuilder ().build ();
131134
132- List <DataPoint > dataPoints = List .of (
133- new DataPoint .Number (createDoubleDataPoint (timestamp ), createGaugeMetric ("test.metric" , "" , List .of ()))
134- );
135-
136135 DataPointGroupingContext .DataPointGroup dataPointGroup = new DataPointGroupingContext .DataPointGroup (
137136 resource ,
138137 null ,
139138 scope ,
140139 null ,
141140 List .of (),
142141 "" ,
143- dataPoints ,
144142 "metrics-generic.otel-default"
145143 );
144+ dataPointGroup .addDataPoint (
145+ Set .of (),
146+ new DataPoint .Number (createDoubleDataPoint (timestamp ), createGaugeMetric ("test.metric" , "" , List .of ()))
147+ );
146148
147149 XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
148150 documentBuilder .buildMetricDocument (builder , dataPointGroup );
@@ -162,21 +164,21 @@ public void testEmptyFields() throws IOException {
162164 Resource resource = Resource .newBuilder ().build ();
163165 InstrumentationScope scope = InstrumentationScope .newBuilder ().build ();
164166
165- NumberDataPoint dataPoint = createDoubleDataPoint (timestamp );
166- var metric = createGaugeMetric ("test.metric" , "" , List .of (dataPoint ));
167- List <DataPoint > dataPoints = List .of (new DataPoint .Number (dataPoint , metric ));
168-
169167 DataPointGroupingContext .DataPointGroup dataPointGroup = new DataPointGroupingContext .DataPointGroup (
170168 resource ,
171169 null ,
172170 scope ,
173171 null ,
174172 List .of (),
175173 "" ,
176- dataPoints ,
177174 "metrics-generic.otel-default"
178175 );
179176
177+ dataPointGroup .addDataPoint (
178+ Set .of (),
179+ new DataPoint .Number (createDoubleDataPoint (timestamp ), createGaugeMetric ("test.metric" , "" , List .of ()))
180+ );
181+
180182 XContentBuilder builder = XContentFactory .contentBuilder (XContentType .JSON );
181183 documentBuilder .buildMetricDocument (builder , dataPointGroup );
182184
0 commit comments