|
5 | 5 |
|
6 | 6 | package io.opentelemetry.instrumentation.docs.utils;
|
7 | 7 |
|
| 8 | +import static java.util.Collections.emptyList; |
8 | 9 | import static org.assertj.core.api.Assertions.assertThat;
|
9 | 10 |
|
10 | 11 | import com.fasterxml.jackson.core.JsonProcessingException;
|
|
22 | 23 | import java.util.ArrayList;
|
23 | 24 | import java.util.HashMap;
|
24 | 25 | import java.util.HashSet;
|
| 26 | +import java.util.LinkedHashMap; |
25 | 27 | import java.util.List;
|
26 | 28 | import java.util.Map;
|
27 | 29 | import java.util.Set;
|
@@ -420,4 +422,67 @@ void testSpanParsing() throws Exception {
|
420 | 422 |
|
421 | 423 | assertThat(expectedYaml).isEqualTo(stringWriter.toString());
|
422 | 424 | }
|
| 425 | + |
| 426 | + @Test |
| 427 | + void testTelemetryGroupsAreSorted() throws Exception { |
| 428 | + EmittedMetrics.Metric metric = |
| 429 | + new EmittedMetrics.Metric("a.metric", "description", "COUNTER", "1", emptyList()); |
| 430 | + EmittedSpans.Span span = new EmittedSpans.Span("SERVER", emptyList()); |
| 431 | + |
| 432 | + // First ordering |
| 433 | + Map<String, List<EmittedMetrics.Metric>> metrics1 = new LinkedHashMap<>(); |
| 434 | + metrics1.put("z-group", List.of(metric)); |
| 435 | + metrics1.put("a-group", List.of(metric)); |
| 436 | + |
| 437 | + Map<String, List<EmittedSpans.Span>> spans1 = new LinkedHashMap<>(); |
| 438 | + spans1.put("c-group", List.of(span)); |
| 439 | + spans1.put("f-group", List.of(span)); |
| 440 | + spans1.put("b-group", List.of(span)); |
| 441 | + |
| 442 | + List<InstrumentationModule> modules1 = new ArrayList<>(); |
| 443 | + modules1.add( |
| 444 | + new InstrumentationModule.Builder() |
| 445 | + .srcPath("instrumentation/test/test-1.0") |
| 446 | + .instrumentationName("test-1.0") |
| 447 | + .namespace("test") |
| 448 | + .group("test") |
| 449 | + .metrics(metrics1) |
| 450 | + .spans(spans1) |
| 451 | + .build()); |
| 452 | + |
| 453 | + StringWriter stringWriter1 = new StringWriter(); |
| 454 | + BufferedWriter writer1 = new BufferedWriter(stringWriter1); |
| 455 | + YamlHelper.generateInstrumentationYaml(modules1, writer1); |
| 456 | + writer1.flush(); |
| 457 | + String yaml1 = stringWriter1.toString(); |
| 458 | + |
| 459 | + // Different ordering |
| 460 | + Map<String, List<EmittedMetrics.Metric>> metrics2 = new LinkedHashMap<>(); |
| 461 | + metrics2.put("a-group", List.of(metric)); |
| 462 | + metrics2.put("z-group", List.of(metric)); |
| 463 | + |
| 464 | + Map<String, List<EmittedSpans.Span>> spans2 = new LinkedHashMap<>(); |
| 465 | + spans2.put("f-group", List.of(span)); |
| 466 | + spans2.put("b-group", List.of(span)); |
| 467 | + spans2.put("c-group", List.of(span)); |
| 468 | + |
| 469 | + List<InstrumentationModule> modules2 = new ArrayList<>(); |
| 470 | + modules2.add( |
| 471 | + new InstrumentationModule.Builder() |
| 472 | + .srcPath("instrumentation/test/test-1.0") |
| 473 | + .instrumentationName("test-1.0") |
| 474 | + .namespace("test") |
| 475 | + .group("test") |
| 476 | + .metrics(metrics2) |
| 477 | + .spans(spans2) |
| 478 | + .build()); |
| 479 | + |
| 480 | + StringWriter stringWriter2 = new StringWriter(); |
| 481 | + BufferedWriter writer2 = new BufferedWriter(stringWriter2); |
| 482 | + YamlHelper.generateInstrumentationYaml(modules2, writer2); |
| 483 | + writer2.flush(); |
| 484 | + String yaml2 = stringWriter2.toString(); |
| 485 | + |
| 486 | + assertThat(yaml1).isEqualTo(yaml2); |
| 487 | + } |
423 | 488 | }
|
0 commit comments