@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); }
void updateSampler() { 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); } }
RemoteControlledSampler implements Sampler { void updateSampler() { 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); } } }
RemoteControlledSampler implements Sampler { void updateSampler() { 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); } } private  RemoteControlledSampler(Builder builder); }
RemoteControlledSampler implements Sampler { void updateSampler() { 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); } } private  RemoteControlledSampler(Builder builder); @Override SamplingStatus sample(String operation, long id); @Override boolean equals(Object sampler); @Override void close(); }
RemoteControlledSampler implements Sampler { void updateSampler() { 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); } } private  RemoteControlledSampler(Builder builder); @Override SamplingStatus sample(String operation, long id); @Override boolean equals(Object sampler); @Override void close(); static final String TYPE; }