Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NH-34752 Add calculate_tracing_mode tests and fixture #138

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 68 additions & 3 deletions tests/unit/test_sampler/fixtures/sampler.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,83 @@
import pytest
import re
from typing import Any

from solarwinds_apm.sampler import _SwSampler

def side_effect_fn(param):

# Basic Sampler fixture =====================================

def config_get(param) -> Any:
if param == "tracing_mode":
return -1
elif param == "transaction_filters":
return []
else:
return None

@pytest.fixture(name="sw_sampler")
@pytest.fixture(name="fixture_swsampler")
def fixture_swsampler(mocker):
mock_apm_config = mocker.Mock()
mock_get = mocker.Mock(
side_effect=side_effect_fn
side_effect=config_get
)
mock_apm_config.configure_mock(
**{
"agent_enabled": True,
"get": mock_get,
}
)
return _SwSampler(mock_apm_config)


# Sampler fixtures with Transaction Filters =================

def config_get_txn_filters(param) -> Any:
if param == "tracing_mode":
return -1
elif param == "transaction_filters":
return [
{
"regex": re.compile("http://foo/bar"),
"tracing_mode": 1,
},
{
"regex": re.compile(r"http://foo/[a-z]*/bar"),
"tracing_mode": 1,
},
{
"regex": re.compile("http://foo/bar-baz"),
"tracing_mode": 1,
},
{
"regex": re.compile("http://foo/bar-baz"),
"tracing_mode": 0,
},
{
"regex": re.compile("CLIENT:foo"),
"tracing_mode": 1,
},
{
"regex": re.compile(r"CLIENT:f[a-z]*o"),
"tracing_mode": 1,
},
{
"regex": re.compile("CLIENT:foo_bar"),
"tracing_mode": 1,
},
{
"regex": re.compile("CLIENT:foo_bar"),
"tracing_mode": 0,
}
]
else:
return None

@pytest.fixture(name="fixture_swsampler_txnfilters")
def fixture_swsampler_txnfilters(mocker):
mock_apm_config = mocker.Mock()
mock_get = mocker.Mock(
side_effect=config_get_txn_filters
)
mock_apm_config.configure_mock(
**{
Expand Down
Loading