Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Unexpected results from rule matching

Đang mở
#323 1 bình luận 0 reaction 1 người được giao Xem trên GitHub

@srprash đang làm issue này rồi.

Từ ngày 18/1/2022.

Đánh giá

Issue này chưa được đánh giá.

Mô tả

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?

Ngôn ngữ chính
Python
Star
340
Fork
148
Merge trung bình
7 ngày 8 giờ
Pull request đã merge (30 ngày)
2

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của aws/aws-xray-sdk-python

Tất cả issue của aws/aws-xray-sdk-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.