From cff50acd6e8933eb769b41d617f2abda0e3275fc Mon Sep 17 00:00:00 2001 From: Paurush Garg Date: Thu, 22 Sep 2022 11:38:13 -0700 Subject: [PATCH 1/3] Updating dependicies regarding issues 721 715 714 --- load-generator/build.gradle | 7 +- .../generator/emitter/OtlpMetricEmitter.java | 87 ++++++++++--------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/load-generator/build.gradle b/load-generator/build.gradle index 67e75e12e..35db1cdde 100644 --- a/load-generator/build.gradle +++ b/load-generator/build.gradle @@ -32,9 +32,10 @@ dependencies { implementation platform("io.opentelemetry:opentelemetry-bom:1.12.0") implementation "io.opentelemetry:opentelemetry-api" - implementation "io.opentelemetry:opentelemetry-sdk-metrics:1.4.1-alpha" - implementation "io.opentelemetry:opentelemetry-exporter-otlp:1.10.0" - implementation "io.opentelemetry:opentelemetry-exporter-otlp-metrics:1.4.1-alpha" + implementation "io.opentelemetry:opentelemetry-sdk-metrics:1.18.0" + implementation "io.opentelemetry:opentelemetry-exporter-otlp:1.18.0" + implementation "io.opentelemetry:opentelemetry-semconv:1.18.0-alpha" + implementation "io.opentelemetry:opentelemetry-sdk-extension-aws" implementation "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.4.1-alpha" diff --git a/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpMetricEmitter.java b/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpMetricEmitter.java index 8f2b5a068..a2ce54c89 100644 --- a/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpMetricEmitter.java +++ b/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpMetricEmitter.java @@ -16,23 +16,29 @@ package com.amazon.opentelemetry.load.generator.emitter; import com.amazon.opentelemetry.load.generator.model.Parameter; -import io.grpc.ManagedChannelBuilder; -import io.opentelemetry.api.metrics.GlobalMeterProvider; -import io.opentelemetry.api.metrics.common.Labels; +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.LongCounter; -import io.opentelemetry.api.metrics.LongValueRecorder; import io.opentelemetry.api.metrics.Meter; + import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter; +import io.opentelemetry.sdk.OpenTelemetrySdk; import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.opentelemetry.sdk.metrics.export.IntervalMetricReader; -import io.opentelemetry.sdk.metrics.export.MetricExporter; -import java.util.Collections; +import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader; +import io.opentelemetry.sdk.resources.Resource; +import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; + +import java.util.concurrent.ThreadLocalRandom; +import java.time.Duration; public class OtlpMetricEmitter extends MetricEmitter { private final static String API_NAME = "loadTest"; + private final static Attributes METRIC_ATTRIBUTES = Attributes.of(AttributeKey.stringKey(DIMENSION_API_NAME), API_NAME, + AttributeKey.stringKey(DIMENSION_STATUS_CODE), "200"); LongCounter apiBytesSentCounter; - LongValueRecorder apiLatencyRecorder; + Long apiLatency; public OtlpMetricEmitter(Parameter param) { super(); @@ -47,43 +53,46 @@ public void emitDataLoad() throws Exception { @Override public void nextDataPoint() { - apiLatencyRecorder.record(200, Labels - .of(DIMENSION_API_NAME, API_NAME, DIMENSION_STATUS_CODE, "200")); - apiBytesSentCounter - .add(100, Labels.of(DIMENSION_API_NAME, API_NAME, DIMENSION_STATUS_CODE, "200")); + .add(10, METRIC_ATTRIBUTES); + mutateApiLatency(); } @Override public void setupProvider() { - MetricExporter metricExporter = - OtlpGrpcMetricExporter.builder() - .setChannel( - ManagedChannelBuilder.forTarget(param.getEndpoint()).usePlaintext().build()) - .build(); - - IntervalMetricReader.builder() - .setMetricProducers( - Collections.singleton(SdkMeterProvider.builder().buildAndRegisterGlobal())) - .setExportIntervalMillis(param.getFlushInterval()) - .setMetricExporter(metricExporter) - .build(); - - Meter meter = GlobalMeterProvider.getMeter("aws-otel-load-generator-metric", "0.1.0"); - - - apiBytesSentCounter = meter - .longCounterBuilder(API_COUNTER_METRIC) - .setDescription("API request load sent in bytes") - .setUnit("one") - .build(); - - apiLatencyRecorder = - meter - .longValueRecorderBuilder(API_LATENCY_METRIC) + Resource resource = Resource.getDefault().merge( + Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "load-generator"))); + + OpenTelemetrySdk.builder().setMeterProvider( + SdkMeterProvider.builder() + .registerMetricReader( + PeriodicMetricReader.builder(OtlpGrpcMetricExporter.builder().setEndpoint("http://" + param.getEndpoint()).build()) + .setInterval(Duration.ofMillis(param.getFlushInterval())).build()) + .setResource(resource) + + .build()) + .buildAndRegisterGlobal(); + + Meter meter = + GlobalOpenTelemetry.meterBuilder("aws-otel-load-generator-metric") + .setInstrumentationVersion("1.0") + .build(); + + apiBytesSentCounter = + meter.counterBuilder(API_COUNTER_METRIC) + .setDescription("API request load sent in bytes") + .setUnit("one") + .build(); + + meter.gaugeBuilder(API_LATENCY_METRIC) .setDescription("API latency time") .setUnit("ms") - .build(); + .ofLongs() + .buildWithCallback(measurement -> measurement.record( + apiLatency, METRIC_ATTRIBUTES)); } -} + private void mutateApiLatency() { + this.apiLatency = ThreadLocalRandom.current().nextLong(-100,100); + } +} \ No newline at end of file From 92c4741620012ec9d1b19dd7fffb37beaddcc2ba Mon Sep 17 00:00:00 2001 From: Paurush Garg Date: Fri, 23 Sep 2022 10:37:22 -0700 Subject: [PATCH 2/3] Adding code to fix issue 714 regarding otlp traces --- load-generator/build.gradle | 3 +- .../generator/emitter/OtlpMetricEmitter.java | 2 +- .../generator/emitter/OtlpTraceEmitter.java | 37 ++++++++++++------- .../factory/AwsTracerConfigurer.java | 36 ------------------ 4 files changed, 25 insertions(+), 53 deletions(-) delete mode 100644 load-generator/src/main/java/com/amazon/opentelemetry/load/generator/factory/AwsTracerConfigurer.java diff --git a/load-generator/build.gradle b/load-generator/build.gradle index 35db1cdde..1a73b8b1c 100644 --- a/load-generator/build.gradle +++ b/load-generator/build.gradle @@ -35,10 +35,9 @@ dependencies { implementation "io.opentelemetry:opentelemetry-sdk-metrics:1.18.0" implementation "io.opentelemetry:opentelemetry-exporter-otlp:1.18.0" implementation "io.opentelemetry:opentelemetry-semconv:1.18.0-alpha" + implementation "io.opentelemetry:opentelemetry-sdk:1.18.0" implementation "io.opentelemetry:opentelemetry-sdk-extension-aws" - implementation "io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.4.1-alpha" - implementation "com.amazonaws:aws-xray-recorder-sdk-core:2.11.2" implementation "com.amazonaws:aws-xray-recorder-sdk-aws-sdk:2.11.2" diff --git a/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpMetricEmitter.java b/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpMetricEmitter.java index a2ce54c89..5ca9dc118 100644 --- a/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpMetricEmitter.java +++ b/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpMetricEmitter.java @@ -75,7 +75,7 @@ public void setupProvider() { Meter meter = GlobalOpenTelemetry.meterBuilder("aws-otel-load-generator-metric") - .setInstrumentationVersion("1.0") + .setInstrumentationVersion("0.1.0") .build(); apiBytesSentCounter = diff --git a/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpTraceEmitter.java b/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpTraceEmitter.java index 97ad0fac4..eb3c2065f 100644 --- a/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpTraceEmitter.java +++ b/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/emitter/OtlpTraceEmitter.java @@ -15,17 +15,22 @@ package com.amazon.opentelemetry.load.generator.emitter; -import com.amazon.opentelemetry.load.generator.factory.AwsTracerConfigurer; import com.amazon.opentelemetry.load.generator.model.Parameter; -import io.grpc.ManagedChannelBuilder; +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.SpanKind; -import io.opentelemetry.api.trace.TracerProvider; import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter; +import io.opentelemetry.sdk.trace.export.BatchSpanProcessor; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.Tracer; +import io.opentelemetry.sdk.OpenTelemetrySdk; +import io.opentelemetry.sdk.extension.aws.trace.AwsXrayIdGenerator; +import io.opentelemetry.sdk.resources.Resource; import io.opentelemetry.sdk.trace.SdkTracerProvider; import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor; +import io.opentelemetry.semconv.resource.attributes.ResourceAttributes; + import java.time.Duration; import java.util.UUID; @@ -46,20 +51,24 @@ public void emitDataLoad() throws Exception { @Override public void setupProvider() throws Exception { - OtlpGrpcSpanExporter spanExporter = OtlpGrpcSpanExporter.builder() - .setChannel( - ManagedChannelBuilder.forTarget(param.getEndpoint()).usePlaintext().build()) - .setTimeout(Duration.ofMillis(10)) - .build(); - SdkTracerProviderBuilder builder = SdkTracerProvider.builder(); - new AwsTracerConfigurer().configure(builder); - builder.addSpanProcessor(SimpleSpanProcessor.create(spanExporter)); - TracerProvider tracerProvider = builder.build(); + Resource resource = Resource.getDefault().merge( + Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "load-generator"))); - tracer = - tracerProvider.get("aws-otel-load-generator-trace", "semver:0.1.0"); + OpenTelemetrySdk.builder() + .setTracerProvider( + SdkTracerProvider.builder() + .addSpanProcessor( + BatchSpanProcessor.builder(OtlpGrpcSpanExporter.getDefault()).build()) + .setIdGenerator(AwsXrayIdGenerator.getInstance()) + .setResource(resource) + .build()) + .buildAndRegisterGlobal(); + tracer = + GlobalOpenTelemetry.tracerBuilder("aws-otel-load-generator-trace") + .setInstrumentationVersion("semver:0.1.0") + .build(); } @Override diff --git a/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/factory/AwsTracerConfigurer.java b/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/factory/AwsTracerConfigurer.java deleted file mode 100644 index e832ff296..000000000 --- a/load-generator/src/main/java/com/amazon/opentelemetry/load/generator/factory/AwsTracerConfigurer.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -package com.amazon.opentelemetry.load.generator.factory; - -import io.opentelemetry.sdk.autoconfigure.spi.SdkTracerProviderConfigurer; -import io.opentelemetry.sdk.extension.aws.trace.AwsXrayIdGenerator; -import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder; - -public class AwsTracerConfigurer implements SdkTracerProviderConfigurer { - static { - if (System.getProperty("otel.aws.imds.endpointOverride") == null) { - String overrideFromEnv = System.getenv("OTEL_AWS_IMDS_ENDPOINT_OVERRIDE"); - if (overrideFromEnv != null) { - System.setProperty("otel.aws.imds.endpointOverride", overrideFromEnv); - } - } - } - - @Override - public void configure(SdkTracerProviderBuilder sdkTracerProviderBuilder) { - sdkTracerProviderBuilder.setIdGenerator(AwsXrayIdGenerator.getInstance()); - } -} From 355477154c542b2f488bd2df6a9319fd9f5def92 Mon Sep 17 00:00:00 2001 From: Paurush Garg Date: Fri, 23 Sep 2022 11:04:57 -0700 Subject: [PATCH 3/3] updating dependencies as per comment to use bom --- load-generator/build.gradle | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/load-generator/build.gradle b/load-generator/build.gradle index 1a73b8b1c..e7106c896 100644 --- a/load-generator/build.gradle +++ b/load-generator/build.gradle @@ -30,13 +30,12 @@ dependencies { implementation "io.grpc:grpc-netty-shaded:1.47.0" - implementation platform("io.opentelemetry:opentelemetry-bom:1.12.0") + implementation platform("io.opentelemetry:opentelemetry-bom:1.18.0") implementation "io.opentelemetry:opentelemetry-api" - implementation "io.opentelemetry:opentelemetry-sdk-metrics:1.18.0" - implementation "io.opentelemetry:opentelemetry-exporter-otlp:1.18.0" - implementation "io.opentelemetry:opentelemetry-semconv:1.18.0-alpha" - implementation "io.opentelemetry:opentelemetry-sdk:1.18.0" + implementation "io.opentelemetry:opentelemetry-sdk" + implementation "io.opentelemetry:opentelemetry-exporter-otlp" + implementation "io.opentelemetry:opentelemetry-semconv:1.18.0-alpha" implementation "io.opentelemetry:opentelemetry-sdk-extension-aws" implementation "com.amazonaws:aws-xray-recorder-sdk-core:2.11.2" implementation "com.amazonaws:aws-xray-recorder-sdk-aws-sdk:2.11.2"