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

chore(billing): Add profile chunk to org stats v2 endpoint #81019

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion src/sentry/api/endpoints/organization_stats_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,16 @@ class OrgStatsQueryParamsSerializer(serializers.Serializer):
)

category = serializers.ChoiceField(
("error", "transaction", "attachment", "replay", "profile", "profile_duration", "monitor"),
(
"error",
"transaction",
"attachment",
"replay",
"profile",
"profile_duration",
"profile_chunk",
"monitor",
),
required=False,
help_text=(
"Filter by data category. Each category represents a different type of data:\n\n"
Expand All @@ -109,6 +118,7 @@ class OrgStatsQueryParamsSerializer(serializers.Serializer):
"- `replay`: Session replay events\n"
"- `profile`: Performance profiles\n"
"- `profile_duration`: Profile duration data (note: cannot be combined with other categories since quantity represents milliseconds)\n"
"- `profile_chunk`: Profile chunk\n"
"- `monitor`: Cron monitor events"
),
)
Expand Down
15 changes: 15 additions & 0 deletions tests/apidocs/endpoints/organizations/test_org_stats_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,18 @@ def test_profile_duration_category(self):
request = RequestFactory().get(self.url)

self.validate_schema(request, response)

def test_profile_chunk_category(self):
"""
Test that the organization stats endpoint correctly handles profile chunk category.
"""
query = {
"interval": "1d",
"field": "sum(quantity)",
"groupBy": "category",
"category": "profile_chunk",
}
response = self.client.get(self.url, query, format="json")
request = RequestFactory().get(self.url)

self.validate_schema(request, response)
71 changes: 71 additions & 0 deletions tests/snuba/api/endpoints/test_organization_stats_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@ def setUp(self):
3,
)

# Add profile_chunk outcome data
self.store_outcomes(
{
"org_id": self.org.id,
"timestamp": self.now - timedelta(hours=1),
"project_id": self.project.id,
"category": DataCategory.PROFILE_CHUNK,
"quantity": 10,
},
)

def do_request(self, query, user=None, org=None, status_code=200):
self.login_as(user=user or self.user)
org_slug = (org or self.organization).slug
Expand Down Expand Up @@ -474,6 +485,11 @@ def test_org_simple(self):
"series": {"sum(quantity)": [0, 0, 3000]},
"totals": {"sum(quantity)": 3000},
},
{
"by": {"category": "profile_chunk", "outcome": "accepted", "reason": "none"},
"series": {"sum(quantity)": [0, 0, 10]},
"totals": {"sum(quantity)": 10},
},
{
"by": {
"category": "transaction",
Expand Down Expand Up @@ -930,6 +946,61 @@ def test_profile_duration_groupby(self):
],
}

@freeze_time("2021-03-14T12:27:28.303Z")
def test_profile_chunk_filter(self):
"""Test that profile_chunk data is correctly filtered and returned"""
response = self.do_request(
{
"project": [-1],
"statsPeriod": "1d",
"interval": "1d",
"field": ["sum(quantity)"],
"category": ["profile_chunk"],
},
status_code=200,
)

assert result_sorted(response.data) == {
"start": "2021-03-13T00:00:00Z",
"end": "2021-03-15T00:00:00Z",
"intervals": ["2021-03-13T00:00:00Z", "2021-03-14T00:00:00Z"],
"groups": [
{
"by": {},
"series": {"sum(quantity)": [0, 10]},
"totals": {"sum(quantity)": 10},
}
],
}

@freeze_time("2021-03-14T12:27:28.303Z")
def test_profile_chunk_groupby(self):
"""Test that profile_chunk data is correctly grouped"""
response = self.do_request(
{
"project": [-1],
"statsPeriod": "1d",
"interval": "1d",
"field": ["sum(quantity)"],
"groupBy": ["category"],
"category": ["profile_chunk"],
},
status_code=200,
)

assert result_sorted(response.data) == {
"start": "2021-03-13T00:00:00Z",
"end": "2021-03-15T00:00:00Z",
"intervals": ["2021-03-13T00:00:00Z", "2021-03-14T00:00:00Z"],
"groups": [
{
"by": {"category": "profile_chunk"},
"series": {"sum(quantity)": [0, 10]},
"totals": {"sum(quantity)": 10},
}
],
}


def result_sorted(result):
"""sort the groups of the results array by the `by` object, ensuring a stable order"""
Expand Down
Loading