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

feat(dynamic-sampling): add endpoint to retrieve project span counts #80587

Conversation

shellmayr
Copy link
Member

@shellmayr shellmayr commented Nov 12, 2024

  • Expose the span counts in all projects of an org via a new endpoint at /{organization}/sampling/project-span-counts/
  • API response format is the same as in the metrics/query API
  • Allows all members of an org with org:read permissions or higher to access the project ids, project names, and span counts of all projects in the org, even if there is no open membership

Contributes to https://github.com/getsentry/projects/issues/353

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 12, 2024
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #80587      +/-   ##
==========================================
+ Coverage   78.36%   78.39%   +0.02%     
==========================================
  Files        7206     7216      +10     
  Lines      318724   319330     +606     
  Branches    43907    43976      +69     
==========================================
+ Hits       249778   250340     +562     
- Misses      62585    62616      +31     
- Partials     6361     6374      +13     

@shellmayr shellmayr marked this pull request as ready for review November 13, 2024 14:16
@shellmayr shellmayr requested a review from a team as a code owner November 13, 2024 14:17
@shellmayr shellmayr requested review from a team and jan-auer November 13, 2024 14:26
Comment on lines 42 to 45
projects = cast(
Sequence[Project],
Project.objects.filter(organization=organization, status=ObjectStatus.ACTIVE).all(),
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a potential issue. Queryset .all() does nothing but copy the queryset, which is basically an iterator and not really a sequence. typing.cast is essentially a no-op functionally, just there for typing. If you require an actual sequence I would use projects = list(Projects.objects.filter(...)).

Comment on lines 42 to 47
projects = cast(
Sequence[Project],
list(
Project.objects.filter(organization=organization, status=ObjectStatus.ACTIVE).all()
),
)
Copy link
Member

@jan-auer jan-auer Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cast to Sequence should no longer be required - a list is a sequence. Also, list() will evaluate the queryset, I think you can omit the .all().

Optionally, I'd add a comment to clarify that we do not want team filters even with closed membership, so that in the future this is not unintentionally "fixed".

Suggested change
projects = cast(
Sequence[Project],
list(
Project.objects.filter(organization=organization, status=ObjectStatus.ACTIVE).all()
),
)
projects = list(
Project.objects.filter(organization=organization, status=ObjectStatus.ACTIVE)
)

@@ -1417,6 +1420,11 @@ def create_group_urls(name_prefix: str) -> list[URLPattern | URLResolver]:
OrganizationSamplingProjectRatesEndpoint.as_view(),
name="sentry-api-0-organization-sampling-project-rates",
),
re_path(
r"^(?P<organization_id_or_slug>[^\/]+)/sampling/project-span-counts/$",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This endpoint returns the span count per root project, which distinguishes it from regular stats endpoints. Should we choose a URL that makes this clear? This might make the URL too long, so I'm not sure we should actually do this.

Options could be:

  • project-root-counts (we can equally add other counts there if we need to)
  • span-root-counts
  • root-counts

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's a good point. None of them really feel intuitive to me, but I suppose project-root-counts is probably the best, as it even takes out the specificity of spans in case we ever adapt what type of data sampling acts on.

@shellmayr shellmayr merged commit 3163af7 into master Nov 14, 2024
50 checks passed
@shellmayr shellmayr deleted the shellmayr/feat/add-organization-sampling-project-span-counts-endpoint branch November 14, 2024 11:43
Copy link

sentry-io bot commented Nov 22, 2024

Suspect Issues

This pull request was deployed and Sentry observed the following issues:

  • ‼️ MetricsQueryExecutionError: An error occurred while executing the query /api/0/organizations/{organization_id_or_slug}/... View Issue

Did you find this useful? React with a 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants