Skip to content

Commit e02dae2

Browse files
authored
Merge pull request #53 from cisco-open/fix/bugs/rel-21.11
Fix bugs from issues #47, #48 and #49 for Nov '21 v0.9.0 release
2 parents adb25e1 + 066c38d commit e02dae2

File tree

8 files changed

+164
-10
lines changed

8 files changed

+164
-10
lines changed

src/main/java/io/opentelemetry/contrib/generator/core/dto/EntityDefinition.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,7 @@ private void validateMandatoryFields() {
5858
}
5959

6060
private void validateAttributes() {
61-
if (MapUtils.emptyIfNull(attributes).isEmpty()) {
62-
throw new GeneratorException("At least one item must be available in 'attributes' for entity " + name);
63-
}
61+
attributes = attributes == null ? new HashMap<>() : attributes;
6462
Map<String, String> attrs = new HashMap<>();
6563
for (Map.Entry<String, String> eachAttribute: attributes.entrySet()) {
6664
if (eachAttribute.getKey().trim().length() == 0 || eachAttribute.getValue().trim().length() == 0) {

src/main/java/io/opentelemetry/contrib/generator/telemetry/cli/CLIProcessor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333

3434
import java.io.File;
3535
import java.io.IOException;
36+
import java.net.URI;
37+
import java.net.URISyntaxException;
3638

3739
@Slf4j
3840
public class CLIProcessor {
@@ -127,6 +129,11 @@ private static PayloadHandler getPayloadHandler(String targetEnvYAML) {
127129
targetEnvironmentDetails.getPassword());
128130
}
129131
if (!nonNullRestURL.isBlank()) {
132+
try {
133+
new URI(nonNullRestURL);
134+
} catch (URISyntaxException e) {
135+
log.warn("Invalid rest URL provided in environment target YAML", e);
136+
}
130137
return new RESTPayloadHandler(nonNullRestURL, authHandler);
131138
}
132139
int gRPCPort;

src/main/java/io/opentelemetry/contrib/generator/telemetry/traces/dto/Traces.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public void validate(String requestID, Set<String> allEntityTypes) {
5151
if (rootSpanNames.size() < rootSpans.size()) {
5252
throw new GeneratorException("Root span names are not unique");
5353
}
54+
childSpans = childSpans == null ? new ArrayList<>() : childSpans;
5455
Set<String> childSpanNames = childSpans.stream().map(SpanDefinition::getName).collect(Collectors.toSet());
5556
if (childSpanNames.size() < childSpans.size()) {
5657
throw new GeneratorException("Child span names are not unique");
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.opentelemetry.contrib.generator.core;
2+
3+
import io.opentelemetry.contrib.generator.telemetry.TelemetryGenerator;
4+
import io.opentelemetry.contrib.generator.telemetry.dto.GeneratorInput;
5+
import io.opentelemetry.contrib.generator.telemetry.helpers.TestPayloadHandler;
6+
import io.opentelemetry.contrib.generator.telemetry.transport.PayloadHandler;
7+
import org.testng.Assert;
8+
import org.testng.annotations.BeforeClass;
9+
import org.testng.annotations.Test;
10+
11+
import java.nio.file.Paths;
12+
13+
public class TestGeneratorsUsingEntityWithNoAttrs {
14+
15+
private final String ENTITIES_YAML = Paths.get(System.getProperty("user.dir"), "src", "test", "resources",
16+
"test-definitions", "entity-definition-noattrs.yaml").toString();
17+
private final String METRICS_YAML = Paths.get(System.getProperty("user.dir"), "src", "test", "resources",
18+
"test-definitions", "metrics-noattrsentity.yaml").toString();
19+
private final PayloadHandler payloadStore = new TestPayloadHandler();
20+
private TestPayloadHandler testStore;
21+
22+
@BeforeClass
23+
public void generateData() {
24+
GeneratorInput generatorInput = new GeneratorInput.YAMLFilesBuilder(ENTITIES_YAML)
25+
.withMetricDefinitionYAML(METRICS_YAML)
26+
.build();
27+
TelemetryGenerator telemetryGenerator = new TelemetryGenerator(generatorInput, payloadStore, true);
28+
telemetryGenerator.runGenerator();
29+
testStore = (TestPayloadHandler) payloadStore;
30+
}
31+
32+
@Test
33+
public void validatePacketCounts() {
34+
Assert.assertEquals(testStore.getMetricsPacketCount(), 1800);
35+
}
36+
}

src/test/java/io/opentelemetry/contrib/generator/telemetry/TestTracesGenerator.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import io.opentelemetry.proto.trace.v1.ScopeSpans;
2525
import io.opentelemetry.proto.trace.v1.Span;
2626
import org.testng.Assert;
27-
import org.testng.annotations.BeforeClass;
2827
import org.testng.annotations.Test;
2928

3029
import java.nio.file.Paths;
@@ -39,26 +38,27 @@ public class TestTracesGenerator {
3938

4039
private final String ENTITIES_YAML = Paths.get(System.getProperty("user.dir"), "src", "test", "resources",
4140
"test-definitions", "entities-traces-test.yaml").toString();
42-
private final String TRACES_YAML = Paths.get(System.getProperty("user.dir"), "src", "test", "resources",
43-
"test-definitions", "trace-definition.yaml").toString();
41+
private final String TEST_DEFS_PATH = Paths.get(System.getProperty("user.dir"), "src", "test", "resources",
42+
"test-definitions").toString();
43+
private final String TRACES_YAML = Paths.get(TEST_DEFS_PATH, "trace-definition.yaml").toString();
4444
private final PayloadHandler payloadStore = new TestPayloadHandler();
4545
private TestPayloadHandler testStore;
4646

47-
@BeforeClass
47+
@Test
4848
public void generateData() {
4949
GeneratorInput generatorInput = new GeneratorInput.YAMLFilesBuilder(ENTITIES_YAML).withTraceDefinitionYAML(TRACES_YAML).build();
5050
TelemetryGenerator telemetryGenerator = new TelemetryGenerator(generatorInput, payloadStore, true);
5151
telemetryGenerator.runGenerator();
5252
testStore = (TestPayloadHandler) payloadStore;
5353
}
5454

55-
@Test
55+
@Test(dependsOnMethods = "generateData")
5656
public void testResourceSpansCount() {
5757
int totalExpectedResourceSpans = 11518;
5858
Assert.assertEquals(testStore.getTracePacketCount(), totalExpectedResourceSpans, "Mismatch in resource span counts");
5959
}
6060

61-
@Test
61+
@Test(dependsOnMethods = "generateData")
6262
public void testSpanCounts() {
6363
Assert.assertNotNull(testStore.getSpanCount(), "No spans were stored in the test payload handler");
6464
Map<String, AtomicInteger> spanCounts = testStore.getSpanCount();
@@ -161,7 +161,7 @@ public void testSpanCounts() {
161161
Assert.assertEquals(spanCounts.get("searchAccountsRequest").get(), searchAccountsRequest, "Mismatch in span count for searchAccountsRequest");
162162
}
163163

164-
@Test
164+
@Test(dependsOnMethods = "generateData")
165165
public void testSpanTimes() {
166166
//Grab a single payload for the trace trees to check
167167
ExportTraceServiceRequest updateAccountTrace = null;
@@ -236,6 +236,18 @@ public void testSpanTimes() {
236236
"Mismatch in end time for deleteAccountQuery span");
237237
}
238238

239+
@Test
240+
public void testWithOnlyRootSpans() {
241+
String onlyRootSpanTraces = Paths.get(TEST_DEFS_PATH, "trace-definition-onlyrootspans.yaml").toString();
242+
GeneratorInput rootSpansGeneratorInput = new GeneratorInput.YAMLFilesBuilder(ENTITIES_YAML)
243+
.withTraceDefinitionYAML(onlyRootSpanTraces).build();
244+
PayloadHandler rootSpansStore = new TestPayloadHandler();
245+
TelemetryGenerator rootSpansTelemetryGenerator = new TelemetryGenerator(rootSpansGeneratorInput, rootSpansStore, false);
246+
rootSpansTelemetryGenerator.runGenerator();
247+
TestPayloadHandler rootSpansTestStore = (TestPayloadHandler) rootSpansStore;
248+
Assert.assertEquals(90, rootSpansTestStore.getTracePacketCount());
249+
}
250+
239251
private long[] getSpanStartTimeEndTime(ExportTraceServiceRequest trace, String spanName) {
240252
Span span = trace.getResourceSpansList().stream()
241253
.map(ResourceSpans::getScopeSpansList)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright 2022 AppDynamics Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
entities:
18+
- name: service_instance
19+
count: 150
20+
childrenDistribution:
21+
instance_endpoint: 'distribution(1, 0, 0)'
22+
attributes:
23+
service.instance.id: '"instance.id-".concat(alphanumericSequence("ceewewsdc"))'
24+
service.name: '"service.name-".concat(alphanumericSequence("ksdj3"))'
25+
service.namespace: '"service.namespace-".concat(alphanumericSequence("gnrtrvv4"))'
26+
- name: instance_endpoint
27+
count: 150
28+
attributeOperations:
29+
- 'copyFromParent("service_instance", "service.instance.id")'
30+
- 'copyFromParent("service_instance", "service.name")'
31+
- 'copyFromParent("service_instance", "service.namespace")'
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#
2+
# Copyright 2022 AppDynamics Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
payloadFrequencySeconds: 10
18+
payloadCount: 6
19+
metrics:
20+
- name: system.network.in.kb.sec
21+
unit: kBy/s
22+
otelType: summary
23+
valueFunction: 'absoluteCosineSequenceSummary("*7000", 5)'
24+
isDouble: true
25+
quantiles: [0, 50, 100]
26+
reportingEntities: [service_instance, instance_endpoint]
27+
attributes:
28+
system.internal.ip: 'IPv4Sequence("10.134.1.34")'
29+
- name: system.network.out.kb.sec
30+
unit: kBy/s
31+
otelType: summary
32+
valueFunction: 'randomSummary(1, 10, "*400", 7)'
33+
isDouble: true
34+
quantiles: [0, 50, 100]
35+
reportingEntities: [service_instance, instance_endpoint]
36+
attributes:
37+
system.internal.ip: 'IPv4Sequence("10.121.17.65")'
38+
network.device.type: 'roundRobin(["ethernet", "wired", "wireless"])'
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright 2022 AppDynamics Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
17+
traceCompletionTimeoutSecs: 120
18+
rootSpans:
19+
- name: "healthCheck"
20+
spanKind: SPAN_KIND_SERVER
21+
reportingResource: http_backend
22+
attributes:
23+
type: 'roundRobin(["REST"])'
24+
url: 'roundRobin(["/healthcheck"])'
25+
payloadCount: 5
26+
payloadFrequencySeconds: 15
27+
- name: "getAccountDetails"
28+
spanKind: SPAN_KIND_SERVER
29+
reportingResource: request
30+
payloadCount: 5
31+
copyCount: 17

0 commit comments

Comments
 (0)