Skip to content

Commit

Permalink
inspectIT#1269: Integrated the concept of an IOpenTelemetryController…
Browse files Browse the repository at this point in the history
… that handles the registration and unregister of individual traces and metrics exporter services. Fixed JaegerExporterService, PrometheusExporterService, ZipkinExporterService to work with inspectIT Ocelot. Adjusted build.gradle in the core package and added a SpringTestBase.yml configuration to speed up tests in the core module (as the OTEL implementation of the Prometheus server needs ~10 seconds to shut down).
  • Loading branch information
Heiko Holz committed Jan 11, 2022
1 parent 0326626 commit 37bdc0a
Show file tree
Hide file tree
Showing 31 changed files with 1,598 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import rocks.inspectit.ocelot.bootstrap.instrumentation.IHookManager;
import rocks.inspectit.ocelot.bootstrap.instrumentation.noop.NoopHookManager;
import rocks.inspectit.ocelot.bootstrap.instrumentation.noop.NoopObjectAttachments;
import rocks.inspectit.ocelot.bootstrap.opentelemetry.IOpenTelemetryController;
import rocks.inspectit.ocelot.bootstrap.opentelemetry.NoopOpenTelemetryController;

import java.net.URL;

Expand Down Expand Up @@ -41,4 +43,6 @@ public class Instances {
public static LogTraceCorrelator logTraceCorrelator = NoopLogTraceCorrelator.INSTANCE;

public static TraceIdInjector traceIdInjector = NoopTraceIdInjector.INSTANCE;

public static IOpenTelemetryController openTelemetryController = NoopOpenTelemetryController.INSTANCE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package rocks.inspectit.ocelot.bootstrap.opentelemetry;

/**
* Controller interface for the OpenTelemetryController. Its implementation is {@link rocks.inspectit.ocelot.core.opentelemetry.OpenTelemetryControllerImpl}
*/
public interface IOpenTelemetryController {

/**
* Shuts down the {@link IOpenTelemetryController}
*/
void shutdown();

/**
* Starts the {@link IOpenTelemetryController}
*
* @return Whether the {@link IOpenTelemetryController} was successfuly started
*/
boolean start();

/**
* Gets whether the {@link IOpenTelemetryController} is configured
*
* @return Whether the {@link IOpenTelemetryController} is configured
*/
boolean isConfigured();

/**
* Gets whether the {@link IOpenTelemetryController} is enabled
*
* @return Whether the {@link IOpenTelemetryController} is enabled
*/
boolean isEnabled();

/**
* Notifies the {@link IOpenTelemetryController} that something in the {@link rocks.inspectit.ocelot.config.model.tracing.TracingSettings} changed
*/
void notifyTracingSettingsChanged();

/**
* Notifies the {@link IOpenTelemetryController} that something in the {@link rocks.inspectit.ocelot.config.model.metrics.MetricsSettings} changed
*/
void notifyMetricsSettingsChanged();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package rocks.inspectit.ocelot.bootstrap.opentelemetry;

public class NoopOpenTelemetryController implements IOpenTelemetryController {

public static final NoopOpenTelemetryController INSTANCE = new NoopOpenTelemetryController();

@Override
public void shutdown() {

}

@Override
public boolean start() {
return true;
}

@Override
public boolean isConfigured() {
return false;
}

@Override
public boolean isEnabled() {
return true;
}

@Override
public void notifyTracingSettingsChanged() {

}

@Override
public void notifyMetricsSettingsChanged() {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package rocks.inspectit.ocelot.config.model.exporters.trace;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Settings for {@link rocks.inspectit.ocelot.core.exporter.OtlpTraceExporterService}
*/
@Data
@NoArgsConstructor
public class OtlpTraceExporterSettings {

private boolean enabled;

/***
* The OTLP traces endpoint to connect to
*/
private String url;

private String serviceName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ public class TraceExportersSettings {

@Valid
private LoggingTraceExporterSettings logging;

@Valid
private OtlpTraceExporterSettings otlp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ inspectit:
# the time at which the exporter tries to reconnect to the OpenCensus agent
reconnection-period: 5s

# settings for the SpanLoggingExporterService
# settings for the LoggingSpanExporter used in LoggingTraceExporterService
logging:
enabled: true
service-name: ${inspectit.service-name}

# settings for the OtlpGrpcSpanExporter used in OtlpTraceExporterService
otlp:
enabled: true
service-name: ${inspectit.service-name}
url: null
14 changes: 13 additions & 1 deletion inspectit-ocelot-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ test {

jvmArgs '-Xmx512m', '-XX:+HeapDumpOnOutOfMemoryError', '-XX:HeapDumpPath=/__w/inspectit-ocelot/inspectit-ocelot/test_heapdump.bin'

// include custom configurations to potentially speed up tests or change settings in test files
jvmArgs "-Dinspectit.config.file-based.path=$projectDir/src/test/resources/config"

testLogging {
exceptionFormat = 'full'
}
Expand Down Expand Up @@ -84,6 +87,13 @@ dependencies {
// OpenTelemetry exporters
platform("io.opentelemetry:opentelemetry-bom:${openTelemetryVersion}"),
"io.opentelemetry:opentelemetry-exporter-logging",
"io.opentelemetry:opentelemetry-exporter-jaeger",
"io.opentelemetry:opentelemetry-exporter-jaeger-thrift",
"io.opentelemetry:opentelemetry-exporter-zipkin",
"io.opentelemetry:opentelemetry-exporter-otlp",

platform("io.opentelemetry:opentelemetry-bom-alpha:${openTelemetryAlphaVersion}"),
"io.opentelemetry:opentelemetry-exporter-prometheus",

// The following dependency is required for the OC-exporter to work correctly and must be matched against the grpc version
// See https://github.com/census-instrumentation/opencensus-java/blob/master/exporters/trace/ocagent/README.md
Expand Down Expand Up @@ -134,7 +144,9 @@ task checkDependencyJavaVersions {
// exclude OpenTelemetry as they guarantee JDK 8 support
"opentelemetry",
// exclude jackson which is being used by OTel
"jackson"]
"jackson",
// exclude kotlin-stdlib which is being used by opentelemetry-exporter-jaeger-thrift
"kotlin-stdlib"]

def jarCheckPath = "$buildDir/jarCheck"
outputs.dir jarCheckPath
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rocks.inspectit.ocelot.core.config.spring;

import org.hibernate.validator.internal.constraintvalidators.hv.LengthValidator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import rocks.inspectit.ocelot.bootstrap.Instances;
Expand All @@ -8,13 +9,15 @@
import rocks.inspectit.ocelot.bootstrap.correlation.noop.NoopTraceIdInjector;
import rocks.inspectit.ocelot.bootstrap.instrumentation.noop.NoopHookManager;
import rocks.inspectit.ocelot.bootstrap.instrumentation.noop.NoopObjectAttachments;
import rocks.inspectit.ocelot.bootstrap.opentelemetry.NoopOpenTelemetryController;
import rocks.inspectit.ocelot.config.model.InspectitConfig;
import rocks.inspectit.ocelot.core.config.InspectitEnvironment;
import rocks.inspectit.ocelot.core.instrumentation.config.InstrumentationConfigurationResolver;
import rocks.inspectit.ocelot.core.instrumentation.context.ContextManager;
import rocks.inspectit.ocelot.core.instrumentation.context.ObjectAttachmentsImpl;
import rocks.inspectit.ocelot.core.instrumentation.correlation.log.LogTraceCorrelatorImpl;
import rocks.inspectit.ocelot.core.instrumentation.correlation.log.MdcAccessManager;
import rocks.inspectit.ocelot.core.opentelemetry.OpenTelemetryControllerImpl;
import rocks.inspectit.ocelot.core.tags.CommonTagsManager;

import javax.annotation.PreDestroy;
Expand Down Expand Up @@ -52,12 +55,19 @@ public LogTraceCorrelatorImpl getLogTraceCorrelator(MdcAccessManager mdcAccessMa
return new LogTraceCorrelatorImpl(mdcAccessManager, traceIdKey);
}

@Bean(OpenTelemetryControllerImpl.BEAN_NAME)
public OpenTelemetryControllerImpl getOpenTelemetryController(InspectitEnvironment environment) {
InspectitConfig configuration = environment.getCurrentConfig();
return new OpenTelemetryControllerImpl();
}

@PreDestroy
void destroy() {
Instances.contextManager = NoopContextManager.INSTANCE;
Instances.attachments = NoopObjectAttachments.INSTANCE;
Instances.hookManager = NoopHookManager.INSTANCE;
Instances.logTraceCorrelator = NoopLogTraceCorrelator.INSTANCE;
Instances.traceIdInjector = NoopTraceIdInjector.INSTANCE;
Instances.openTelemetryController = NoopOpenTelemetryController.INSTANCE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package rocks.inspectit.ocelot.core.exporter;

import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.export.MetricReader;
import io.opentelemetry.sdk.metrics.export.MetricReaderFactory;
import rocks.inspectit.ocelot.config.model.InspectitConfig;
import rocks.inspectit.ocelot.config.model.exporters.metrics.PrometheusExporterSettings;
import rocks.inspectit.ocelot.core.service.DynamicallyActivatableService;

/**
* Base class for metrics export services that can be dynamically enabled and disabled based on the {@link InspectitConfig}.
* This class extends {@link DynamicallyActivatableService} which handles the waiting for changes in the configuration.
*/
public abstract class DynamicallyActivatableMetricsExporterService extends DynamicallyActivatableService {

/**
* Gets a {@link MetricReaderFactory} for this service.
*
* @return
*/
public abstract MetricReaderFactory getMetricReaderFactory();

/**
* Constructor.
*
* @param configDependencies The list of configuration properties in camelCase this service depends on.
* For example "exporters.metrics.prometheus" specifies a dependency
* to {@link PrometheusExporterSettings}
* and all its children.
*/
public DynamicallyActivatableMetricsExporterService(String... configDependencies) {
super(configDependencies);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public static DynamicallyActivatableSampler createParentBased(Sampler root) {
return new DynamicallyActivatableSampler(Sampler.parentBased(root));
}

/**
* Returns a new {@link DynamicallyActivatableSampler} with a {@link io.opentelemetry.sdk.trace.samplers.TraceIdRatioBasedSampler} implementation
* @param ratio The desired ratio of sampling. Must be within [0.0, 1.0].
* @return A new {@link DynamicallyActivatableSampler} with a {@link io.opentelemetry.sdk.trace.samplers.TraceIdRatioBasedSampler} implementation.
*/
public static DynamicallyActivatableSampler createRatio(double ratio) {
return new DynamicallyActivatableSampler(Sampler.traceIdRatioBased(ratio));
}
Expand Down
Loading

0 comments on commit 37bdc0a

Please sign in to comment.