75
75
import java .util .concurrent .TimeUnit ;
76
76
77
77
import static io .opentelemetry .api .common .AttributeKey .stringKey ;
78
+ import static io .opentelemetry .sdk .metrics .data .AggregationTemporality .CUMULATIVE ;
79
+ import static io .opentelemetry .sdk .metrics .data .AggregationTemporality .DELTA ;
78
80
import static org .elasticsearch .test .hamcrest .ElasticsearchAssertions .assertResponse ;
79
81
import static org .hamcrest .Matchers .aMapWithSize ;
80
82
import static org .hamcrest .Matchers .anEmptyMap ;
@@ -286,7 +288,7 @@ public void testGroupingDifferentGroup() throws Exception {
286
288
287
289
public void testTimeSeriesMetrics () throws Exception {
288
290
long now = Clock .getDefault ().now ();
289
- MetricData metric1 = createCounter (TEST_RESOURCE , Attributes .empty (), "counter" , 42 , "By" , now );
291
+ MetricData metric1 = createCounter (TEST_RESOURCE , Attributes .empty (), "counter" , 42 , "By" , now , CUMULATIVE );
290
292
MetricData metric2 = createDoubleGauge (TEST_RESOURCE , Attributes .empty (), "gauge" , 42 , "By" , now );
291
293
export (List .of (metric1 , metric2 ));
292
294
@@ -303,9 +305,30 @@ public void testTimeSeriesMetrics() throws Exception {
303
305
});
304
306
}
305
307
308
+ public void testCounterTemporality () throws Exception {
309
+ long now = Clock .getDefault ().now ();
310
+ export (
311
+ List .of (
312
+ createCounter (TEST_RESOURCE , Attributes .empty (), "cumulative_counter" , 42 , "By" , now , CUMULATIVE ),
313
+ createCounter (TEST_RESOURCE , Attributes .empty (), "delta_counter" , 42 , "By" , now , DELTA )
314
+ )
315
+ );
316
+
317
+ assertResponse (client ().admin ().indices ().prepareGetMappings (TEST_REQUEST_TIMEOUT , "metrics-generic.otel-default" ), resp -> {
318
+ Map <String , MappingMetadata > mappings = resp .getMappings ();
319
+ assertThat (mappings , aMapWithSize (1 ));
320
+ Map <String , Object > mapping = mappings .values ().iterator ().next ().getSourceAsMap ();
321
+ assertThat (mapping , not (anEmptyMap ()));
322
+ assertThat (evaluate (mapping , "properties.metrics.properties.cumulative_counter.type" ), equalTo ("long" ));
323
+ assertThat (evaluate (mapping , "properties.metrics.properties.cumulative_counter.time_series_metric" ), equalTo ("counter" ));
324
+ assertThat (evaluate (mapping , "properties.metrics.properties.delta_counter.type" ), equalTo ("long" ));
325
+ assertThat (evaluate (mapping , "properties.metrics.properties.delta_counter.time_series_metric" ), equalTo ("gauge" ));
326
+ });
327
+ }
328
+
306
329
public void testExponentialHistograms () throws Exception {
307
330
long now = Clock .getDefault ().now ();
308
- export (List .of (createExponentialHistogram (now , "exponential_histogram" , AggregationTemporality . DELTA , Attributes .empty ())));
331
+ export (List .of (createExponentialHistogram (now , "exponential_histogram" , DELTA , Attributes .empty ())));
309
332
310
333
assertResponse (client ().admin ().indices ().prepareGetMappings (TEST_REQUEST_TIMEOUT , "metrics-generic.otel-default" ), resp -> {
311
334
Map <String , MappingMetadata > mappings = resp .getMappings ();
@@ -334,7 +357,7 @@ public void testExponentialHistogramsAsAggregateMetricDouble() throws Exception
334
357
createExponentialHistogram (
335
358
now ,
336
359
"exponential_histogram_summary" ,
337
- AggregationTemporality . DELTA ,
360
+ DELTA ,
338
361
Attributes .of (
339
362
AttributeKey .stringArrayKey ("elasticsearch.mapping.hints" ),
340
363
List .of ("aggregate_metric_double" , "_doc_count" )
@@ -364,7 +387,7 @@ public void testExponentialHistogramsAsAggregateMetricDouble() throws Exception
364
387
365
388
public void testHistogram () throws Exception {
366
389
long now = Clock .getDefault ().now ();
367
- export (List .of (createHistogram (now , "histogram" , AggregationTemporality . DELTA , Attributes .empty ())));
390
+ export (List .of (createHistogram (now , "histogram" , DELTA , Attributes .empty ())));
368
391
369
392
assertResponse (client ().admin ().indices ().prepareGetMappings (TEST_REQUEST_TIMEOUT , "metrics-generic.otel-default" ), resp -> {
370
393
Map <String , MappingMetadata > mappings = resp .getMappings ();
@@ -391,7 +414,7 @@ public void testHistogramAsAggregateMetricDouble() throws Exception {
391
414
createHistogram (
392
415
now ,
393
416
"histogram_summary" ,
394
- AggregationTemporality . DELTA ,
417
+ DELTA ,
395
418
Attributes .of (
396
419
AttributeKey .stringArrayKey ("elasticsearch.mapping.hints" ),
397
420
List .of ("aggregate_metric_double" , "_doc_count" )
@@ -422,8 +445,8 @@ public void testCumulativeHistograms() {
422
445
RuntimeException .class ,
423
446
() -> export (
424
447
List .of (
425
- createExponentialHistogram (now , "exponential_histogram" , AggregationTemporality . CUMULATIVE , Attributes .empty ()),
426
- createHistogram (now , "histogram" , AggregationTemporality . CUMULATIVE , Attributes .empty ())
448
+ createExponentialHistogram (now , "exponential_histogram" , CUMULATIVE , Attributes .empty ()),
449
+ createHistogram (now , "histogram" , CUMULATIVE , Attributes .empty ())
427
450
)
428
451
)
429
452
);
@@ -509,7 +532,8 @@ private static MetricData createCounter(
509
532
String name ,
510
533
long value ,
511
534
String unit ,
512
- long timeEpochNanos
535
+ long timeEpochNanos ,
536
+ AggregationTemporality temporality
513
537
) {
514
538
return ImmutableMetricData .createLongSum (
515
539
resource ,
@@ -519,7 +543,7 @@ private static MetricData createCounter(
519
543
unit ,
520
544
ImmutableSumData .create (
521
545
true ,
522
- AggregationTemporality . CUMULATIVE ,
546
+ temporality ,
523
547
List .of (ImmutableLongPointData .create (timeEpochNanos , timeEpochNanos , attributes , value ))
524
548
)
525
549
);
0 commit comments