|
| 1 | +package io.opentelemetry.contrib.generator.telemetry; |
| 2 | + |
| 3 | +import io.opentelemetry.contrib.generator.telemetry.dto.GeneratorInput; |
| 4 | +import io.opentelemetry.contrib.generator.telemetry.helpers.TestPayloadHandler; |
| 5 | +import io.opentelemetry.contrib.generator.telemetry.transport.PayloadHandler; |
| 6 | +import io.opentelemetry.contrib.generator.telemetry.transport.TransportStorage; |
| 7 | +import io.opentelemetry.proto.collector.logs.v1.ExportLogsServiceRequest; |
| 8 | +import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest; |
| 9 | +import org.testng.Assert; |
| 10 | +import org.testng.annotations.BeforeClass; |
| 11 | +import org.testng.annotations.Test; |
| 12 | + |
| 13 | +import java.nio.file.Paths; |
| 14 | +import java.util.HashMap; |
| 15 | +import java.util.List; |
| 16 | +import java.util.Map; |
| 17 | +import java.util.Set; |
| 18 | + |
| 19 | +public class TestAllGeneratorsWithJSONInput { |
| 20 | + private final String ENTITIES_JSON = Paths.get(System.getProperty("user.dir"), "src", "test", "resources", |
| 21 | + "test-definitions", "entity-definition.json").toString(); |
| 22 | + private final String METRICS_JSON = Paths.get(System.getProperty("user.dir"), "src", "test", "resources", |
| 23 | + "test-definitions", "metrics-test.json").toString(); |
| 24 | + private final String LOGS_JSON = Paths.get(System.getProperty("user.dir"), "src", "test", "resources", |
| 25 | + "test-definitions", "logs-test-combined.json").toString(); |
| 26 | + private final String TRACES_JSON = Paths.get(System.getProperty("user.dir"), "src", "test", "resources", |
| 27 | + "test-definitions", "trace-definition.json").toString(); |
| 28 | + private final PayloadHandler payloadStore = new TestPayloadHandler(); |
| 29 | + private TestPayloadHandler testStore; |
| 30 | + private TransportStorage transportStorage; |
| 31 | + |
| 32 | + @BeforeClass |
| 33 | + public void generateData() { |
| 34 | + GeneratorInput generatorInput = new GeneratorInput.JSONFilesBuilder(ENTITIES_JSON) |
| 35 | + .withMetricDefinitionYAML(METRICS_JSON) |
| 36 | + .withLogDefinitionYAML(LOGS_JSON) |
| 37 | + .withTraceDefinitionYAML(TRACES_JSON) |
| 38 | + .build(); |
| 39 | + TelemetryGenerator telemetryGenerator = new TelemetryGenerator(generatorInput, payloadStore, true); |
| 40 | + telemetryGenerator.runGenerator(); |
| 41 | + testStore = (TestPayloadHandler) payloadStore; |
| 42 | + transportStorage = telemetryGenerator.getTransportStorage(); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void validatePacketCounts() { |
| 47 | + int NETWORK_INTERFACE_COUNT = 120; |
| 48 | + int CONTAINER_COUNT = 150; |
| 49 | + int MACHINE_COUNT = 80; |
| 50 | + int NODE_COUNT = 25; |
| 51 | + int POD_COUNT = 75; |
| 52 | + int DISK_COUNT = 100; |
| 53 | + int AWS_RDS_COUNT = 50; |
| 54 | + int AWS_EBS_COUNT = 50; |
| 55 | + int METRIC_REPORTING_ENTITIES_COUNT = NETWORK_INTERFACE_COUNT + CONTAINER_COUNT + MACHINE_COUNT + NODE_COUNT + |
| 56 | + POD_COUNT + DISK_COUNT + AWS_EBS_COUNT + AWS_RDS_COUNT; |
| 57 | + int LOG_REPORTING_ENTITIES_COUNT = CONTAINER_COUNT + NODE_COUNT + 2 * POD_COUNT + MACHINE_COUNT; |
| 58 | + int metricPayloadCount = 10; |
| 59 | + int logsPayloadCount = 20; |
| 60 | + int expectedMetricPackets = METRIC_REPORTING_ENTITIES_COUNT * metricPayloadCount; |
| 61 | + int expectedLogsPackets = LOG_REPORTING_ENTITIES_COUNT * logsPayloadCount; |
| 62 | + int expectedSpanPackets = 11518; |
| 63 | + Assert.assertEquals(testStore.getMetricsPacketCount(), expectedMetricPackets, "Mismatch in expected metric packets count"); |
| 64 | + Assert.assertEquals(testStore.getLogsPacketCount(), expectedLogsPackets, "Mismatch in expected log packets count"); |
| 65 | + Assert.assertEquals(testStore.getTracePacketCount(), expectedSpanPackets, "Mismatch in expected span packets count"); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void validateStorageCounts() { |
| 70 | + Assert.assertEquals(transportStorage.getStoredMetricsPayloads().size(), 8, |
| 71 | + "Mismatch in entity type counts for metric payloads"); |
| 72 | + Assert.assertEquals(transportStorage.getStoredLogsPayloads().size(), 3, |
| 73 | + "Mismatch in entity type counts for log payloads"); |
| 74 | + Assert.assertEquals(transportStorage.getStoredLogsPayloads().get("log_by_ttg_0").size(), 3, |
| 75 | + "Mismatch in entity type counts for log payloads"); |
| 76 | + Assert.assertEquals(transportStorage.getStoredLogsPayloads().get("log_by_ttg_0").get("pod").size(), 20, |
| 77 | + "Mismatch in entity type counts for log payloads"); |
| 78 | + Assert.assertEquals(transportStorage.getStoredTracesPayloads().size(), 8, |
| 79 | + "Mismatch in entity type counts for trace payloads"); |
| 80 | + Assert.assertEquals(transportStorage.getMetricsResponses().size(), 8, |
| 81 | + "Mismatch in entity type counts for metric response statuses"); |
| 82 | + Assert.assertEquals(transportStorage.getLogsResponses().size(), 3, |
| 83 | + "Mismatch in entity type counts for log response statuses"); |
| 84 | + Assert.assertEquals(transportStorage.getTracesResponses().size(), 8, |
| 85 | + "Mismatch in entity type counts for trace response statuses"); |
| 86 | + for (Map.Entry<String, List<ExportMetricsServiceRequest>> metricCounts: transportStorage.getStoredMetricsPayloads().entrySet()) { |
| 87 | + Assert.assertEquals(metricCounts.getValue().size(), 10, "Expected 10 metric payloads for entity type: " + |
| 88 | + metricCounts.getKey()); |
| 89 | + Assert.assertEquals(transportStorage.getMetricsResponses().get(metricCounts.getKey()).size(), 10, |
| 90 | + "Expected 10 metric response statuses for entity type: " + metricCounts.getKey()); |
| 91 | + } |
| 92 | + |
| 93 | + for (Map.Entry<String, Map<String, List<ExportLogsServiceRequest>>> logCounts: transportStorage.getStoredLogsPayloads().entrySet()) { |
| 94 | + Set<String> entityNames = logCounts.getValue().keySet(); |
| 95 | + for(String name : entityNames){ |
| 96 | + Assert.assertEquals(logCounts.getValue().get(name).size(), 20, "Expected 20 log payloads for entity type: " + |
| 97 | + logCounts.getKey()); |
| 98 | + Assert.assertEquals(transportStorage.getLogsResponses().get(logCounts.getKey()).get(name).size(), 20, |
| 99 | + "Expected 20 log response statuses for " + "log:entity key: " + logCounts.getKey()); |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + Map<String, Integer> expectedTracePayloads = new HashMap<>(); |
| 104 | + expectedTracePayloads.put("healthCheck::group::0", 10); |
| 105 | + expectedTracePayloads.put("searchAccountsRequest::group::0", 5); |
| 106 | + expectedTracePayloads.put("getAccountDetails::group::0", 10); |
| 107 | + expectedTracePayloads.put("getAccountDetails::group::1", 10); |
| 108 | + expectedTracePayloads.put("updateAccountDetails::group::0", 7); |
| 109 | + expectedTracePayloads.put("deleteAccount::group::0", 5); |
| 110 | + expectedTracePayloads.put("createNewAccount::group::0", 20); |
| 111 | + expectedTracePayloads.put("createNewAccount::group::1", 20); |
| 112 | + for (Map.Entry<String, Integer> eachTraceGroup: expectedTracePayloads.entrySet()) { |
| 113 | + Assert.assertEquals(transportStorage.getStoredTracesPayloads().get(eachTraceGroup.getKey()).size(), eachTraceGroup.getValue(), |
| 114 | + "Mismatch in expected payloads count for trace group " + eachTraceGroup.getKey()); |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments