Skip to content

Commit 1c0bbcf

Browse files
author
Andrii Soldatenko
committed
add more tests
1 parent 5e4d833 commit 1c0bbcf

File tree

5 files changed

+59
-35
lines changed

5 files changed

+59
-35
lines changed

src/sentry/conf/server.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ def SOCIAL_AUTH_DEFAULT_USERNAME():
849849
},
850850
"dynamic-sampling-project-biases": {
851851
"task": "sentry.dynamic_sampling.tasks.prioritize_by_project",
852-
"schedule": timedelta(hours=1),
852+
# Run daily at 08:00
853+
"schedule": crontab(hour=8, minute=0),
853854
"options": {"expires": 3600},
854855
},
855856
}
@@ -1085,7 +1086,7 @@ def SOCIAL_AUTH_DEFAULT_USERNAME():
10851086
# Try to derive normalization rules by clustering transaction names.
10861087
"organizations:transaction-name-clusterer": False,
10871088
# Sanitize transaction names in the ingestion pipeline.
1088-
"organizations:transaction-name-sanitization": False,
1089+
"organizations:transaction-name-sanitization": False, # DEPRECATED
10891090
# Extraction metrics for transactions during ingestion.
10901091
"organizations:transaction-metrics-extraction": False,
10911092
# True if release-health related queries should be run against both
@@ -1144,8 +1145,6 @@ def SOCIAL_AUTH_DEFAULT_USERNAME():
11441145
"organizations:invite-members": True,
11451146
# Enable rate limits for inviting members.
11461147
"organizations:invite-members-rate-limits": True,
1147-
# Enable new issue actions on issue details
1148-
"organizations:issue-actions-v2": True,
11491148
# Enable new issue alert "issue owners" fallback
11501149
"organizations:issue-alert-fallback-targeting": False,
11511150
# Enable removing issue from issue list if action taken.
@@ -1248,8 +1247,6 @@ def SOCIAL_AUTH_DEFAULT_USERNAME():
12481247
"organizations:onboarding-remove-multiselect-platform": False,
12491248
# Enable ANR rates in project details page
12501249
"organizations:anr-rate": False,
1251-
# Enable deobfuscating exception values in Java issues
1252-
"organizations:java-exception-value-deobfuscation": False,
12531250
# Enable tag improvements in the issue details page
12541251
"organizations:issue-details-tag-improvements": False,
12551252
# Enable the release details performance section

src/sentry/dynamic_sampling/prioritise_projects.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44
from datetime import datetime, timedelta
55
from typing import Mapping, Sequence
66

7-
from snuba_sdk import Column, Condition, Direction, Entity, Granularity, Op, OrderBy, Query, Request
7+
from snuba_sdk import (
8+
Column,
9+
Condition,
10+
Direction,
11+
Entity,
12+
Function,
13+
Granularity,
14+
Op,
15+
OrderBy,
16+
Query,
17+
Request,
18+
)
819

920
from sentry.sentry_metrics.indexer.strings import TRANSACTION_METRICS_NAMES
1021
from sentry.snuba.dataset import Dataset, EntityKey
@@ -17,14 +28,18 @@
1728

1829

1930
def fetch_projects_with_total_volumes() -> Mapping[int, Sequence[int]]:
31+
"""
32+
This function fetch with pagination orgs and projects with count per root project
33+
"""
2034
aggregated_projects = defaultdict(list)
2135
start_time = time.time()
2236
offset = 0
2337
while (time.time() - start_time) < MAX_SECONDS:
2438
query = (
2539
Query(
26-
match=Entity(EntityKey.GenericMetricsCounters.value),
40+
match=Entity(EntityKey.GenericOrgMetricsCounters.value),
2741
select=[
42+
Function("sum", [Column("value")], "root_count_value"),
2843
Column("org_id"),
2944
Column("project_id"),
3045
],
@@ -62,7 +77,7 @@ def fetch_projects_with_total_volumes() -> Mapping[int, Sequence[int]]:
6277
data = data[:-1]
6378

6479
for row in data:
65-
aggregated_projects[row["org_id"]].append(row["project_id"])
80+
aggregated_projects[row["org_id"]].append({row["project_id"]: row["root_count_value"]})
6681

6782
if not more_results:
6883
break
@@ -74,7 +89,3 @@ def fetch_projects_with_total_volumes() -> Mapping[int, Sequence[int]]:
7489
)
7590

7691
return aggregated_projects
77-
78-
79-
def process_projects_with_total_volumes(project_ids):
80-
...

src/sentry/snuba/dataset.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ class EntityKey(Enum):
2929
GenericMetricsDistributions = "generic_metrics_distributions"
3030
GenericMetricsSets = "generic_metrics_sets"
3131
GenericMetricsCounters = "generic_metrics_counters"
32+
GenericOrgMetricsCounters = "generic_org_metrics_counters"
3233
IssuePlatform = "search_issues"
Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
import pytest
1+
from datetime import datetime, timezone
2+
3+
from freezegun import freeze_time
24

35
from sentry.dynamic_sampling.prioritise_projects import fetch_projects_with_total_volumes
4-
from sentry.testutils.factories import Factories
5-
from sentry.utils.snuba import SnubaError
6-
7-
8-
@pytest.mark.django_db
9-
def test_prioritize_projects():
10-
organization = Factories.create_organization(name="test-org")
11-
Factories.create_project(organization=organization)
12-
# TODO (andrii): remove it when snuba PR is ready
13-
# https://github.com/getsentry/snuba/pull/3708
14-
with pytest.raises(SnubaError):
15-
fetch_projects_with_total_volumes()
6+
from sentry.snuba.metrics import TransactionMRI
7+
from sentry.testutils import BaseMetricsLayerTestCase, SnubaTestCase, TestCase
8+
9+
MOCK_DATETIME = datetime(2023, 8, 7, 0, 0, 0, tzinfo=timezone.utc)
10+
11+
12+
@freeze_time(MOCK_DATETIME)
13+
class PrioritiseProjectsSnubaQueryTest(BaseMetricsLayerTestCase, TestCase, SnubaTestCase):
14+
@property
15+
def now(self):
16+
return MOCK_DATETIME
17+
18+
def test_simple_one_org_one_project(self):
19+
org1 = self.create_organization("test-org")
20+
p1 = self.create_project(organization=org1)
21+
22+
self.store_performance_metric(
23+
name=TransactionMRI.COUNT_PER_ROOT_PROJECT.value,
24+
tags={"transaction": "foo_transaction"},
25+
hours_before_now=1,
26+
value=1,
27+
project_id=p1.id,
28+
org_id=org1.id,
29+
)
30+
31+
results = fetch_projects_with_total_volumes()
32+
assert results[org1.id] == [{p1.id: 1.0}]
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1+
from collections import defaultdict
2+
13
import pytest
24

35
from sentry.dynamic_sampling.tasks import fetch_projects_with_total_volumes
4-
from sentry.utils.snuba import SnubaError
56

67

78
@pytest.mark.django_db
8-
def test_simple(default_project):
9-
test_data = [
9+
def test_simple_no_data(default_project):
10+
_ = [
1011
{
1112
"org_id": [default_project.organization.id],
1213
"project_id": [default_project.id],
1314
},
1415
]
15-
assert 1 == 1
16-
_ = test_data
17-
# TODO (andrii): remove it when snuba PR is ready
18-
# https://github.com/getsentry/snuba/pull/3708
19-
with pytest.raises(SnubaError):
20-
fetch_projects_with_total_volumes()
16+
project_volumes_total = fetch_projects_with_total_volumes()
17+
18+
assert project_volumes_total == defaultdict(list)

0 commit comments

Comments
 (0)