def test_adaptive_sampler_default_values(): adaptive_sampler = AdaptiveSampler({}, 2) assert '%s' % adaptive_sampler == 'AdaptiveSampler(0.001000, 0.001667, 2)', 'sampler should use default values' sampled, tags = adaptive_sampler.is_sampled(0, 'op') assert sampled assert tags == get_tags('probabilistic', 0.001), 'should use default probability' assert '%s' % adaptive_sampler.samplers['op'] == 'GuaranteedThroughputProbabilisticSampler(op, 0.001000, 0.001667)' adaptive_sampler.update(strategies = { "defaultLowerBoundTracesPerSecond":4, "perOperationStrategies": [ { "operation":"new_op", "probabilisticSampling":{ "samplingRate":0.002 } } ] }) assert '%s' % adaptive_sampler == 'AdaptiveSampler(0.001000, 4.000000, 2)' sampled, tags = adaptive_sampler.is_sampled(0, 'new_op') assert sampled assert tags == get_tags('probabilistic', 0.002) assert '%s' % adaptive_sampler.samplers['new_op'] == 'GuaranteedThroughputProbabilisticSampler(new_op, 0.002000, 4.000000)' sampled, tags = adaptive_sampler.is_sampled(0, 'op') assert sampled assert tags == get_tags('probabilistic', 0.001) # TODO ruh roh, the lowerbound isn't changed if the operation isn't included in perOperationStrategies assert '%s' % adaptive_sampler.samplers['op'] == 'GuaranteedThroughputProbabilisticSampler(op, 0.001000, 0.001667)'
def test_adaptive_sampler_default_values(): adaptive_sampler = AdaptiveSampler({}, 2) assert '%s' % adaptive_sampler == \ 'AdaptiveSampler(0.001000, 0.001667, 2)', 'sampler should use default values' sampled, tags = adaptive_sampler.is_sampled(0, 'op') assert sampled assert tags == \ get_tags('probabilistic', 0.001), 'should use default probability' assert '%s' % adaptive_sampler.samplers['op'] == \ 'GuaranteedThroughputProbabilisticSampler(op, 0.001000, 0.001667)' adaptive_sampler.update(strategies={ 'defaultLowerBoundTracesPerSecond': 4, 'perOperationStrategies': [ { 'operation': 'new_op', 'probabilisticSampling': { 'samplingRate': 0.002 } } ] }) assert '%s' % adaptive_sampler == 'AdaptiveSampler(0.001000, 4.000000, 2)' sampled, tags = adaptive_sampler.is_sampled(0, 'new_op') assert sampled assert tags == get_tags('probabilistic', 0.002) assert '%s' % adaptive_sampler.samplers['new_op'] == \ 'GuaranteedThroughputProbabilisticSampler(new_op, 0.002000, 4.000000)' sampled, tags = adaptive_sampler.is_sampled(0, 'op') assert sampled assert tags == get_tags('probabilistic', 0.001) # TODO ruh roh, the lowerbound isn't changed # if the operation isn't included in perOperationStrategies assert '%s' % adaptive_sampler.samplers['op'] == \ 'GuaranteedThroughputProbabilisticSampler(op, 0.001000, 0.001667)'
def test_adaptive_sampler(): strategies = { "defaultSamplingProbability":0.51, "defaultLowerBoundTracesPerSecond":3, "perOperationStrategies": [ { "operation":"op", "probabilisticSampling":{ "samplingRate":0.5 } } ] } sampler = AdaptiveSampler(strategies, 2) sampled, tags = sampler.is_sampled(MAX_INT-10, 'op') assert sampled assert tags == get_tags('probabilistic', 0.5) # This operation is seen for the first time by the sampler sampled, tags = sampler.is_sampled(MAX_INT-10, "new_op") assert sampled assert tags == get_tags('probabilistic', 0.51) ts = time.time() with mock.patch('jaeger_client.rate_limiter.RateLimiter.timestamp') \ as mock_time: # Move time forward by a second to guarantee the rate limiter has enough credits mock_time.side_effect = lambda: ts + 1 sampled, tags = sampler.is_sampled(MAX_INT+(MAX_INT/4), "new_op") assert sampled assert tags == get_tags('lowerbound', 0.51) # This operation is seen for the first time by the sampler but surpasses # max_operations of 2. The default probabilistic sampler will be used sampled, tags = sampler.is_sampled(MAX_INT-10, "new_op_2") assert sampled assert tags == get_tags('probabilistic', 0.51) sampled, _ = sampler.is_sampled(MAX_INT+(MAX_INT/4), "new_op_2") assert not sampled assert '%s' % sampler == 'AdaptiveSampler(0.510000, 3.000000, 2)' # Update the strategies strategies = { "defaultSamplingProbability":0.52, "defaultLowerBoundTracesPerSecond":4, "perOperationStrategies": [ { "operation":"op", "probabilisticSampling":{ "samplingRate":0.52 } }, { "operation":"new_op_3", "probabilisticSampling":{ "samplingRate":0.53 } } ] } sampler.update(strategies) # The probability for op has been updated sampled, tags = sampler.is_sampled(MAX_INT-10, 'op') assert sampled assert tags == get_tags('probabilistic', 0.52) # A new operation has been added sampled, tags = sampler.is_sampled(MAX_INT-10, 'new_op_3') assert sampled assert tags == get_tags('probabilistic', 0.53) assert '%s' % sampler == 'AdaptiveSampler(0.520000, 4.000000, 2)' sampler.close()
def test_adaptive_sampler(): strategies = { "defaultSamplingProbability": 0.51, "defaultLowerBoundTracesPerSecond": 3, "perOperationStrategies": [{ "operation": "op", "probabilisticSampling": { "samplingRate": 0.5 } }] } sampler = AdaptiveSampler(strategies, 2) sampled, tags = sampler.is_sampled(MAX_INT - 10, 'op') assert sampled assert tags == get_tags('probabilistic', 0.5) # This operation is seen for the first time by the sampler sampled, tags = sampler.is_sampled(MAX_INT - 10, "new_op") assert sampled assert tags == get_tags('probabilistic', 0.51) sampled, tags = sampler.is_sampled(MAX_INT + (MAX_INT / 4), "new_op") assert sampled assert tags == get_tags('lowerbound', 0.51) # This operation is seen for the first time by the sampler but surpasses # max_operations of 2. The default probabilistic sampler will be used sampled, tags = sampler.is_sampled(MAX_INT - 10, "new_op_2") assert sampled assert tags == get_tags('probabilistic', 0.51) sampled, _ = sampler.is_sampled(MAX_INT + (MAX_INT / 4), "new_op_2") assert not sampled assert '%s' % sampler == 'AdaptiveSampler(0.510000, 3.000000, 2)' # Update the strategies strategies = { "defaultSamplingProbability": 0.52, "defaultLowerBoundTracesPerSecond": 4, "perOperationStrategies": [{ "operation": "op", "probabilisticSampling": { "samplingRate": 0.52 } }, { "operation": "new_op_3", "probabilisticSampling": { "samplingRate": 0.53 } }] } sampler.update(strategies) # The probability for op has been updated sampled, tags = sampler.is_sampled(MAX_INT - 10, 'op') assert sampled assert tags == get_tags('probabilistic', 0.52) # A new operation has been added sampled, tags = sampler.is_sampled(MAX_INT - 10, 'new_op_3') assert sampled assert tags == get_tags('probabilistic', 0.53) assert '%s' % sampler == 'AdaptiveSampler(0.520000, 4.000000, 2)' sampler.close()
def test_adaptive_sampler(): strategies = { 'defaultSamplingProbability': 0.51, 'defaultLowerBoundTracesPerSecond': 3, 'perOperationStrategies': [ { 'operation': 'op', 'probabilisticSampling': { 'samplingRate': 0.5 } } ] } sampler = AdaptiveSampler(strategies, 2) sampled, tags = sampler.is_sampled(MAX_INT - 10, 'op') assert sampled assert tags == get_tags('probabilistic', 0.5) # This operation is seen for the first time by the sampler sampled, tags = sampler.is_sampled(MAX_INT - 10, 'new_op') assert sampled assert tags == get_tags('probabilistic', 0.51) ts = time.time() with mock.patch('jaeger_client.rate_limiter.RateLimiter.timestamp') \ as mock_time: # Move time forward by a second to guarantee the rate limiter has enough credits mock_time.side_effect = lambda: ts + 1 sampled, tags = sampler.is_sampled(int(MAX_INT + (MAX_INT / 4)), 'new_op') assert sampled assert tags == get_tags('lowerbound', 0.51) # This operation is seen for the first time by the sampler but surpasses # max_operations of 2. The default probabilistic sampler will be used sampled, tags = sampler.is_sampled(MAX_INT - 10, 'new_op_2') assert sampled assert tags == get_tags('probabilistic', 0.51) sampled, _ = sampler.is_sampled(int(MAX_INT + (MAX_INT / 4)), 'new_op_2') assert not sampled assert '%s' % sampler == 'AdaptiveSampler(0.510000, 3.000000, 2)' # Update the strategies strategies = { 'defaultSamplingProbability': 0.52, 'defaultLowerBoundTracesPerSecond': 4, 'perOperationStrategies': [ { 'operation': 'op', 'probabilisticSampling': { 'samplingRate': 0.52 } }, { 'operation': 'new_op_3', 'probabilisticSampling': { 'samplingRate': 0.53 } } ] } sampler.update(strategies) # The probability for op has been updated sampled, tags = sampler.is_sampled(MAX_INT - 10, 'op') assert sampled assert tags == get_tags('probabilistic', 0.52) # A new operation has been added sampled, tags = sampler.is_sampled(MAX_INT - 10, 'new_op_3') assert sampled assert tags == get_tags('probabilistic', 0.53) assert '%s' % sampler == 'AdaptiveSampler(0.520000, 4.000000, 2)' sampler.close()