From 13e2de7f9aef91052ea94536b87eabc7a5a45be7 Mon Sep 17 00:00:00 2001 From: Pavol Loffay Date: Tue, 15 May 2018 18:59:08 +0200 Subject: [PATCH] Do not use deprecated APIs internally Signed-off-by: Pavol Loffay --- .../reporters/RemoteReporter.java | 5 ++- .../samplers/RemoteControlledSampler.java | 5 ++- .../io/jaegertracing/ConfigurationTest.java | 35 +++++++++---------- .../baggage/BaggageSetterTest.java | 8 +++-- .../RemoteBaggageRestrictionManagerTest.java | 15 ++++---- .../reporters/RemoteReporterTest.java | 14 ++++++-- .../samplers/RemoteControlledSamplerTest.java | 32 +++++++++++++---- .../jaegertracing/senders/HttpSenderTest.java | 5 +-- .../jaegertracing/senders/UdpSenderTest.java | 4 +-- .../resources/behavior/EndToEndBehavior.java | 25 +++++++++---- .../senders/zipkin/ZipkinSenderTest.java | 4 +-- 11 files changed, 98 insertions(+), 54 deletions(-) diff --git a/jaeger-core/src/main/java/io/jaegertracing/reporters/RemoteReporter.java b/jaeger-core/src/main/java/io/jaegertracing/reporters/RemoteReporter.java index 625183db0..df6304ff1 100644 --- a/jaeger-core/src/main/java/io/jaegertracing/reporters/RemoteReporter.java +++ b/jaeger-core/src/main/java/io/jaegertracing/reporters/RemoteReporter.java @@ -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; @@ -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); } diff --git a/jaeger-core/src/main/java/io/jaegertracing/samplers/RemoteControlledSampler.java b/jaeger-core/src/main/java/io/jaegertracing/samplers/RemoteControlledSampler.java index df193a11b..6e0978cb0 100644 --- a/jaeger-core/src/main/java/io/jaegertracing/samplers/RemoteControlledSampler.java +++ b/jaeger-core/src/main/java/io/jaegertracing/samplers/RemoteControlledSampler.java @@ -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; @@ -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); } diff --git a/jaeger-core/src/test/java/io/jaegertracing/ConfigurationTest.java b/jaeger-core/src/test/java/io/jaegertracing/ConfigurationTest.java index 073197325..5e1448037 100644 --- a/jaeger-core/src/test/java/io/jaegertracing/ConfigurationTest.java +++ b/jaeger-core/src/test/java/io/jaegertracing/ConfigurationTest.java @@ -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; @@ -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()); } @@ -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 @@ -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); } @@ -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); } @@ -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); } @@ -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); } diff --git a/jaeger-core/src/test/java/io/jaegertracing/baggage/BaggageSetterTest.java b/jaeger-core/src/test/java/io/jaegertracing/baggage/BaggageSetterTest.java index cefcc97e5..2626021a8 100644 --- a/jaeger-core/src/test/java/io/jaegertracing/baggage/BaggageSetterTest.java +++ b/jaeger-core/src/test/java/io/jaegertracing/baggage/BaggageSetterTest.java @@ -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(); @@ -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(); diff --git a/jaeger-core/src/test/java/io/jaegertracing/baggage/RemoteBaggageRestrictionManagerTest.java b/jaeger-core/src/test/java/io/jaegertracing/baggage/RemoteBaggageRestrictionManagerTest.java index 15c4c22a3..606d84be9 100644 --- a/jaeger-core/src/test/java/io/jaegertracing/baggage/RemoteBaggageRestrictionManagerTest.java +++ b/jaeger-core/src/test/java/io/jaegertracing/baggage/RemoteBaggageRestrictionManagerTest.java @@ -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; @@ -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; @@ -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); } @@ -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 @@ -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 diff --git a/jaeger-core/src/test/java/io/jaegertracing/reporters/RemoteReporterTest.java b/jaeger-core/src/test/java/io/jaegertracing/reporters/RemoteReporterTest.java index bfe06cc19..f6a0fb065 100644 --- a/jaeger-core/src/test/java/io/jaegertracing/reporters/RemoteReporterTest.java +++ b/jaeger-core/src/test/java/io/jaegertracing/reporters/RemoteReporterTest.java @@ -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(); @@ -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) diff --git a/jaeger-core/src/test/java/io/jaegertracing/samplers/RemoteControlledSamplerTest.java b/jaeger-core/src/test/java/io/jaegertracing/samplers/RemoteControlledSamplerTest.java index 4994b605e..77d6d86d2 100644 --- a/jaeger-core/src/test/java/io/jaegertracing/samplers/RemoteControlledSamplerTest.java +++ b/jaeger-core/src/test/java/io/jaegertracing/samplers/RemoteControlledSamplerTest.java @@ -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; @@ -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 @@ -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); @@ -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); @@ -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()); } diff --git a/jaeger-core/src/test/java/io/jaegertracing/senders/HttpSenderTest.java b/jaeger-core/src/test/java/io/jaegertracing/senders/HttpSenderTest.java index 786a6e488..0ee35ae64 100644 --- a/jaeger-core/src/test/java/io/jaegertracing/senders/HttpSenderTest.java +++ b/jaeger-core/src/test/java/io/jaegertracing/senders/HttpSenderTest.java @@ -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()); } diff --git a/jaeger-core/src/test/java/io/jaegertracing/senders/UdpSenderTest.java b/jaeger-core/src/test/java/io/jaegertracing/senders/UdpSenderTest.java index fd952b967..29b3c1650 100644 --- a/jaeger-core/src/test/java/io/jaegertracing/senders/UdpSenderTest.java +++ b/jaeger-core/src/test/java/io/jaegertracing/senders/UdpSenderTest.java @@ -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; @@ -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); diff --git a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/EndToEndBehavior.java b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/EndToEndBehavior.java index b6caaca74..b7f11b24d 100644 --- a/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/EndToEndBehavior.java +++ b/jaeger-crossdock/src/main/java/io/jaegertracing/crossdock/resources/behavior/EndToEndBehavior.java @@ -40,25 +40,36 @@ public EndToEndBehavior(Map 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) { diff --git a/jaeger-zipkin/src/test/java/io/jaegertracing/senders/zipkin/ZipkinSenderTest.java b/jaeger-zipkin/src/test/java/io/jaegertracing/senders/zipkin/ZipkinSenderTest.java index dfe16dd42..b697c8951 100644 --- a/jaeger-zipkin/src/test/java/io/jaegertracing/senders/zipkin/ZipkinSenderTest.java +++ b/jaeger-zipkin/src/test/java/io/jaegertracing/senders/zipkin/ZipkinSenderTest.java @@ -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; @@ -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();