Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sdk-extensions/jaeger-remote-sampler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ dependencies {

testImplementation(project(":sdk:testing"))
testImplementation(project(":sdk-extensions:autoconfigure"))
testImplementation(project(":sdk-extensions:declarative-config"))
testImplementation(project(":api:incubator"))
testImplementation("com.google.guava:guava")
testImplementation("com.google.protobuf:protobuf-java")
testImplementation("com.linecorp.armeria:armeria-junit5")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public final class JaegerRemoteSampler implements Sampler {
private final AtomicBoolean isShutdown = new AtomicBoolean();

private final GrpcSender grpcSender;
private final int pollingIntervalMs;

JaegerRemoteSampler(
GrpcSender grpcSender,
Expand All @@ -53,6 +54,7 @@ public final class JaegerRemoteSampler implements Sampler {
Sampler initialSampler) {
this.serviceName = serviceName != null ? serviceName : "";
this.grpcSender = grpcSender;
this.pollingIntervalMs = pollingIntervalMs;
this.sampler = initialSampler;
pollExecutor = Executors.newScheduledThreadPool(1, new DaemonThreadFactory(WORKER_THREAD_NAME));
pollFuture =
Expand Down Expand Up @@ -174,6 +176,11 @@ Sampler getSampler() {
return this.sampler;
}

// Visible for testing
int getPollingIntervalMs() {
return this.pollingIntervalMs;
}

public static JaegerRemoteSamplerBuilder builder() {
return new JaegerRemoteSamplerBuilder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public Sampler create(DeclarativeConfigProperties config) {
}
builder.setInitialSampler(DeclarativeConfiguration.createSampler(initialSamplerModel));

Long pollingIntervalMs = config.getLong("internal");
Long pollingIntervalMs = config.getLong("interval");
if (pollingIntervalMs != null) {
builder.setPollingInterval(Duration.ofMillis(pollingIntervalMs));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.sdk.extension.trace.jaeger.sampler;

import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties;
import io.opentelemetry.internal.testing.slf4j.SuppressLogger;
import io.opentelemetry.sdk.autoconfigure.declarativeconfig.DeclarativeConfiguration;
import io.opentelemetry.sdk.extension.trace.jaeger.sampler.internal.JaegerRemoteSamplerComponentProvider;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;

// Connecting to the (unavailable) endpoint during the initial poll logs a warning; suppress it.
@SuppressLogger(JaegerRemoteSampler.class)
class JaegerRemoteSamplerComponentProviderTest {

private static final int DEFAULT_POLLING_INTERVAL_MILLIS = 60000;

@Test
void create_appliesConfiguredInterval() {
// Regression test for reading the wrong declarative config key: the property is "interval", so
// reading "internal" silently dropped the operator's value and fell back to the default.
Sampler sampler =
create(
"endpoint: http://localhost:14250\n"
+ "interval: 10000\n"
+ "initial_sampler:\n"
+ " always_off: {}\n");
try {
assertThat(((JaegerRemoteSampler) sampler).getPollingIntervalMs()).isEqualTo(10000);
} finally {
((JaegerRemoteSampler) sampler).shutdown();
}
}

@Test
void create_defaultsIntervalWhenOmitted() {
Sampler sampler =
create("endpoint: http://localhost:14250\n" + "initial_sampler:\n" + " always_off: {}\n");
try {
assertThat(((JaegerRemoteSampler) sampler).getPollingIntervalMs())
.isEqualTo(DEFAULT_POLLING_INTERVAL_MILLIS);
} finally {
((JaegerRemoteSampler) sampler).shutdown();
}
}

private static Sampler create(String yaml) {
DeclarativeConfigProperties config =
DeclarativeConfiguration.toConfigProperties(
new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8)));
return new JaegerRemoteSamplerComponentProvider().create(config);
}
}
Loading