Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Unexpected results from rule matching

オープン
#323 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

@srprash がすでに取り組んでいます。

2022年1月18日 から。

評価

この issue はまだ評価されていません。

説明

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?

主要言語
Python
スター
340
フォーク
148
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

aws/aws-xray-sdk-python のほかの issue

aws/aws-xray-sdk-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。