From 95b7f094057c1f6cc3043f4b8ac069ba5f5dc8ed Mon Sep 17 00:00:00 2001 From: Andrii Soldatenko Date: Mon, 6 Feb 2023 10:46:03 +0100 Subject: [PATCH] refactor test --- .../models/adjustment_models.py | 8 ++++---- .../dynamic_sampling/test_adjusments_models.py | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/sentry/dynamic_sampling/models/adjustment_models.py b/src/sentry/dynamic_sampling/models/adjustment_models.py index 7b347854186678..be4e66a2a3d5cd 100644 --- a/src/sentry/dynamic_sampling/models/adjustment_models.py +++ b/src/sentry/dynamic_sampling/models/adjustment_models.py @@ -7,9 +7,9 @@ @dataclass class Project: id: int - count_per_root: int + count_per_root: float blended_sample_rate: float - new_count_per_root: int = 0 + new_count_per_root: float = 0.0 new_sample_rate: float = 0.0 @@ -32,7 +32,7 @@ def adjust_sample_rates(self): # Step 3: # IF len % 2 == 0 left_split = sorted_projects[: len(sorted_projects) // 2] - right_split = reversed(sorted_projects[len(sorted_projects) // 2 :]) + right_split = reversed(sorted_projects[len(sorted_projects) // 2 : len(sorted_projects)]) new_left = [] new_right = [] @@ -52,4 +52,4 @@ def adjust_sample_rates(self): # This opinionated `coefficient` reduces adjustment on every step coefficient = diff / left.new_count_per_root - return [new_left, new_right] + return [*new_right, *reversed(new_left)] diff --git a/tests/sentry/dynamic_sampling/test_adjusments_models.py b/tests/sentry/dynamic_sampling/test_adjusments_models.py index 49fd42f0716095..2531a4e0885497 100644 --- a/tests/sentry/dynamic_sampling/test_adjusments_models.py +++ b/tests/sentry/dynamic_sampling/test_adjusments_models.py @@ -16,11 +16,18 @@ def test_adjust_sample_rates_org_with_single_project(): def test_adjust_sample_rates_org_with_few_projects(): projects = [ - P(id=1, count_per_root=9, blended_sample_rate=0.04), - P(id=2, count_per_root=7, blended_sample_rate=0.04), - P(id=3, count_per_root=3, blended_sample_rate=0.04), - P(id=4, count_per_root=1, blended_sample_rate=0.04), + P(id=1, count_per_root=9.0, blended_sample_rate=0.04), + P(id=2, count_per_root=7.0, blended_sample_rate=0.04), + P(id=3, count_per_root=3.0, blended_sample_rate=0.04), + P(id=4, count_per_root=1.0, blended_sample_rate=0.04), ] p = AdjustedModel(projects=projects, fidelity_rate=0.25) - assert p.adjust_sample_rates == [P(id=1, count_per_root=10, blended_sample_rate=0.04)] + expected_projects = [ + P(id=1, count_per_root=9.0, new_count_per_root=6.0, blended_sample_rate=0.04), + P(id=2, count_per_root=7.0, new_count_per_root=5.5, blended_sample_rate=0.04), + P(id=3, count_per_root=3.0, new_count_per_root=4.5, blended_sample_rate=0.04), + P(id=4, count_per_root=1.0, new_count_per_root=4.0, blended_sample_rate=0.04), + ] + + assert p.adjust_sample_rates == expected_projects