Skip to content

Commit

Permalink
rename config option to X_sample_rate
Browse files Browse the repository at this point in the history
  • Loading branch information
quinnmil committed Jan 10, 2025
1 parent 2ec02ec commit 0ee5b33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/scout_apm/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ def log(self) -> None:
"name",
"revision_sha",
"sample_rate",
"sample_endpoint_rate",
"endpoint_sample_rate",
"sample_endpoints",
"sample_jobs",
"sample_job_rate",
"job_sample_rate",
"scm_subdirectory",
"shutdown_message_enabled",
"shutdown_timeout_seconds",
Expand Down Expand Up @@ -252,9 +252,9 @@ def __init__(self):
"revision_sha": self._git_revision_sha(),
"sample_rate": 100,
"sample_endpoints": [],
"sample_endpoint_rate": None,
"endpoint_sample_rate": None,
"sample_jobs": [],
"sample_job_rate": None,
"job_sample_rate": None,
"scm_subdirectory": "",
"shutdown_message_enabled": True,
"shutdown_timeout_seconds": 2.0,
Expand Down Expand Up @@ -381,9 +381,9 @@ def convert_endpoint_sampling(value: Union[str, Dict[str, Any]]) -> Dict[str, in
"monitor": convert_to_bool,
"sample_rate": convert_sample_rate,
"sample_endpoints": convert_endpoint_sampling,
"sample_endpoint_rate": convert_sample_rate,
"endpoint_sample_rate": convert_sample_rate,
"sample_jobs": convert_endpoint_sampling,
"sample_job_rate": convert_sample_rate,
"job_sample_rate": convert_sample_rate,
"shutdown_message_enabled": convert_to_bool,
"shutdown_timeout_seconds": convert_to_float,
}
Expand Down
12 changes: 6 additions & 6 deletions src/scout_apm/core/sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def __init__(self, config):
self.sample_jobs = config.value("sample_jobs")
self.ignore_endpoints = set(config.value("ignore_endpoints"))
self.ignore_jobs = set(config.value("ignore_jobs"))
self.sample_endpoint_rate = config.value("sample_endpoint_rate")
self.sample_job_rate = config.value("sample_job_rate")
self.endpoint_sample_rate = config.value("endpoint_sample_rate")
self.job_sample_rate = config.value("job_sample_rate")

def _any_sampling(self):
"""
Expand Down Expand Up @@ -117,8 +117,8 @@ def get_effective_sample_rate(self, operation: str) -> int:
matching_rate = self._find_matching_rate(name, self.sample_endpoints)
if matching_rate is not None:
return matching_rate
if self.sample_endpoint_rate is not None:
return self.sample_endpoint_rate
if self.endpoint_sample_rate is not None:
return self.endpoint_sample_rate

else: # op_type == 'job'
if name in self.ignore_jobs:
Expand All @@ -127,8 +127,8 @@ def get_effective_sample_rate(self, operation: str) -> int:
matching_rate = self._find_matching_rate(name, self.sample_jobs)
if matching_rate is not None:
return matching_rate
if self.sample_job_rate is not None:
return self.sample_job_rate
if self.job_sample_rate is not None:
return self.job_sample_rate

# Fall back to global sample rate
return self.sample_rate
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/core/test_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def config():
},
ignore_endpoints=["metrics", "ping"],
ignore_jobs=["test-job"],
sample_endpoint_rate=70, # 70% sampling for unspecified endpoints
sample_job_rate=40, # 40% sampling for unspecified jobs
endpoint_sample_rate=70, # 70% sampling for unspecified endpoints
job_sample_rate=40, # 40% sampling for unspecified jobs
)
yield config
ScoutConfig.reset_all()
Expand Down Expand Up @@ -105,7 +105,7 @@ def test_should_sample_job_default_rate(sampler):


def test_should_sample_endpoint_fallback_to_global_rate(config):
config.set(sample_endpoint_rate=None)
config.set(endpoint_sample_rate=None)
sampler = Sampler(config)
with mock.patch("random.randint", return_value=40):
assert sampler.should_sample("Controller/unspecified") is True
Expand All @@ -114,7 +114,7 @@ def test_should_sample_endpoint_fallback_to_global_rate(config):


def test_should_sample_job_fallback_to_global_rate(config):
config.set(sample_job_rate=None)
config.set(job_sample_rate=None)
sampler = Sampler(config)
with mock.patch("random.randint", return_value=40):
assert sampler.should_sample("Job/unspecified-job") is True
Expand Down

0 comments on commit 0ee5b33

Please sign in to comment.