From 9860a0b286b23936f9f3069fae721dabe6276917 Mon Sep 17 00:00:00 2001 From: Chen <19492223+chenqi0805@users.noreply.github.com> Date: Fri, 4 Feb 2022 21:20:44 -0600 Subject: [PATCH 1/8] MAINT: fixed client trace ingestion simulation Signed-off-by: Chen <19492223+chenqi0805@users.noreply.github.com> --- performance-test/build.gradle | 3 + .../FixedClientTraceSimulation.java | 35 ++++++ .../test/performance/tools/TraceChain.java | 30 +++++ .../performance/tools/TraceTemplates.java | 118 ++++++++++++++++++ 4 files changed, 186 insertions(+) create mode 100644 performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/FixedClientTraceSimulation.java create mode 100644 performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceChain.java create mode 100644 performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java diff --git a/performance-test/build.gradle b/performance-test/build.gradle index 65149c9b2c..7b508fe869 100644 --- a/performance-test/build.gradle +++ b/performance-test/build.gradle @@ -15,6 +15,9 @@ repositories { } dependencies { + gatling "io.opentelemetry:opentelemetry-proto:${versionMap.opentelemetryProto}" + gatling "org.apache.commons:commons-lang3:3.12.0" + gatling 'com.google.protobuf:protobuf-java-util:3.19.1' implementation 'com.fasterxml.jackson.core:jackson-core:2.13.0' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2' diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/FixedClientTraceSimulation.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/FixedClientTraceSimulation.java new file mode 100644 index 0000000000..ecc274f1b6 --- /dev/null +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/FixedClientTraceSimulation.java @@ -0,0 +1,35 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.dataprepper.test.performance; + +import io.gatling.javaapi.core.CoreDsl; +import io.gatling.javaapi.core.ScenarioBuilder; +import io.gatling.javaapi.core.Simulation; +import io.gatling.javaapi.http.HttpDsl; +import org.opensearch.dataprepper.test.performance.tools.TraceChain; + +import java.time.Duration; +import java.util.Arrays; +import java.util.List; + +public class FixedClientTraceSimulation extends Simulation { + private static final Integer batchSize = Integer.getInteger("batchSize", 20); + private static final Integer users = Integer.getInteger("users", 10); + private static final Duration duration = Duration.ofMinutes(Long.getLong("duration", 5)); + private static final List endpoints = Arrays.asList(System.getProperty("endpoints").split(",")); + + ScenarioBuilder fixedScenario = CoreDsl.scenario("Slow Burn") + .during(duration) + .on(TraceChain.sendUnframedExportTraceServiceRequest(endpoints, batchSize)); + + { + setUp(fixedScenario.injectOpen(CoreDsl.atOnceUsers(users))) + .protocols(HttpDsl.http + .acceptHeader("application/json") + .header("Content-Type", "application/json; charset=utf-8")) + .assertions(CoreDsl.global().requestsPerSec().gt(140.0)); + } +} diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceChain.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceChain.java new file mode 100644 index 0000000000..1000077ba1 --- /dev/null +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceChain.java @@ -0,0 +1,30 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.dataprepper.test.performance.tools; + +import io.gatling.javaapi.core.ChainBuilder; +import io.gatling.javaapi.core.CoreDsl; +import io.gatling.javaapi.core.Session; +import io.gatling.javaapi.http.HttpDsl; + +import java.util.List; +import java.util.function.Function; + +public class TraceChain { + + public static ChainBuilder sendUnframedExportTraceServiceRequest(final List endpoints, + final int batchSize) { + ChainBuilder chainBuilder = ChainBuilder.EMPTY; + for (final String endpoint : endpoints) { + final Function requestTemplate = TraceTemplates.exportTraceServiceRequestTemplate(batchSize); + chainBuilder = chainBuilder.exec( + HttpDsl.http("Post to " + endpoint) + .post("http://" + endpoint + "/opentelemetry.proto.collector.trace.v1.TraceService/Export") + .body(CoreDsl.StringBody(requestTemplate))); + } + return chainBuilder; + } +} diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java new file mode 100644 index 0000000000..8f3dcbf4fc --- /dev/null +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java @@ -0,0 +1,118 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.dataprepper.test.performance.tools; + +import com.google.protobuf.ByteString; +import com.google.protobuf.InvalidProtocolBufferException; +import com.google.protobuf.util.JsonFormat; +import io.gatling.javaapi.core.Session; +import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest; +import io.opentelemetry.proto.common.v1.AnyValue; +import io.opentelemetry.proto.common.v1.KeyValue; +import io.opentelemetry.proto.resource.v1.Resource; +import io.opentelemetry.proto.trace.v1.InstrumentationLibrarySpans; +import io.opentelemetry.proto.trace.v1.ResourceSpans; +import io.opentelemetry.proto.trace.v1.Span; +import io.opentelemetry.proto.trace.v1.Status; +import org.apache.commons.lang3.RandomStringUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; +import java.util.function.Function; + +public class TraceTemplates { + private static final JsonFormat.Printer PRINTER = JsonFormat.printer().omittingInsignificantWhitespace(); + private static final Random RANDOM = new Random(); + + public static Function exportTraceServiceRequestTemplate(final int batchSize) { + return session -> { + try { + return PRINTER.print(getExportTraceServiceRequest(batchSize)); + } catch (InvalidProtocolBufferException e) { + throw new RuntimeException(e); + } + }; + } + + public static ExportTraceServiceRequest getExportTraceServiceRequest(final int batchSize) { + return ExportTraceServiceRequest.newBuilder() + .addAllResourceSpans(getTraceGroupResourceSpans(batchSize)) + .build(); + } + + public static List getTraceGroupResourceSpans(final int traceGroupSize) { + final ArrayList spansList = new ArrayList<>(); + final byte[] traceId = getRandomBytes(16); + final byte[] rootSpanId = getRandomBytes(8); + for(int i = 0; i < traceGroupSize; i++) { + final byte[] parentId = (i == 0? null : rootSpanId); + final byte[] spanId = (i == 0? rootSpanId : getRandomBytes(8)); + final String serviceName = RandomStringUtils.randomAlphabetic(10); + final String spanName = RandomStringUtils.randomAlphabetic(10); + final Span.SpanKind spanKind = Span.SpanKind.SPAN_KIND_SERVER; + final long endTime = System.currentTimeMillis() * 1000000; + final long durationInNanos = 100000 + RANDOM.nextInt(500000); + final ResourceSpans rs = getResourceSpans( + traceId, + spanId, + parentId, + serviceName, + spanName, + spanKind, + endTime, + durationInNanos, + 1 + ); + spansList.add(rs); + } + return spansList; + } + + public static ResourceSpans getResourceSpans(final byte[] traceId, final byte[] spanId, final byte[] parentId, + final String serviceName, final String spanName, final Span.SpanKind spanKind, + final long endTimeInNanos, final long durationInNanos, final Integer statusCode) { + final ByteString parentSpanId = parentId != null ? ByteString.copyFrom(parentId) : ByteString.EMPTY; + final long startTimeInNanos = endTimeInNanos - durationInNanos; + final KeyValue.Builder kvBuilder = KeyValue.newBuilder() + .setKey("key") + .setValue(AnyValue.newBuilder().setStringValue("value")); + return ResourceSpans.newBuilder() + .setResource( + Resource.newBuilder() + .addAttributes(KeyValue.newBuilder() + .setKey("service.name") + .setValue(AnyValue.newBuilder().setStringValue(serviceName).build()).build()) + .build() + ) + .addInstrumentationLibrarySpans( + 0, + InstrumentationLibrarySpans.newBuilder() + .addSpans( + Span.newBuilder() + .setName(spanName) + .setKind(spanKind) + .setSpanId(ByteString.copyFrom(spanId)) + .setParentSpanId(parentSpanId) + .setTraceId(ByteString.copyFrom(traceId)) + .setStartTimeUnixNano(startTimeInNanos) + .setEndTimeUnixNano(endTimeInNanos) + .setStatus(Status.newBuilder().setCodeValue(statusCode)) + .addEvents(Span.Event.newBuilder().addAttributes(kvBuilder)) + .addLinks(Span.Link.newBuilder().addAttributes(kvBuilder)) + .build() + ) + .build() + ) + .build(); + } + + public static byte[] getRandomBytes(int len) { + byte[] bytes = new byte[len]; + RANDOM.nextBytes(bytes); + return bytes; + } +} From 17142a7000c36b007d91dce07bf9c31d4bf303a7 Mon Sep 17 00:00:00 2001 From: Chen <19492223+chenqi0805@users.noreply.github.com> Date: Fri, 4 Feb 2022 21:42:25 -0600 Subject: [PATCH 2/8] MAINT: missing fields Signed-off-by: Chen <19492223+chenqi0805@users.noreply.github.com> --- .../test/performance/tools/TraceTemplates.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java index 8f3dcbf4fc..4f887192fe 100644 --- a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java @@ -101,8 +101,15 @@ public static ResourceSpans getResourceSpans(final byte[] traceId, final byte[] .setStartTimeUnixNano(startTimeInNanos) .setEndTimeUnixNano(endTimeInNanos) .setStatus(Status.newBuilder().setCodeValue(statusCode)) - .addEvents(Span.Event.newBuilder().addAttributes(kvBuilder)) - .addLinks(Span.Link.newBuilder().addAttributes(kvBuilder)) + .addEvents(Span.Event.newBuilder() + .setName(spanName) + .setTimeUnixNano(endTimeInNanos) + .addAttributes(kvBuilder)) + .addLinks(Span.Link.newBuilder() + .setTraceId(ByteString.copyFrom(traceId)) + .setSpanId(ByteString.copyFrom(spanId)) + .setTraceState("") + .addAttributes(kvBuilder)) .build() ) .build() From 92e732ea378eacb54003b46ac05b0101a50c6d1c Mon Sep 17 00:00:00 2001 From: Chen <19492223+chenqi0805@users.noreply.github.com> Date: Fri, 4 Feb 2022 21:50:57 -0600 Subject: [PATCH 3/8] MAINT: fill in trace state Signed-off-by: Chen <19492223+chenqi0805@users.noreply.github.com> --- examples/log-ingestion/test.log | 1 - .../dataprepper/test/performance/tools/TraceTemplates.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/log-ingestion/test.log b/examples/log-ingestion/test.log index 8b13789179..e69de29bb2 100644 --- a/examples/log-ingestion/test.log +++ b/examples/log-ingestion/test.log @@ -1 +0,0 @@ - diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java index 4f887192fe..fa90b3d53e 100644 --- a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java @@ -108,7 +108,7 @@ public static ResourceSpans getResourceSpans(final byte[] traceId, final byte[] .addLinks(Span.Link.newBuilder() .setTraceId(ByteString.copyFrom(traceId)) .setSpanId(ByteString.copyFrom(spanId)) - .setTraceState("") + .setTraceState("test state") .addAttributes(kvBuilder)) .build() ) From 63305598f9701da058973b1eba4a92eecc953d18 Mon Sep 17 00:00:00 2001 From: Chen <19492223+chenqi0805@users.noreply.github.com> Date: Sat, 5 Feb 2022 21:53:05 -0600 Subject: [PATCH 4/8] MAINT: split trace group by endpoint Signed-off-by: Chen <19492223+chenqi0805@users.noreply.github.com> --- .../test/performance/tools/TraceChain.java | 14 +++++++---- .../performance/tools/TraceTemplates.java | 24 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceChain.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceChain.java index 1000077ba1..c579f62253 100644 --- a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceChain.java +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceChain.java @@ -5,25 +5,31 @@ package org.opensearch.dataprepper.test.performance.tools; +import com.google.protobuf.util.JsonFormat; import io.gatling.javaapi.core.ChainBuilder; import io.gatling.javaapi.core.CoreDsl; -import io.gatling.javaapi.core.Session; import io.gatling.javaapi.http.HttpDsl; import java.util.List; -import java.util.function.Function; public class TraceChain { + private static final JsonFormat.Printer PRINTER = JsonFormat.printer().omittingInsignificantWhitespace(); public static ChainBuilder sendUnframedExportTraceServiceRequest(final List endpoints, final int batchSize) { ChainBuilder chainBuilder = ChainBuilder.EMPTY; + chainBuilder = chainBuilder.exec(session -> { + final List requestJsons = TraceTemplates.exportTraceServiceRequestJsons(endpoints.size(), batchSize); + for (int i = 0; i < endpoints.size(); i++) { + session = session.set(endpoints.get(i), requestJsons.get(i)); + } + return session; + }); for (final String endpoint : endpoints) { - final Function requestTemplate = TraceTemplates.exportTraceServiceRequestTemplate(batchSize); chainBuilder = chainBuilder.exec( HttpDsl.http("Post to " + endpoint) .post("http://" + endpoint + "/opentelemetry.proto.collector.trace.v1.TraceService/Export") - .body(CoreDsl.StringBody(requestTemplate))); + .body(CoreDsl.StringBody(session -> session.getString(endpoint)))); } return chainBuilder; } diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java index fa90b3d53e..82d25ef6ac 100644 --- a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java @@ -20,27 +20,39 @@ import org.apache.commons.lang3.RandomStringUtils; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Random; import java.util.function.Function; +import java.util.stream.Collectors; public class TraceTemplates { private static final JsonFormat.Printer PRINTER = JsonFormat.printer().omittingInsignificantWhitespace(); private static final Random RANDOM = new Random(); - public static Function exportTraceServiceRequestTemplate(final int batchSize) { - return session -> { + public static List exportTraceServiceRequestJsons(final int peerListSize, final int batchSize) { + return getExportTraceServiceRequests(peerListSize, batchSize).stream().map(exportTraceServiceRequest -> { try { - return PRINTER.print(getExportTraceServiceRequest(batchSize)); + return PRINTER.print(exportTraceServiceRequest); } catch (InvalidProtocolBufferException e) { throw new RuntimeException(e); } - }; + }).collect(Collectors.toList()); } - public static ExportTraceServiceRequest getExportTraceServiceRequest(final int batchSize) { + public static List getExportTraceServiceRequests(final int peerListSize, final int batchSize) { + final List results = new ArrayList<>(); + final List resourceSpansList = getTraceGroupResourceSpans(peerListSize * batchSize); + for (int i=0; i resourceSpansList) { return ExportTraceServiceRequest.newBuilder() - .addAllResourceSpans(getTraceGroupResourceSpans(batchSize)) + .addAllResourceSpans(resourceSpansList) .build(); } From 2eb414fdc783c21e093a983be315bc02774b3aee Mon Sep 17 00:00:00 2001 From: Chen <19492223+chenqi0805@users.noreply.github.com> Date: Sat, 5 Feb 2022 22:17:34 -0600 Subject: [PATCH 5/8] ADD: slow burn simulation Signed-off-by: Chen <19492223+chenqi0805@users.noreply.github.com> --- .../performance/SlowBurnTraceSimulation.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/SlowBurnTraceSimulation.java diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/SlowBurnTraceSimulation.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/SlowBurnTraceSimulation.java new file mode 100644 index 0000000000..190fbb4e1b --- /dev/null +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/SlowBurnTraceSimulation.java @@ -0,0 +1,40 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.dataprepper.test.performance; + +import io.gatling.javaapi.core.CoreDsl; +import io.gatling.javaapi.core.ScenarioBuilder; +import io.gatling.javaapi.core.Simulation; +import org.opensearch.dataprepper.test.performance.tools.Chain; +import org.opensearch.dataprepper.test.performance.tools.Protocol; +import org.opensearch.dataprepper.test.performance.tools.TraceChain; + +import java.time.Duration; +import java.util.Arrays; +import java.util.List; + +public class SlowBurnTraceSimulation extends Simulation { + private static final Integer batchSize = Integer.getInteger("batchSize", 200); + private static final Integer rampUsers = Integer.getInteger("rampUsers", 60); + private static final Duration rampUpTime = Duration.ofMinutes(Integer.getInteger("rampUpTime", 60)); + private static final Duration peakDuration = Duration.ofMinutes(Integer.getInteger("rampUpTime", 5)); + private static final List endpoints = Arrays.asList(System.getProperty("endpoints").split(",")); + + ScenarioBuilder rampUpScenario = CoreDsl.scenario("Slow Burn") + .forever() + .on(TraceChain.sendUnframedExportTraceServiceRequest(endpoints, batchSize)); + + { + setUp( + rampUpScenario.injectOpen( + CoreDsl.rampUsers(rampUsers).during(rampUpTime), + CoreDsl.nothingFor(peakDuration) + ) + ) + .maxDuration(rampUpTime.plus(peakDuration)) + .protocols(Protocol.httpProtocol()); + } +} From b5cee9d286426ea07fc8ec789673fb9b17a2786a Mon Sep 17 00:00:00 2001 From: Chen <19492223+chenqi0805@users.noreply.github.com> Date: Mon, 7 Feb 2022 09:48:40 -0600 Subject: [PATCH 6/8] FIX: touched irrelevant file Signed-off-by: Chen <19492223+chenqi0805@users.noreply.github.com> --- examples/log-ingestion/test.log | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/log-ingestion/test.log b/examples/log-ingestion/test.log index e69de29bb2..8b13789179 100644 --- a/examples/log-ingestion/test.log +++ b/examples/log-ingestion/test.log @@ -0,0 +1 @@ + From 0f6b1c6c7a8337b9300ee1e8150c9f65c39931de Mon Sep 17 00:00:00 2001 From: Chen <19492223+chenqi0805@users.noreply.github.com> Date: Mon, 7 Feb 2022 10:06:58 -0600 Subject: [PATCH 7/8] MAINT: unused imports Signed-off-by: Chen <19492223+chenqi0805@users.noreply.github.com> --- .../dataprepper/test/performance/SlowBurnTraceSimulation.java | 1 - .../dataprepper/test/performance/tools/TraceTemplates.java | 2 -- 2 files changed, 3 deletions(-) diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/SlowBurnTraceSimulation.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/SlowBurnTraceSimulation.java index 190fbb4e1b..25e2ef5cff 100644 --- a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/SlowBurnTraceSimulation.java +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/SlowBurnTraceSimulation.java @@ -8,7 +8,6 @@ import io.gatling.javaapi.core.CoreDsl; import io.gatling.javaapi.core.ScenarioBuilder; import io.gatling.javaapi.core.Simulation; -import org.opensearch.dataprepper.test.performance.tools.Chain; import org.opensearch.dataprepper.test.performance.tools.Protocol; import org.opensearch.dataprepper.test.performance.tools.TraceChain; diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java index 82d25ef6ac..ffcb9ff951 100644 --- a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java @@ -8,7 +8,6 @@ import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import com.google.protobuf.util.JsonFormat; -import io.gatling.javaapi.core.Session; import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest; import io.opentelemetry.proto.common.v1.AnyValue; import io.opentelemetry.proto.common.v1.KeyValue; @@ -23,7 +22,6 @@ import java.util.Collections; import java.util.List; import java.util.Random; -import java.util.function.Function; import java.util.stream.Collectors; public class TraceTemplates { From 863554a5bb5bed8365ce6e15ca7f22ee24c70fe0 Mon Sep 17 00:00:00 2001 From: Chen <19492223+chenqi0805@users.noreply.github.com> Date: Mon, 14 Feb 2022 20:22:06 -0600 Subject: [PATCH 8/8] MAINT: finite range of services and span names Signed-off-by: Chen <19492223+chenqi0805@users.noreply.github.com> --- .../test/performance/tools/TraceTemplates.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java index ffcb9ff951..4547b5d4e7 100644 --- a/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java +++ b/performance-test/src/gatling/java/org/opensearch/dataprepper/test/performance/tools/TraceTemplates.java @@ -16,17 +16,20 @@ import io.opentelemetry.proto.trace.v1.ResourceSpans; import io.opentelemetry.proto.trace.v1.Span; import io.opentelemetry.proto.trace.v1.Status; -import org.apache.commons.lang3.RandomStringUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; public class TraceTemplates { private static final JsonFormat.Printer PRINTER = JsonFormat.printer().omittingInsignificantWhitespace(); private static final Random RANDOM = new Random(); + private static final List SERVICE_NAMES = Arrays.asList("SERVICE_A", "SERVICE_B", "SERVICE_C", "SERVICE_D", "SERVICE_E"); + private static final List SPAN_NAMES = Arrays.asList("SPAN_A", "SPAN_B", "SPAN_C", "SPAN_D", "SPAN_E"); public static List exportTraceServiceRequestJsons(final int peerListSize, final int batchSize) { return getExportTraceServiceRequests(peerListSize, batchSize).stream().map(exportTraceServiceRequest -> { @@ -58,11 +61,14 @@ public static List getTraceGroupResourceSpans(final int traceGrou final ArrayList spansList = new ArrayList<>(); final byte[] traceId = getRandomBytes(16); final byte[] rootSpanId = getRandomBytes(8); + final ThreadLocalRandom threadLocalRandom = ThreadLocalRandom.current(); for(int i = 0; i < traceGroupSize; i++) { final byte[] parentId = (i == 0? null : rootSpanId); final byte[] spanId = (i == 0? rootSpanId : getRandomBytes(8)); - final String serviceName = RandomStringUtils.randomAlphabetic(10); - final String spanName = RandomStringUtils.randomAlphabetic(10); + final int randomServiceIndex = threadLocalRandom.nextInt(SERVICE_NAMES.size()); + final int randomSpanNameIndex = threadLocalRandom.nextInt(SPAN_NAMES.size()); + final String serviceName = SERVICE_NAMES.get(randomServiceIndex); + final String spanName = SPAN_NAMES.get(randomSpanNameIndex); final Span.SpanKind spanKind = Span.SpanKind.SPAN_KIND_SERVER; final long endTime = System.currentTimeMillis() * 1000000; final long durationInNanos = 100000 + RANDOM.nextInt(500000);