Search in sources :

Example 6 with Sampler

use of io.jaegertracing.spi.Sampler in project jaeger-client-java by jaegertracing.

the class MicrometerTest method validateMetricCounts.

@Test
public void validateMetricCounts() throws InterruptedException {
    Sampler constantSampler = new ConstSampler(true);
    Configuration configuration = new Configuration("validateMetricCounts");
    JaegerTracer tracer = configuration.getTracerBuilder().withSampler(constantSampler).withMetrics(metrics).build();
    createSomeSpans(tracer);
    tracer.close();
    double finishedSpans = registry.get("jaeger_tracer_finished_spans").counter().count();
    double startedSpans = registry.get("jaeger_tracer_started_spans").tag("sampled", "y").counter().count();
    double traces = registry.get("jaeger_tracer_traces").tag("sampled", "y").tag("state", "started").counter().count();
    assertEquals("Wrong number of finishedSpans", 4.0, finishedSpans, assertDelta);
    assertEquals("Wrong number of startedSpans", 10.0, startedSpans, assertDelta);
    assertEquals("Wrong number of traces", 10.0, traces, assertDelta);
}
Also used : Configuration(io.jaegertracing.Configuration) Sampler(io.jaegertracing.spi.Sampler) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) JaegerTracer(io.jaegertracing.internal.JaegerTracer) Test(org.junit.Test)

Example 7 with Sampler

use of io.jaegertracing.spi.Sampler in project jaeger-client-java by jaegertracing.

the class RemoteControlledSampler method updateRateLimitingOrProbabilisticSampler.

/**
 * Replace {@link #sampler} with a new instance when parameters are updated.
 * @param response which contains either a {@link ProbabilisticSampler} or {@link RateLimitingSampler}
 */
private void updateRateLimitingOrProbabilisticSampler(SamplingStrategyResponse response) {
    Sampler sampler;
    if (response.getProbabilisticSampling() != null) {
        ProbabilisticSamplingStrategy strategy = response.getProbabilisticSampling();
        sampler = new ProbabilisticSampler(strategy.getSamplingRate());
    } else if (response.getRateLimitingSampling() != null) {
        RateLimitingSamplingStrategy strategy = response.getRateLimitingSampling();
        sampler = new RateLimitingSampler(strategy.getMaxTracesPerSecond());
    } else {
        metrics.samplerParsingFailure.inc(1);
        log.error("No strategy present in response. Not updating sampler.");
        return;
    }
    if (!this.sampler.equals(sampler)) {
        this.sampler = sampler;
        metrics.samplerUpdated.inc(1);
    }
}
Also used : Sampler(io.jaegertracing.spi.Sampler) ProbabilisticSamplingStrategy(io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy) RateLimitingSamplingStrategy(io.jaegertracing.internal.samplers.http.RateLimitingSamplingStrategy)

Example 8 with Sampler

use of io.jaegertracing.spi.Sampler in project jaeger-client-java by jaegertracing.

the class ConfigurationTest method testProbabilisticSampler.

@Test
public void testProbabilisticSampler() {
    SamplerConfiguration samplerConfiguration = new SamplerConfiguration().withType(ProbabilisticSampler.TYPE);
    Sampler sampler = samplerConfiguration.createSampler("name", new Metrics(new InMemoryMetricsFactory()));
    assertTrue(sampler instanceof ProbabilisticSampler);
}
Also used : Metrics(io.jaegertracing.internal.metrics.Metrics) InMemoryMetricsFactory(io.jaegertracing.internal.metrics.InMemoryMetricsFactory) Sampler(io.jaegertracing.spi.Sampler) RateLimitingSampler(io.jaegertracing.internal.samplers.RateLimitingSampler) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) ProbabilisticSampler(io.jaegertracing.internal.samplers.ProbabilisticSampler) SamplerConfiguration(io.jaegertracing.Configuration.SamplerConfiguration) ProbabilisticSampler(io.jaegertracing.internal.samplers.ProbabilisticSampler) Test(org.junit.Test)

Example 9 with Sampler

use of io.jaegertracing.spi.Sampler in project jaeger-client-java by jaegertracing.

the class ConfigurationTest method testRateLimitingSampler.

@Test
public void testRateLimitingSampler() {
    SamplerConfiguration samplerConfiguration = new SamplerConfiguration().withType(RateLimitingSampler.TYPE);
    Sampler sampler = samplerConfiguration.createSampler("name", new Metrics(new InMemoryMetricsFactory()));
    assertTrue(sampler instanceof RateLimitingSampler);
}
Also used : RateLimitingSampler(io.jaegertracing.internal.samplers.RateLimitingSampler) Metrics(io.jaegertracing.internal.metrics.Metrics) InMemoryMetricsFactory(io.jaegertracing.internal.metrics.InMemoryMetricsFactory) Sampler(io.jaegertracing.spi.Sampler) RateLimitingSampler(io.jaegertracing.internal.samplers.RateLimitingSampler) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) ProbabilisticSampler(io.jaegertracing.internal.samplers.ProbabilisticSampler) SamplerConfiguration(io.jaegertracing.Configuration.SamplerConfiguration) Test(org.junit.Test)

Example 10 with Sampler

use of io.jaegertracing.spi.Sampler in project jaeger-client-java by jaegertracing.

the class JaegerTracerTest method testClose.

@Test
public void testClose() {
    Reporter reporter = mock(Reporter.class);
    Sampler sampler = mock(Sampler.class);
    tracer = new JaegerTracer.Builder("bonda").withReporter(reporter).withSampler(sampler).build();
    tracer.close();
    verify(reporter).close();
    verify(sampler).close();
}
Also used : Reporter(io.jaegertracing.spi.Reporter) RemoteReporter(io.jaegertracing.internal.reporters.RemoteReporter) InMemoryReporter(io.jaegertracing.internal.reporters.InMemoryReporter) Sampler(io.jaegertracing.spi.Sampler) ConstSampler(io.jaegertracing.internal.samplers.ConstSampler) Builder(io.jaegertracing.internal.JaegerTracer.Builder) Test(org.junit.Test)

Aggregations

Sampler (io.jaegertracing.spi.Sampler)12 Test (org.junit.Test)8 ConstSampler (io.jaegertracing.internal.samplers.ConstSampler)7 ProbabilisticSampler (io.jaegertracing.internal.samplers.ProbabilisticSampler)5 Metrics (io.jaegertracing.internal.metrics.Metrics)4 RateLimitingSampler (io.jaegertracing.internal.samplers.RateLimitingSampler)4 SamplerConfiguration (io.jaegertracing.Configuration.SamplerConfiguration)3 JaegerTracer (io.jaegertracing.internal.JaegerTracer)3 InMemoryMetricsFactory (io.jaegertracing.internal.metrics.InMemoryMetricsFactory)3 RemoteReporter (io.jaegertracing.internal.reporters.RemoteReporter)2 RemoteControlledSampler (io.jaegertracing.internal.samplers.RemoteControlledSampler)2 ProbabilisticSamplingStrategy (io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy)2 Reporter (io.jaegertracing.spi.Reporter)2 Configuration (io.jaegertracing.Configuration)1 Builder (io.jaegertracing.internal.JaegerTracer.Builder)1 CompositeReporter (io.jaegertracing.internal.reporters.CompositeReporter)1 InMemoryReporter (io.jaegertracing.internal.reporters.InMemoryReporter)1 LoggingReporter (io.jaegertracing.internal.reporters.LoggingReporter)1 HttpSamplingManager (io.jaegertracing.internal.samplers.HttpSamplingManager)1 OperationSamplingParameters (io.jaegertracing.internal.samplers.http.OperationSamplingParameters)1