Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Do not use deprecated APIs internally #412

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

import io.jaegertracing.Span;
import io.jaegertracing.exceptions.SenderException;
import io.jaegertracing.metrics.InMemoryMetricsFactory;
import io.jaegertracing.metrics.Metrics;
import io.jaegertracing.metrics.NullStatsReporter;
import io.jaegertracing.metrics.StatsFactoryImpl;
import io.jaegertracing.senders.Sender;
import io.jaegertracing.senders.UdpSender;
import java.util.Timer;
Expand Down Expand Up @@ -226,7 +225,7 @@ public RemoteReporter build() {
sender = new UdpSender();
}
if (metrics == null) {
metrics = new Metrics(new StatsFactoryImpl(new NullStatsReporter()));
metrics = new Metrics(new InMemoryMetricsFactory());
}
return new RemoteReporter(sender, flushInterval, maxQueueSize, DEFAULT_CLOSE_ENQUEUE_TIMEOUT_MILLIS, metrics);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
package io.jaegertracing.samplers;

import io.jaegertracing.exceptions.SamplingStrategyErrorException;
import io.jaegertracing.metrics.InMemoryMetricsFactory;
import io.jaegertracing.metrics.Metrics;
import io.jaegertracing.metrics.NullStatsReporter;
import io.jaegertracing.metrics.StatsFactoryImpl;
import io.jaegertracing.samplers.http.OperationSamplingParameters;
import io.jaegertracing.samplers.http.ProbabilisticSamplingStrategy;
import io.jaegertracing.samplers.http.RateLimitingSamplingStrategy;
Expand Down Expand Up @@ -228,7 +227,7 @@ public RemoteControlledSampler build() {
initialSampler = new ProbabilisticSampler(0.001);
}
if (metrics == null) {
metrics = new Metrics(new StatsFactoryImpl(new NullStatsReporter()));
metrics = new Metrics(new InMemoryMetricsFactory());
}
return new RemoteControlledSampler(this);
}
Expand Down
35 changes: 17 additions & 18 deletions jaeger-core/src/test/java/io/jaegertracing/ConfigurationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@

import io.jaegertracing.Configuration.ReporterConfiguration;
import io.jaegertracing.Configuration.SamplerConfiguration;
import io.jaegertracing.metrics.InMemoryMetricsFactory;
import io.jaegertracing.metrics.Metrics;
import io.jaegertracing.metrics.NullStatsReporter;
import io.jaegertracing.metrics.StatsFactoryImpl;
import io.jaegertracing.samplers.ConstSampler;
import io.jaegertracing.samplers.ProbabilisticSampler;
import io.jaegertracing.samplers.RateLimitingSampler;
Expand Down Expand Up @@ -112,8 +111,8 @@ public void testReporterConfiguration() {
System.setProperty(Configuration.JAEGER_REPORTER_MAX_QUEUE_SIZE, "1000");
ReporterConfiguration reporterConfig = ReporterConfiguration.fromEnv();
assertTrue(reporterConfig.getLogSpans());
assertEquals("MyHost", reporterConfig.getAgentHost());
assertEquals(1234, reporterConfig.getAgentPort().intValue());
assertEquals("MyHost", reporterConfig.getSenderConfiguration().getAgentHost());
assertEquals(1234, reporterConfig.getSenderConfiguration().getAgentPort().intValue());
assertEquals(500, reporterConfig.getFlushIntervalMs().intValue());
assertEquals(1000, reporterConfig.getMaxQueueSize().intValue());
}
Expand Down Expand Up @@ -191,8 +190,10 @@ public void testSenderWithAgentDataFromEnv() {
public void testSenderBackwardsCompatibilityGettingAgentHostAndPort() {
System.setProperty(Configuration.JAEGER_AGENT_HOST, "jaeger-agent");
System.setProperty(Configuration.JAEGER_AGENT_PORT, "6832");
assertEquals("jaeger-agent", Configuration.ReporterConfiguration.fromEnv().getAgentHost());
assertEquals(Integer.valueOf(6832), Configuration.ReporterConfiguration.fromEnv().getAgentPort());
assertEquals("jaeger-agent", Configuration.ReporterConfiguration.fromEnv()
.getSenderConfiguration().getAgentHost());
assertEquals(Integer.valueOf(6832), Configuration.ReporterConfiguration.fromEnv()
.getSenderConfiguration().getAgentPort());
}

@Test
Expand Down Expand Up @@ -224,20 +225,18 @@ public void testCustomSender() {

@Test
public void testSenderWithBasicAuthUsesHttpSender() {
Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration.Builder()
.endpoint("https://jaeger-collector:14268/api/traces")
.authUsername("username")
.authPassword("password")
.build();
Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration()
.withEndpoint("https://jaeger-collector:14268/api/traces")
.withAuthUsername("username")
.withAuthPassword("password");
assertTrue(senderConfiguration.getSender() instanceof HttpSender);
}

@Test
public void testSenderWithAuthTokenUsesHttpSender() {
Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration.Builder()
.endpoint("https://jaeger-collector:14268/api/traces")
.authToken("authToken")
.build();
Configuration.SenderConfiguration senderConfiguration = new Configuration.SenderConfiguration()
.withEndpoint("https://jaeger-collector:14268/api/traces")
.withAuthToken("authToken");
assertTrue(senderConfiguration.getSender() instanceof HttpSender);
}

Expand Down Expand Up @@ -351,7 +350,7 @@ public void testConstSampler() {
SamplerConfiguration samplerConfiguration = new SamplerConfiguration()
.withType(ConstSampler.TYPE);
Sampler sampler = samplerConfiguration.createSampler("name",
new Metrics(new StatsFactoryImpl(new NullStatsReporter())));
new Metrics(new InMemoryMetricsFactory()));
assertTrue(sampler instanceof ConstSampler);
}

Expand All @@ -360,7 +359,7 @@ public void testProbabilisticSampler() {
SamplerConfiguration samplerConfiguration = new SamplerConfiguration()
.withType(ProbabilisticSampler.TYPE);
Sampler sampler = samplerConfiguration.createSampler("name",
new Metrics(new StatsFactoryImpl(new NullStatsReporter())));
new Metrics(new InMemoryMetricsFactory()));
assertTrue(sampler instanceof ProbabilisticSampler);
}

Expand All @@ -369,7 +368,7 @@ public void testRateLimitingSampler() {
SamplerConfiguration samplerConfiguration = new SamplerConfiguration()
.withType(RateLimitingSampler.TYPE);
Sampler sampler = samplerConfiguration.createSampler("name",
new Metrics(new StatsFactoryImpl(new NullStatsReporter())));
new Metrics(new InMemoryMetricsFactory()));
assertTrue(sampler instanceof RateLimitingSampler);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ public void setUp() throws Exception {
mgr = mock(DefaultBaggageRestrictionManager.class);
setter = new BaggageSetter(mgr, metrics);
tracer =
new Tracer.Builder(SERVICE, reporter, new ConstSampler(true))
new Tracer.Builder(SERVICE)
.withReporter(reporter)
.withSampler(new ConstSampler(true))
.withMetrics(metrics)
.build();
span = (Span) tracer.buildSpan("some-operation").startManual();
Expand Down Expand Up @@ -103,7 +105,9 @@ public void testOverrideBaggage() {
@Test
public void testUnsampledSpan() {
tracer =
new Tracer.Builder("SamplerTest", reporter, new ConstSampler(false))
new Tracer.Builder(SERVICE)
.withReporter(reporter)
.withSampler(new ConstSampler(false))
.withMetrics(metrics)
.build();
span = (Span) tracer.buildSpan("some-operation").startManual();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

import io.jaegertracing.baggage.http.BaggageRestrictionResponse;
import io.jaegertracing.exceptions.BaggageRestrictionManagerException;
import io.jaegertracing.metrics.InMemoryStatsReporter;
import io.jaegertracing.metrics.InMemoryMetricsFactory;
import io.jaegertracing.metrics.Metrics;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand All @@ -36,7 +37,7 @@
public class RemoteBaggageRestrictionManagerTest {
@Mock private BaggageRestrictionManagerProxy baggageRestrictionProxy;
private Metrics metrics;
private InMemoryStatsReporter metricsReporter;
private InMemoryMetricsFactory metricsFactory;
private static final String SERVICE_NAME = "service";
private static final String BAGGAGE_KEY = "key";
private static final int MAX_VALUE_LENGTH = 10;
Expand All @@ -47,8 +48,8 @@ public class RemoteBaggageRestrictionManagerTest {

@Before
public void setUp() throws Exception {
metricsReporter = new InMemoryStatsReporter();
metrics = Metrics.fromStatsReporter(metricsReporter);
metricsFactory = new InMemoryMetricsFactory();
metrics = new Metrics(metricsFactory);
undertest = new RemoteBaggageRestrictionManager(SERVICE_NAME, baggageRestrictionProxy, metrics,
false);
}
Expand All @@ -67,7 +68,8 @@ public void testUpdateBaggageRestrictions() throws Exception {
assertEquals(Restriction.of(true, MAX_VALUE_LENGTH), undertest.getRestriction(SERVICE_NAME, BAGGAGE_KEY));
assertFalse(undertest.getRestriction(SERVICE_NAME, "bad-key").isKeyAllowed());
assertTrue(
metricsReporter.counters.get("jaeger:baggage_restrictions_updates.result=ok") > 0L);
metricsFactory.getCounter("jaeger:baggage_restrictions_updates.result=ok",
Collections.emptyMap()) > 0L);
}

@Test
Expand All @@ -82,7 +84,8 @@ public void testAllowBaggageOnInitializationFailure() throws Exception {
assertFalse(undertest.isReady());
// If baggage restriction update fails, all baggage should still be allowed.
assertTrue(undertest.getRestriction(SERVICE_NAME, BAGGAGE_KEY).isKeyAllowed());
assertTrue(metricsReporter.counters.get("jaeger:baggage_restrictions_updates.result=err") > 0L);
assertTrue(metricsFactory.getCounter("jaeger:baggage_restrictions_updates.result=err",
Collections.emptyMap()) > 0L);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,12 @@ public void testFlushWhenQueueFull() {
@Test
public void testFlushUpdatesQueueLength() throws Exception {
int neverFlushInterval = Integer.MAX_VALUE;
reporter = new RemoteReporter(sender, neverFlushInterval, maxQueueSize, metrics);
reporter = new RemoteReporter.Builder()
.withSender(sender)
.withFlushInterval(neverFlushInterval)
.withMaxQueueSize(maxQueueSize)
.withMetrics(metrics)
.build();
tracer = new Tracer.Builder("test-remote-reporter", reporter, new ConstSampler(true))
.withMetrics(metrics)
.build();
Expand Down Expand Up @@ -242,7 +247,12 @@ public int flush() throws SenderException {
}
};

reporter = new RemoteReporter(sender, flushInterval, maxQueueSize, metrics);
reporter = new RemoteReporter.Builder()
.withSender(sender)
.withFlushInterval(flushInterval)
.withMaxQueueSize(maxQueueSize)
.withMetrics(metrics)
.build();
tracer =
new Tracer.Builder("test-remote-reporter", reporter, new ConstSampler(true))
.withMetrics(metrics)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static org.mockito.Mockito.when;

import io.jaegertracing.exceptions.SamplingStrategyErrorException;
import io.jaegertracing.metrics.InMemoryStatsReporter;
import io.jaegertracing.metrics.InMemoryMetricsFactory;
import io.jaegertracing.metrics.Metrics;
import io.jaegertracing.samplers.http.OperationSamplingParameters;
import io.jaegertracing.samplers.http.PerOperationSamplingParameters;
Expand All @@ -49,8 +49,12 @@ public class RemoteControlledSamplerTest {

@Before
public void setUp() throws Exception {
metrics = Metrics.fromStatsReporter(new InMemoryStatsReporter());
undertest = new RemoteControlledSampler(SERVICE_NAME, samplingManager, initialSampler, metrics);
metrics = new Metrics(new InMemoryMetricsFactory());
undertest = new RemoteControlledSampler.Builder(SERVICE_NAME)
.withSamplingManager(samplingManager)
.withInitialSampler(initialSampler)
.withMetrics(metrics)
.build();
}

@After
Expand Down Expand Up @@ -105,7 +109,12 @@ public void testUpdatePerOperationSamplerUpdatesExistingPerOperationSampler() th
OperationSamplingParameters parameters = mock(OperationSamplingParameters.class);
when(samplingManager.getSamplingStrategy(SERVICE_NAME)).thenReturn(
new SamplingStrategyResponse(null, null, parameters));
undertest = new RemoteControlledSampler(SERVICE_NAME, samplingManager, perOperationSampler, metrics);
undertest = new RemoteControlledSampler.Builder(SERVICE_NAME)
.withSamplingManager(samplingManager)
.withInitialSampler(perOperationSampler)
.withMetrics(metrics)
.build();


undertest.updateSampler();
Thread.sleep(20);
Expand Down Expand Up @@ -135,8 +144,11 @@ public void testSample() throws Exception {

@Test
public void testEquals() {
RemoteControlledSampler i2 = new RemoteControlledSampler(SERVICE_NAME, samplingManager,
mock(Sampler.class), metrics);
RemoteControlledSampler i2 = new RemoteControlledSampler.Builder(SERVICE_NAME)
.withSamplingManager(samplingManager)
.withInitialSampler(mock(Sampler.class))
.withMetrics(metrics)
.build();

assertEquals(undertest, undertest);
assertNotEquals(undertest, initialSampler);
Expand All @@ -146,7 +158,13 @@ public void testEquals() {

@Test
public void testDefaultProbabilisticSampler() {
undertest = new RemoteControlledSampler(SERVICE_NAME, samplingManager, null, metrics);
undertest = new RemoteControlledSampler.Builder(SERVICE_NAME)
.withSamplingManager(samplingManager)
.withInitialSampler(null)
.withMetrics(metrics)
.build();


assertEquals(new ProbabilisticSampler(0.001), undertest.getSampler());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ protected Application configure() {
public void sendHappy() throws Exception {
new HttpSender(target("/api/traces").getUri().toString())
.send(new Process("robotrock"), generateSpans());
new HttpSender(target("/api/traces").getUri().toString(), 6500)
new HttpSender.Builder(target("/api/traces").getUri().toString()).withMaxPacketSize(6500).build()
.send(new Process("name"), generateSpans());
new HttpSender(target("/api/traces").getUri().toString(), 6500, new OkHttpClient())
new HttpSender.Builder(target("/api/traces").getUri().toString()).withMaxPacketSize(6500)
.withClient(new OkHttpClient()).build()
.send(new Process("name"), generateSpans());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.jaegertracing.Span;
import io.jaegertracing.Tracer;
import io.jaegertracing.exceptions.SenderException;
import io.jaegertracing.metrics.InMemoryStatsReporter;
import io.jaegertracing.metrics.InMemoryMetricsFactory;
import io.jaegertracing.reporters.InMemoryReporter;
import io.jaegertracing.reporters.Reporter;
import io.jaegertracing.reporters.protocols.JaegerThriftSpanConverter;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void setUp() throws Exception {
reporter = new InMemoryReporter();
tracer =
new Tracer.Builder(SERVICE_NAME, reporter, new ConstSampler(true))
.withStatsReporter(new InMemoryStatsReporter())
.withMetricsFactory(new InMemoryMetricsFactory())
.withTag("foo", "bar")
.build();
sender = new UdpSender(destHost, destPort, maxPacketSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,36 @@ public EndToEndBehavior(Map<String, Tracer> tracers) {

public EndToEndBehavior(String samplingHostPort, String serviceName, Sender sender) {
Metrics metrics = new Metrics(new NoopMetricsFactory());
Reporter reporter = new RemoteReporter(sender, 1000, 100, metrics);
Reporter reporter = new RemoteReporter.Builder()
.withSender(sender)
.withFlushInterval(1000)
.withMaxQueueSize(100)
.withMetrics(metrics)
.build();

ConstSampler constSampler = new ConstSampler(true);

tracers = new HashMap<>();
tracers.put(RemoteControlledSampler.TYPE, getRemoteTracer(metrics, reporter, serviceName, samplingHostPort));
tracers.put(ConstSampler.TYPE, new io.jaegertracing.Tracer.Builder(serviceName, reporter, constSampler).build());
tracers.put(ConstSampler.TYPE,
new io.jaegertracing.Tracer.Builder(serviceName).withReporter(reporter).withSampler(constSampler).build());
}

private Tracer getRemoteTracer(Metrics metrics, Reporter reporter, String serviceName, String samplingHostPort) {
Sampler initialSampler = new ProbabilisticSampler(1.0);
HttpSamplingManager manager = new HttpSamplingManager(samplingHostPort);

RemoteControlledSampler remoteSampler = new RemoteControlledSampler(serviceName, manager, initialSampler,
metrics, 5000);
RemoteControlledSampler remoteSampler = new RemoteControlledSampler.Builder(serviceName)
.withSamplingManager(manager)
.withInitialSampler(initialSampler)
.withMetrics(metrics)
.withPollingInterval(5000)
.build();

io.jaegertracing.Tracer.Builder remoteTracerBuilder = new io.jaegertracing.Tracer.Builder(serviceName, reporter,
remoteSampler);
return remoteTracerBuilder.build();
return new io.jaegertracing.Tracer.Builder(serviceName)
.withReporter(reporter)
.withSampler(remoteSampler)
.build();
}

public void generateTraces(CreateTracesRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.jaegertracing.SpanContext;
import io.jaegertracing.Tracer;
import io.jaegertracing.exceptions.SenderException;
import io.jaegertracing.metrics.InMemoryStatsReporter;
import io.jaegertracing.metrics.InMemoryMetricsFactory;
import io.jaegertracing.reporters.InMemoryReporter;
import io.jaegertracing.reporters.Reporter;
import io.jaegertracing.samplers.ConstSampler;
Expand Down Expand Up @@ -56,7 +56,7 @@ public void setUp() throws Exception {
reporter = new InMemoryReporter();
tracer =
new Tracer.Builder("test-sender", reporter, new ConstSampler(true))
.withStatsReporter(new InMemoryStatsReporter())
.withMetricsFactory(new InMemoryMetricsFactory())
.build();
sender = newSender(messageMaxBytes);
converter = new ThriftSpanConverter();
Expand Down