def test_update_sampler_adaptive_sampler(): error_reporter = mock.MagicMock() error_reporter.error = mock.MagicMock() remote_sampler = RemoteControlledSampler( channel=mock.MagicMock(), service_name='x', error_reporter=error_reporter, max_operations=10, ) response = { "strategyType":"RATE_LIMITING", "operationSampling": { "defaultSamplingProbability":0.001, "defaultLowerBoundTracesPerSecond":2, "perOperationStrategies": [ { "operation":"op", "probabilisticSampling":{ "samplingRate":0.002 } } ] } } remote_sampler._update_sampler(response) assert '%s' % remote_sampler.sampler == 'AdaptiveSampler(0.001000, 2.000000, 10)' new_response = { "strategyType":"RATE_LIMITING", "operationSampling": { "defaultSamplingProbability":0.51, "defaultLowerBoundTracesPerSecond":3, "perOperationStrategies": [ { "operation":"op", "probabilisticSampling":{ "samplingRate":0.002 } } ] } } remote_sampler._update_sampler(new_response) assert '%s' % remote_sampler.sampler == 'AdaptiveSampler(0.510000, 3.000000, 10)' remote_sampler._update_sampler({"strategyType":"PROBABILISTIC","probabilisticSampling":{"samplingRate":0.004}}) assert '%s' % remote_sampler.sampler == 'ProbabilisticSampler(0.004)', \ 'should not fail going from adaptive sampler to probabilistic sampler' remote_sampler._update_sampler({"strategyType":"RATE_LIMITING","operationSampling":{"defaultSamplingProbability":0.4}}) assert '%s' % remote_sampler.sampler == 'AdaptiveSampler(0.400000, 0.001667, 10)' remote_sampler.close()
def test_update_sampler(response, init_sampler, expected_sampler, err_count, err_msg, reference_equivalence, max_operations): error_reporter = mock.MagicMock() error_reporter.error = mock.MagicMock() remote_sampler = RemoteControlledSampler( channel=mock.MagicMock(), service_name='x', error_reporter=error_reporter, max_operations=max_operations, init_sampler=init_sampler, ) # noinspection PyProtectedMember remote_sampler._update_sampler(response) assert error_reporter.error.call_count == err_count if reference_equivalence: assert remote_sampler.sampler is expected_sampler, err_msg else: assert remote_sampler.sampler == expected_sampler, err_msg remote_sampler.close()
def test_update_sampler(response, init_sampler, expected_sampler, err_count, err_msg, reference_equivalence, max_operations): error_reporter = mock.MagicMock() error_reporter.error = mock.MagicMock() remote_sampler = RemoteControlledSampler( channel=mock.MagicMock(), service_name='x', error_reporter=error_reporter, max_operations=max_operations, init_sampler=init_sampler, ) # noinspection PyProtectedMember remote_sampler._update_sampler(response) assert error_reporter.error.call_count == err_count if reference_equivalence: assert remote_sampler.sampler is expected_sampler, err_msg else: assert remote_sampler.sampler == expected_sampler, err_msg remote_sampler.close()
def test_update_sampler_adaptive_sampler(): error_reporter = mock.MagicMock() error_reporter.error = mock.MagicMock() remote_sampler = RemoteControlledSampler( channel=mock.MagicMock(), service_name='x', error_reporter=error_reporter, max_operations=10, ) response = { 'strategyType': 'RATE_LIMITING', 'operationSampling': { 'defaultSamplingProbability': 0.001, 'defaultLowerBoundTracesPerSecond': 2, 'perOperationStrategies': [{ 'operation': 'op', 'probabilisticSampling': { 'samplingRate': 0.002 } }] } } remote_sampler._update_sampler(response) assert '%s' % remote_sampler.sampler == 'AdaptiveSampler(0.001000, 2.000000, 10)' new_response = { 'strategyType': 'RATE_LIMITING', 'operationSampling': { 'defaultSamplingProbability': 0.51, 'defaultLowerBoundTracesPerSecond': 3, 'perOperationStrategies': [{ 'operation': 'op', 'probabilisticSampling': { 'samplingRate': 0.002 } }] } } remote_sampler._update_sampler(new_response) assert '%s' % remote_sampler.sampler == 'AdaptiveSampler(0.510000, 3.000000, 10)' remote_sampler._update_sampler({ 'strategyType': 'PROBABILISTIC', 'probabilisticSampling': { 'samplingRate': 0.004 } }) assert '%s' % remote_sampler.sampler == 'ProbabilisticSampler(0.004)', \ 'should not fail going from adaptive sampler to probabilistic sampler' remote_sampler._update_sampler({ 'strategyType': 'RATE_LIMITING', 'operationSampling': { 'defaultSamplingProbability': 0.4 } }) assert '%s' % remote_sampler.sampler == 'AdaptiveSampler(0.400000, 0.001667, 10)' remote_sampler.close()
def test_update_sampler_adaptive_sampler(): error_reporter = mock.MagicMock() error_reporter.error = mock.MagicMock() remote_sampler = RemoteControlledSampler( channel=mock.MagicMock(), service_name='x', error_reporter=error_reporter, max_operations=10, ) response = { 'strategyType': 'RATE_LIMITING', 'operationSampling': { 'defaultSamplingProbability': 0.001, 'defaultLowerBoundTracesPerSecond': 2, 'perOperationStrategies': [ { 'operation': 'op', 'probabilisticSampling': { 'samplingRate': 0.002 } } ] } } remote_sampler._update_sampler(response) assert '%s' % remote_sampler.sampler == 'AdaptiveSampler(0.001000, 2.000000, 10)' new_response = { 'strategyType': 'RATE_LIMITING', 'operationSampling': { 'defaultSamplingProbability': 0.51, 'defaultLowerBoundTracesPerSecond': 3, 'perOperationStrategies': [ { 'operation': 'op', 'probabilisticSampling': { 'samplingRate': 0.002 } } ] } } remote_sampler._update_sampler(new_response) assert '%s' % remote_sampler.sampler == 'AdaptiveSampler(0.510000, 3.000000, 10)' remote_sampler._update_sampler( {'strategyType': 'PROBABILISTIC', 'probabilisticSampling': {'samplingRate': 0.004}}) assert '%s' % remote_sampler.sampler == 'ProbabilisticSampler(0.004)', \ 'should not fail going from adaptive sampler to probabilistic sampler' remote_sampler._update_sampler({'strategyType': 'RATE_LIMITING', 'operationSampling': {'defaultSamplingProbability': 0.4}}) assert '%s' % remote_sampler.sampler == 'AdaptiveSampler(0.400000, 0.001667, 10)' remote_sampler.close()