-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating dependencies regarding issues 721 715 714 691 #846
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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("0.1.0") | ||
.build(); | ||
|
||
apiBytesSentCounter = | ||
meter.counterBuilder(API_COUNTER_METRIC) | ||
.setDescription("API request load sent in bytes") | ||
.setUnit("one") | ||
.build(); | ||
|
||
meter.gaugeBuilder(API_LATENCY_METRIC) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe you can use a histogram to record latency instead of a gauge: https://aws-otel.github.io/docs/getting-started/java-sdk/trace-manual-instr#creating-metrics There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks. as discussed keeping Gauge for now. |
||
.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); | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you change the value being added? Will this affect the tests in any way?