Skip to content

Commit

Permalink
refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Feb 4, 2025
1 parent 2ba59e3 commit 9f36598
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 48 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ ioGrpc = "1.70.0"
# If you rename or move this variable to another file, adjust the release-workflow
ioOpencensus = "0.31.1"
# Update to latest OTel in next release - Delay due to jaeger-exporter deprecation notice
ioOpentelemetry = "1.34.1"
ioOpentelemetryAlpha = "1.34.1-alpha"
ioOpentelemetry = "1.30.0"
ioOpentelemetryAlpha = "1.30.0-alpha"
ioOpentelemetrySemconv = "1.29.0-alpha"
orgApacheLoggingLog4j = "2.24.1"
# @pin 10+ does not support Java 8 - Maintain latest 9 version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.opencensusshim.OpenCensusMetricProducer;
import io.opentelemetry.opencensusshim.metrics.OpenCensusMetrics;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder;
Expand Down Expand Up @@ -432,13 +432,13 @@ synchronized SdkMeterProvider configureMeterProvider() {
Resource metricServiceNameResource = Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, env.getCurrentConfig()
.getServiceName()));
SdkMeterProviderBuilder builder = SdkMeterProvider.builder()
// register OC metric producer, so the OTel SDK can use OC metrics
.registerMetricProducer(OpenCensusMetricProducer.create())
// TODO Update OTel
//.registerMetricProducer(OpenCensusMetricProducer.create())
.setResource(metricServiceNameResource);

// register metric reader for each service
for (DynamicallyActivatableMetricsExporterService metricsExportService : registeredMetricExporterServices.values()) {
builder.registerMetricReader(metricsExportService.getNewMetricReader());
builder.registerMetricReader(OpenCensusMetrics.attachTo(metricsExportService.getNewMetricReader()));
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import rocks.inspectit.ocelot.core.config.InspectitEnvironment;

import java.io.UncheckedIOException;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand All @@ -60,7 +62,7 @@
@Testcontainers(disabledWithoutDocker = true)
public abstract class ExporterServiceIntegrationTestBase extends SpringTestBase {

static final String COLLECTOR_TAG = "0.58.0";
static final String COLLECTOR_TAG = "0.100.0";

static final String COLLECTOR_IMAGE = "otel/opentelemetry-collector-contrib:" + COLLECTOR_TAG;

Expand Down Expand Up @@ -88,11 +90,6 @@ public abstract class ExporterServiceIntegrationTestBase extends SpringTestBase

static final String INSTRUMENTATION_VERSION = "0.0.1";

static final Resource RESOURCE = Resource.getDefault()
.toBuilder()
.put(ResourceAttributes.SERVICE_NAME, "OTEL integration test")
.build();

private static final Logger LOGGER = Logger.getLogger(ExporterServiceIntegrationTestBase.class.getName());

/**
Expand Down Expand Up @@ -129,7 +126,7 @@ static void startCollector() {
.withExposedPorts(COLLECTOR_OTLP_GRPC_PORT, COLLECTOR_OTLP_HTTP_PORT, COLLECTOR_HEALTH_CHECK_PORT, COLLECTOR_JAEGER_THRIFT_HTTP_PORT, COLLECTOR_JAEGER_THRIFT_BINARY_PORT, COLLECTOR_JAEGER_THRIFT_COMPACT_PORT, COLLECTOR_JAEGER_GRPC_PORT, COLLECTOR_PROMETHEUS_PORT, COLLECTOR_INFLUX_DB1_PORT, COLLECTOR_ZIPKIN_PORT)
.waitingFor(Wait.forHttp("/").forPort(COLLECTOR_HEALTH_CHECK_PORT));

// collector.withStartupTimeout(Duration.of(1, ChronoUnit.MINUTES));
//collector.withStartupTimeout(Duration.of(1, ChronoUnit.MINUTES));
// note: in case you receive the 'Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open' exception,
// uncomment the above line. The exception is probably caused by Docker Desktop hiccups and should only appear locally.
collector.start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import rocks.inspectit.ocelot.core.config.InspectitEnvironment;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -111,6 +110,7 @@ void testNoProtocolSet() {
warnLogs.assertContains("'protocol'");
}

@DirtiesContext
@Test
void defaultSettings() {
AssertionsForClassTypes.assertThat(service.isEnabled()).isFalse();
Expand Down Expand Up @@ -140,20 +140,7 @@ void testAggregationTemporalityCumulative(){
recordMetricsAndFlush(measure, 1, "key", "val");
recordMetricsAndFlush(measure, 2, "key", "val");

await().atMost(30, TimeUnit.SECONDS)
.untilAsserted(() -> assertThat(grpcServer.metricRequests.stream()).anyMatch(mReq -> mReq.getResourceMetricsList()
.stream()
.anyMatch(rm ->
// check for the "my-counter" metrics
rm.getInstrumentationLibraryMetrics(0).getMetrics(0).getName().equals("my-counter")
// check for the specific attribute and value
&& rm.getInstrumentationLibraryMetrics(0)
.getMetricsList()
.stream()
.anyMatch(metric -> metric.getSum()
.getDataPointsList()
.stream()
.anyMatch(d -> d.getAsInt() == 3)))));
awaitMetricsExported(measure, 3, "key", "val");
}

@DirtiesContext
Expand All @@ -172,21 +159,7 @@ void testAggregationTemporalityDelta(){
recordMetricsAndFlush(measure, 1, "key", "val");
recordMetricsAndFlush(measure, 2, "key", "val");

await().atMost(30, TimeUnit.SECONDS)
.untilAsserted(() -> assertThat(grpcServer.metricRequests.stream()).anyMatch(mReq -> mReq.getResourceMetricsList()
.stream()
.anyMatch(rm ->
// check for the "my-counter" metrics
rm.getInstrumentationLibraryMetrics(0).getMetrics(0).getName().equals("my-counter")
// check for the specific attribute and value
&& rm.getInstrumentationLibraryMetrics(0)
.getMetricsList()
.stream()
.anyMatch(metric -> metric.getSum()
.getDataPointsList()
.stream()
.anyMatch(d -> d.getAsInt() == 2)))));

awaitMetricsExported(measure, 2, "key", "val");
}

@DirtiesContext
Expand Down
10 changes: 5 additions & 5 deletions inspectit-ocelot-core/src/test/resources/otel-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ receivers:
zipkin:

exporters:
logging:
logLevel: $LOGGING_EXPORTER_LOG_lEVEL
otlp:
endpoint: $OTLP_EXPORTER_ENDPOINT
tls:
insecure: true
compression: none
debug:
verbosity: detailed

service:
extensions: [health_check]
pipelines:
metrics:
receivers: [otlp, prometheus, influxdb]
exporters: [logging, otlp]
exporters: [debug, otlp]
traces:
receivers: [otlp, jaeger, zipkin]
exporters: [logging, otlp]
exporters: [debug, otlp]
logs:
receivers: [otlp]
exporters: [logging, otlp]
exporters: [debug, otlp]
telemetry:
logs:
level: "info"

0 comments on commit 9f36598

Please sign in to comment.