Search in sources :

Example 6 with SamplingStrategyResponse

use of io.jaegertracing.internal.samplers.http.SamplingStrategyResponse in project jaeger-client-java by jaegertracing.

the class RemoteControlledSampler method updateSampler.

/**
 * Updates {@link #sampler} to a new sampler when it is different.
 */
void updateSampler() {
    // visible for testing
    SamplingStrategyResponse response;
    try {
        response = manager.getSamplingStrategy(serviceName);
        metrics.samplerRetrieved.inc(1);
    } catch (SamplingStrategyErrorException e) {
        metrics.samplerQueryFailure.inc(1);
        return;
    }
    if (response.getOperationSampling() != null) {
        updatePerOperationSampler(response.getOperationSampling());
    } else {
        updateRateLimitingOrProbabilisticSampler(response);
    }
}
Also used : SamplingStrategyResponse(io.jaegertracing.internal.samplers.http.SamplingStrategyResponse) SamplingStrategyErrorException(io.jaegertracing.internal.exceptions.SamplingStrategyErrorException)

Example 7 with SamplingStrategyResponse

use of io.jaegertracing.internal.samplers.http.SamplingStrategyResponse in project jaeger-client-java by jaegertracing.

the class RemoteControlledSamplerTest method testNullResponse.

@Test
public void testNullResponse() throws Exception {
    when(samplingManager.getSamplingStrategy(SERVICE_NAME)).thenReturn(new SamplingStrategyResponse(null, null, null));
    undertest.updateSampler();
    assertEquals(initialSampler, undertest.getSampler());
}
Also used : SamplingStrategyResponse(io.jaegertracing.internal.samplers.http.SamplingStrategyResponse) Test(org.junit.Test)

Example 8 with SamplingStrategyResponse

use of io.jaegertracing.internal.samplers.http.SamplingStrategyResponse in project jaeger-client-java by jaegertracing.

the class RemoteControlledSamplerTest method testUpdateToPerOperationSamplerReplacesProbabilisticSampler.

@Test
public void testUpdateToPerOperationSamplerReplacesProbabilisticSampler() throws Exception {
    List<PerOperationSamplingParameters> operationToSampler = new ArrayList<>();
    operationToSampler.add(new PerOperationSamplingParameters("operation", new ProbabilisticSamplingStrategy(0.1)));
    OperationSamplingParameters parameters = new OperationSamplingParameters(0.11, 0.22, operationToSampler);
    SamplingStrategyResponse response = new SamplingStrategyResponse(null, null, parameters);
    when(samplingManager.getSamplingStrategy(SERVICE_NAME)).thenReturn(response);
    undertest.updateSampler();
    PerOperationSampler perOperationSampler = new PerOperationSampler(2000, parameters);
    Sampler actualSampler = undertest.getSampler();
    assertEquals(perOperationSampler, actualSampler);
}
Also used : SamplingStrategyResponse(io.jaegertracing.internal.samplers.http.SamplingStrategyResponse) PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) OperationSamplingParameters(io.jaegertracing.internal.samplers.http.OperationSamplingParameters) PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) Sampler(io.jaegertracing.spi.Sampler) ArrayList(java.util.ArrayList) ProbabilisticSamplingStrategy(io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy) Test(org.junit.Test)

Example 9 with SamplingStrategyResponse

use of io.jaegertracing.internal.samplers.http.SamplingStrategyResponse in project jaeger-client-java by jaegertracing.

the class RemoteControlledSamplerTest method testUpdatePerOperationSamplerUpdatesExistingPerOperationSampler.

@Test
public void testUpdatePerOperationSamplerUpdatesExistingPerOperationSampler() throws Exception {
    undertest.close();
    PerOperationSampler perOperationSampler = mock(PerOperationSampler.class);
    OperationSamplingParameters parameters = mock(OperationSamplingParameters.class);
    when(samplingManager.getSamplingStrategy(SERVICE_NAME)).thenReturn(new SamplingStrategyResponse(null, null, parameters));
    undertest = new RemoteControlledSampler.Builder(SERVICE_NAME).withSamplingManager(samplingManager).withInitialSampler(perOperationSampler).withMetrics(metrics).build();
    undertest.updateSampler();
    Thread.sleep(20);
    // updateSampler is hit once automatically because of the pollTimer
    verify(perOperationSampler, times(2)).update(parameters);
}
Also used : SamplingStrategyResponse(io.jaegertracing.internal.samplers.http.SamplingStrategyResponse) OperationSamplingParameters(io.jaegertracing.internal.samplers.http.OperationSamplingParameters) PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) Test(org.junit.Test)

Example 10 with SamplingStrategyResponse

use of io.jaegertracing.internal.samplers.http.SamplingStrategyResponse in project jaeger-client-java by jaegertracing.

the class HttpSamplingManagerTest method testParseRateLimitingSampling.

@Test
public void testParseRateLimitingSampling() throws Exception {
    SamplingStrategyResponse response = undertest.parseJson(readFixture("ratelimiting_sampling.json"));
    assertEquals(new RateLimitingSamplingStrategy(2.1), response.getRateLimitingSampling());
    assertNull(response.getProbabilisticSampling());
}
Also used : SamplingStrategyResponse(io.jaegertracing.internal.samplers.http.SamplingStrategyResponse) RateLimitingSamplingStrategy(io.jaegertracing.internal.samplers.http.RateLimitingSamplingStrategy) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

SamplingStrategyResponse (io.jaegertracing.internal.samplers.http.SamplingStrategyResponse)10 Test (org.junit.Test)9 ProbabilisticSamplingStrategy (io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy)4 JerseyTest (org.glassfish.jersey.test.JerseyTest)4 OperationSamplingParameters (io.jaegertracing.internal.samplers.http.OperationSamplingParameters)3 PerOperationSamplingParameters (io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters)3 RateLimitingSamplingStrategy (io.jaegertracing.internal.samplers.http.RateLimitingSamplingStrategy)2 SamplingStrategyErrorException (io.jaegertracing.internal.exceptions.SamplingStrategyErrorException)1 Sampler (io.jaegertracing.spi.Sampler)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1