Unexpected results from rule matching
- Lingua principale
- Python
- Stelle
- 338
- Fork
- 147
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
Hi,
I have standalone apps and APIs in my environment. But, it seems like the SamplingRule.match() always return the highest priority rule as the result for all standalone apps. Currently, all the rules are in the cloud.
My use case is to have a blanket rule to ignore a certain endpoint from multiple APIs and still be able to tweak sampling rules for standalone apps and/or APIs.
Here's my sample test:
```
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_ignore = SamplingRule(name='ignore', priority=10, rate=0,
reservoir_size=0, host='*', method='*',
path='/ignore_endpoint', service='*',
service_type='*')
rule_std_app1 = SamplingRule(name='std_app1', priority=20, rate=0.5,
reservoir_size=10, host='*', method='*',
path='*', service='std_app1',
service_type='*')
rule_api1 = SamplingRule(name='api1', priority=20, rate=0.5,
reservoir_size=10, host='*', method='*',
path='*', service='api1',
service_type='*')
rule_default = SamplingRule(name='Default', priority=1000, rate=0.1,
reservoir_size=1)
def test_rule_matching():
cache = RuleCache()
now = int(time.time())
cache.load_rules([rule_ignore, rule_std_app1, rule_api1, rule_default])
cache.last_updated = now
print("\n")
sampling_req = {'path':'/ignore_endpoint'}
rule = cache.get_matched_rule(sampling_req, now)
print(f"\nsampling_req: {sampling_req}\nExpected: ignore, Matched: {rule.name}")
print(f"{rule.name} == 'ignore'? {rule.name == 'ignore'}")
# assert rule.name == 'ignore'
sampling_req = {'service':'std_app1'}
rule = cache.get_matched_rule(sampling_req, now)
print(f"\nsampling_req: {sampling_req}\nExpected: std_app1, Matched: {rule.name}")
print(f"{rule.name} == 'std_app1'? {rule.name == 'std_app1'}")
# assert rule.name == 'std_app1'
sampling_req = {'service':'std_app2'}
rule = cache.get_matched_rule(sampling_req, now)
print(f"\nsampling_req: {sampling_req}\nExpected: Default, Matched: {rule.name}")
print(f"{rule.name} == 'Default'? {rule.is_default()}")
# assert rule.is_default()
sampling_req = {'service':'api1', 'path':'/test'}
rule = cache.get_matched_rule(sampling_req, now)
print(f"\nsampling_req: {sampling_req}\nExpected: api1, Matched: {rule.name}")
print(f"{rule.name} == 'api1'? {rule.name == 'api1'}")
# assert rule.name == 'api1'
```
Here's the debug output for the print statements
```
sampling_req: {'path': '/ignore_endpoint'}
Expected: ignore, Matched: ignore
ignore == 'ignore'? True
sampling_req: {'service': 'std_app1'}
Expected: std_app1, Matched: ignore
ignore == 'std_app1'? False
sampling_req: {'service': 'std_app2'}
Expected: Default, Matched: ignore
ignore == 'Default'? False
sampling_req: {'service': 'api1', 'path': '/test'}
Expected: api1, Matched: api1
api1 == 'api1'? True
```
As you can see, the standalone apps (std_app1 and std_app2) resulted with ignore rule instead of the expected rule.
Please confirm if this is an expected behavior or a bug?
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.