Search in sources :

Example 1 with PerOperationSamplingParameters

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

the class HttpSamplingManagerTest method testParsePerOperationSampling.

@Test
public void testParsePerOperationSampling() throws Exception {
    SamplingStrategyResponse response = undertest.parseJson(readFixture("per_operation_sampling.json"));
    OperationSamplingParameters actual = response.getOperationSampling();
    assertEquals(0.001, actual.getDefaultSamplingProbability(), 0.0001);
    assertEquals(0.001666, actual.getDefaultLowerBoundTracesPerSecond(), 0.0001);
    List<PerOperationSamplingParameters> actualPerOperationStrategies = actual.getPerOperationStrategies();
    assertEquals(2, actualPerOperationStrategies.size());
    assertEquals(new PerOperationSamplingParameters("GET:/search", new ProbabilisticSamplingStrategy(1.0)), actualPerOperationStrategies.get(0));
    assertEquals(new PerOperationSamplingParameters("PUT:/pacifique", new ProbabilisticSamplingStrategy(0.8258308134813166)), actualPerOperationStrategies.get(1));
}
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) ProbabilisticSamplingStrategy(io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 2 with PerOperationSamplingParameters

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

the class PerOperationSamplerTest method testAbsentOperationIsRemoved.

@Test
public void testAbsentOperationIsRemoved() {
    String absentOp = "ShouldBeRemoved";
    operationToSamplers.put(absentOp, mock(GuaranteedThroughputSampler.class));
    PerOperationSamplingParameters perOperationSamplingParameters1 = new PerOperationSamplingParameters(OPERATION, new ProbabilisticSamplingStrategy(SAMPLING_RATE));
    List<PerOperationSamplingParameters> parametersList = new ArrayList<>();
    parametersList.add(perOperationSamplingParameters1);
    undertest.update(new OperationSamplingParameters(DEFAULT_SAMPLING_PROBABILITY, DEFAULT_LOWER_BOUND_TRACES_PER_SECOND, parametersList));
    assertEquals(1, undertest.getOperationNameToSampler().size());
    assertEquals(new GuaranteedThroughputSampler(SAMPLING_RATE, DEFAULT_LOWER_BOUND_TRACES_PER_SECOND), undertest.getOperationNameToSampler().get(OPERATION));
    assertFalse(undertest.getOperationNameToSampler().containsKey(absentOp));
}
Also used : PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) OperationSamplingParameters(io.jaegertracing.internal.samplers.http.OperationSamplingParameters) PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) ArrayList(java.util.ArrayList) ProbabilisticSamplingStrategy(io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy) Test(org.junit.Test)

Example 3 with PerOperationSamplingParameters

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

the class PerOperationSampler method update.

/**
 * Updates the GuaranteedThroughputSampler for each operation
 * @param strategies The parameters for operation sampling
 * @return true if any samplers were updated
 */
public synchronized boolean update(final OperationSamplingParameters strategies) {
    boolean isUpdated = false;
    lowerBound = strategies.getDefaultLowerBoundTracesPerSecond();
    ProbabilisticSampler defaultSampler = new ProbabilisticSampler(strategies.getDefaultSamplingProbability());
    if (!defaultSampler.equals(this.defaultSampler)) {
        this.defaultSampler = defaultSampler;
        isUpdated = true;
    }
    Map<String, GuaranteedThroughputSampler> newOpsSamplers = new HashMap<String, GuaranteedThroughputSampler>();
    // add or update operation samples using given strategies
    for (PerOperationSamplingParameters strategy : strategies.getPerOperationStrategies()) {
        String operation = strategy.getOperation();
        double samplingRate = strategy.getProbabilisticSampling().getSamplingRate();
        GuaranteedThroughputSampler sampler = operationNameToSampler.get(operation);
        if (sampler != null) {
            isUpdated = sampler.update(samplingRate, lowerBound) || isUpdated;
            newOpsSamplers.put(operation, sampler);
        } else {
            if (newOpsSamplers.size() < maxOperations) {
                sampler = new GuaranteedThroughputSampler(samplingRate, lowerBound);
                newOpsSamplers.put(operation, sampler);
                isUpdated = true;
            } else {
                log.info("Exceeded the maximum number of operations({}) for per operations sampling", maxOperations);
            }
        }
    }
    operationNameToSampler = newOpsSamplers;
    return isUpdated;
}
Also used : PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) HashMap(java.util.HashMap) ToString(lombok.ToString)

Example 4 with PerOperationSamplingParameters

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

the class PerOperationSamplerTest method testUpdateIgnoreGreaterThanMax.

@Test
public void testUpdateIgnoreGreaterThanMax() {
    GuaranteedThroughputSampler guaranteedThroughputSampler = mock(GuaranteedThroughputSampler.class);
    operationToSamplers.put(OPERATION, guaranteedThroughputSampler);
    PerOperationSampler undertest = new PerOperationSampler(1, operationToSamplers, defaultProbabilisticSampler, DEFAULT_LOWER_BOUND_TRACES_PER_SECOND);
    PerOperationSamplingParameters perOperationSamplingParameters1 = new PerOperationSamplingParameters(OPERATION, new ProbabilisticSamplingStrategy(SAMPLING_RATE));
    PerOperationSamplingParameters perOperationSamplingParameters2 = new PerOperationSamplingParameters("second OPERATION", new ProbabilisticSamplingStrategy(SAMPLING_RATE));
    List<PerOperationSamplingParameters> parametersList = new ArrayList<>();
    parametersList.add(perOperationSamplingParameters1);
    parametersList.add(perOperationSamplingParameters2);
    undertest.update(new OperationSamplingParameters(DEFAULT_SAMPLING_PROBABILITY, DEFAULT_LOWER_BOUND_TRACES_PER_SECOND, parametersList));
    assertEquals(1, undertest.getOperationNameToSampler().size());
    assertNotNull(undertest.getOperationNameToSampler().get(OPERATION));
}
Also used : PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) OperationSamplingParameters(io.jaegertracing.internal.samplers.http.OperationSamplingParameters) PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) ArrayList(java.util.ArrayList) ProbabilisticSamplingStrategy(io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy) Test(org.junit.Test)

Example 5 with PerOperationSamplingParameters

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

the class PerOperationSamplerTest method testUpdateAddOperation.

@Test
public void testUpdateAddOperation() {
    PerOperationSamplingParameters perOperationSamplingParameters1 = new PerOperationSamplingParameters(OPERATION, new ProbabilisticSamplingStrategy(SAMPLING_RATE));
    List<PerOperationSamplingParameters> parametersList = new ArrayList<>();
    parametersList.add(perOperationSamplingParameters1);
    undertest.update(new OperationSamplingParameters(DEFAULT_SAMPLING_PROBABILITY, DEFAULT_LOWER_BOUND_TRACES_PER_SECOND, parametersList));
    assertEquals(1, undertest.getOperationNameToSampler().size());
    assertEquals(new GuaranteedThroughputSampler(SAMPLING_RATE, DEFAULT_LOWER_BOUND_TRACES_PER_SECOND), undertest.getOperationNameToSampler().get(OPERATION));
}
Also used : PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) OperationSamplingParameters(io.jaegertracing.internal.samplers.http.OperationSamplingParameters) PerOperationSamplingParameters(io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters) ArrayList(java.util.ArrayList) ProbabilisticSamplingStrategy(io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy) Test(org.junit.Test)

Aggregations

PerOperationSamplingParameters (io.jaegertracing.internal.samplers.http.PerOperationSamplingParameters)8 OperationSamplingParameters (io.jaegertracing.internal.samplers.http.OperationSamplingParameters)7 ProbabilisticSamplingStrategy (io.jaegertracing.internal.samplers.http.ProbabilisticSamplingStrategy)7 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 SamplingStrategyResponse (io.jaegertracing.internal.samplers.http.SamplingStrategyResponse)2 Sampler (io.jaegertracing.spi.Sampler)1 HashMap (java.util.HashMap)1 ToString (lombok.ToString)1 JerseyTest (org.glassfish.jersey.test.JerseyTest)1