Skip to content

Commit

Permalink
Updated temporality and applied java spotless
Browse files Browse the repository at this point in the history
Signed-off-by: Atharva Sharma <[email protected]>
  • Loading branch information
atharvasharma61 committed May 7, 2024
1 parent ee5e1c1 commit 53770cf
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ public Map<String, Supplier<Transport>> getTransports(
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService,
Tracer tracer,
MetricsRegistry metricsRegistry) {
MetricsRegistry metricsRegistry
) {
return Collections.singletonMap(
NETTY_TRANSPORT_NAME,
() -> new Netty4Transport(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;

import io.opentelemetry.exporter.logging.LoggingMetricExporter;
import io.opentelemetry.exporter.otlp.metrics.OtlpGrpcMetricExporter;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector;
import io.opentelemetry.sdk.metrics.export.MetricExporter;

/**
Expand All @@ -46,7 +50,16 @@ private OTelMetricsExporterFactory() {
*/
public static MetricExporter create(Settings settings) {
Class<MetricExporter> MetricExporterProviderClass = OTelTelemetrySettings.OTEL_METRICS_EXPORTER_CLASS_SETTING.get(settings);
MetricExporter metricExporter = instantiateExporter(MetricExporterProviderClass);
MetricExporter metricExporter;
if (MetricExporterProviderClass.getName().equals(LoggingMetricExporter.class.getName())) {
metricExporter = LoggingMetricExporter.create(AggregationTemporality.DELTA);
} else if (MetricExporterProviderClass.getName().equals(OtlpGrpcMetricExporter.class.getName())) {
metricExporter = OtlpGrpcMetricExporter.builder()
.setAggregationTemporalitySelector(AggregationTemporalitySelector.deltaPreferred())
.build();
} else {
metricExporter = instantiateExporter(MetricExporterProviderClass);
}
logger.info("Successfully instantiated the Metrics MetricExporter class {}", MetricExporterProviderClass);
return metricExporter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.opensearch.telemetry.tracing;

import io.opentelemetry.sdk.metrics.internal.view.Base2ExponentialHistogramAggregation;
import org.opensearch.common.settings.Settings;
import org.opensearch.telemetry.TelemetrySettings;
import org.opensearch.telemetry.metrics.exporter.OTelMetricsExporterFactory;
Expand All @@ -23,12 +24,12 @@
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.Aggregation;
import io.opentelemetry.sdk.metrics.InstrumentSelector;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.View;
import io.opentelemetry.sdk.metrics.export.PeriodicMetricReader;
import io.opentelemetry.sdk.metrics.internal.view.Base2ExponentialHistogramAggregation;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
Expand Down Expand Up @@ -101,6 +102,10 @@ private static SdkMeterProvider createSdkMetricProvider(Settings settings, Resou
InstrumentSelector.builder().setType(InstrumentType.HISTOGRAM).build(),
View.builder().setAggregation(Base2ExponentialHistogramAggregation.getDefault()).build()
)
.registerView(
InstrumentSelector.builder().setName("otlp.exporter.*").build(),
View.builder().setAggregation(Aggregation.drop()).build()
)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public Map<String, Supplier<Transport>> getTransports(
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService,
Tracer tracer,
MetricsRegistry metricsRegistry) {
MetricsRegistry metricsRegistry
) {
return Collections.singletonMap(
NIO_TRANSPORT_NAME,
() -> new NioTransport(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ default Map<String, Supplier<Transport>> getTransports(
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService,
Tracer tracer,
MetricsRegistry metricsRegistry) {
MetricsRegistry metricsRegistry
) {
return Collections.emptyMap();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public Map<String, Supplier<Transport>> getTransports(
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService,
Tracer tracer,
MetricsRegistry metricsRegistry) {
MetricsRegistry metricsRegistry
) {
return Collections.singletonMap("custom", custom);
}
};
Expand Down Expand Up @@ -288,7 +289,8 @@ public Map<String, Supplier<Transport>> getTransports(
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService,
Tracer tracer,
MetricsRegistry metricsRegistry) {
MetricsRegistry metricsRegistry
) {
return Collections.singletonMap("default_custom", customTransport);
}

Expand Down Expand Up @@ -333,7 +335,8 @@ public Map<String, Supplier<Transport>> getTransports(
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService,
Tracer tracer,
MetricsRegistry metricsRegistry) {
MetricsRegistry metricsRegistry
) {
return Collections.singletonMap("default_custom", customTransport);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public Map<String, Supplier<Transport>> getTransports(
NamedWriteableRegistry namedWriteableRegistry,
NetworkService networkService,
Tracer tracer,
MetricsRegistry metricsRegistry) {
MetricsRegistry metricsRegistry
) {
return Collections.singletonMap(
MOCK_NIO_TRANSPORT_NAME,
() -> new MockNioTransport(
Expand Down

0 comments on commit 53770cf

Please sign in to comment.