Beispiel #1
0
def test_path_matching():

    rule = SamplingRule(RULE)
    assert rule.applies('name', 'GET', '/api/move/up')
    assert rule.applies(None, 'POST', '/api/move/up')
    assert rule.applies('name', None, '/api/move/up')
    assert rule.applies('name', 'PUT', None)
    assert not rule.applies(None, 'GET', '/root')
def test_preserving_sampling_statistics():
    cache = RuleCache()
    cache.load_rules([rule_default, rule_0])
    rule_0.increment_request_count()
    rule_0.increment_sampled_count()
    rule_0.reservoir.load_quota(quota=3, TTL=15, interval=None)

    new_rule_0 = SamplingRule(name='a', priority=1,
                              rate=0.1, reservoir_size=1)
    cache.load_rules([rule_default, new_rule_0])

    statistics = cache.rules[0].snapshot_statistics()
    reservoir = cache.rules[0].reservoir

    assert statistics['request_count'] == 1
    assert statistics['sampled_count'] == 1
    assert reservoir.quota == 3
    assert reservoir.TTL == 15
import time
import pytest

from aws_xray_sdk.core.sampling.sampling_rule import SamplingRule
from aws_xray_sdk.core.sampling.rule_cache import RuleCache
from aws_xray_sdk.core.sampling.reservoir import Reservoir

rule_0 = SamplingRule(name='a', priority=1, rate=0.1,
                      reservoir_size=1, host='*mydomain*',
                      method='GET', path='myop', service='random',
                      service_type='random')
rule_1 = SamplingRule(name='aa', priority=2, rate=0.1,
                      reservoir_size=1, host='*random*',
                      method='POST', path='random', service='proxy',
                      service_type='random')
rule_2 = SamplingRule(name='b', priority=2, rate=0.1,
                      reservoir_size=1, host='*', method='GET',
                      path='ping', service='myapp',
                      service_type='AWS::EC2::Instance')
rule_default = SamplingRule(name='Default', priority=1000, rate=0.1,
                            reservoir_size=1)


@pytest.fixture(autouse=True)
def reset_rules():
    """
    Clean up context storage before and after each test run.
    """
    rules = [rule_default, rule_2, rule_0, rule_1]
    for rule in rules:
        rule.snapshot_statistics()
Beispiel #4
0
def test_incomplete_path_rule():

    rule = copy.deepcopy(RULE)
    del rule['url_path']
    with pytest.raises(InvalidSamplingManifestError):
        SamplingRule(rule)
Beispiel #5
0
def test_invalid_default():

    with pytest.raises(InvalidSamplingManifestError):
        SamplingRule(RULE, default=True)
Beispiel #6
0
def test_negative_fixed_target():

    rule = copy.deepcopy(RULE)
    rule['fixed_target'] = -1
    with pytest.raises(InvalidSamplingManifestError):
        SamplingRule(rule)
Beispiel #7
0
def test_negative_rate():

    rule = copy.deepcopy(RULE)
    rule['rate'] = -1
    with pytest.raises(InvalidSamplingManifestError):
        SamplingRule(rule)