Skip to content

Commit

Permalink
refactor test
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Soldatenko committed Feb 7, 2023
1 parent 8efaf23 commit 95b7f09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/sentry/dynamic_sampling/models/adjustment_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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 = []
Expand All @@ -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)]
17 changes: 12 additions & 5 deletions tests/sentry/dynamic_sampling/test_adjusments_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 95b7f09

Please sign in to comment.