Skip to content

Commit

Permalink
Merge branch 'master' into chore-add-strict-types
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed May 14, 2024
2 parents 046dd70 + 9ae4b44 commit 422da91
Show file tree
Hide file tree
Showing 186 changed files with 2,601 additions and 1,944 deletions.
31 changes: 1 addition & 30 deletions fixtures/backup/model_dependencies/detailed.json
Original file line number Diff line number Diff line change
Expand Up @@ -5650,35 +5650,6 @@
]
]
},
"sentry.sentryfunction": {
"dangling": false,
"foreign_keys": {
"organization": {
"kind": "FlexibleForeignKey",
"model": "sentry.organization",
"nullable": false
}
},
"model": "sentry.sentryfunction",
"relocation_dependencies": [],
"relocation_scope": "Excluded",
"silos": [
"Region"
],
"table_name": "sentry_sentryfunction",
"uniques": [
[
"external_id"
],
[
"organization",
"slug"
],
[
"slug"
]
]
},
"sentry.sentryshot": {
"dangling": false,
"foreign_keys": {
Expand Down Expand Up @@ -6177,4 +6148,4 @@
]
]
}
}
}
5 changes: 1 addition & 4 deletions fixtures/backup/model_dependencies/flat.json
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,6 @@
"sentry.apitoken",
"sentry.sentryappinstallation"
],
"sentry.sentryfunction": [
"sentry.organization"
],
"sentry.sentryshot": [
"sentry.organization"
],
Expand Down Expand Up @@ -848,4 +845,4 @@
"social_auth.usersocialauth": [
"sentry.user"
]
}
}
3 changes: 1 addition & 2 deletions fixtures/backup/model_dependencies/sorted.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"sentry.repositoryprojectpathconfig",
"sentry.reprocessingreport",
"sentry.scheduleddeletion",
"sentry.sentryfunction",
"sentry.sentryshot",
"sentry.stringindexer",
"sentry.team",
Expand Down Expand Up @@ -229,4 +228,4 @@
"sentry.incidentseen",
"sentry.incidentproject",
"sentry.incidentactivity"
]
]
3 changes: 1 addition & 2 deletions fixtures/backup/model_dependencies/truncate.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"sentry_repositoryprojectpathconfig",
"sentry_reprocessingreport",
"sentry_scheduleddeletion",
"sentry_sentryfunction",
"sentry_sentryshot",
"sentry_stringindexer",
"sentry_team",
Expand Down Expand Up @@ -229,4 +228,4 @@
"sentry_incidentseen",
"sentry_incidentproject",
"sentry_incidentactivity"
]
]
2 changes: 1 addition & 1 deletion migrations_lockfile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ feedback: 0004_index_together
hybridcloud: 0016_add_control_cacheversion
nodestore: 0002_nodestore_no_dictfield
replays: 0004_index_together
sentry: 0720_remove_actor_columns
sentry: 0722_drop_sentryfunctions
social_auth: 0002_default_auto_field
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -554,8 +554,7 @@ disable_error_code = [
module = [
"sentry.api.endpoints.issues.*",
"sentry.api.helpers.source_map_helper",
"sentry.buffer.base",
"sentry.buffer.redis",
"sentry.buffer.*",
"sentry.build.*",
"sentry.eventstore.reprocessing.redis",
"sentry.hybridcloud",
Expand Down Expand Up @@ -617,7 +616,6 @@ module = [
"sentry.services.hybrid_cloud.notifications.*",
"sentry.services.hybrid_cloud.organization_actions.*",
"sentry.services.hybrid_cloud.organization_mapping.*",
"sentry.services.hybrid_cloud.organization_provisioning.*",
"sentry.services.hybrid_cloud.organizationmember_mapping.*",
"sentry.services.hybrid_cloud.orgauthtoken.*",
"sentry.services.hybrid_cloud.pagination",
Expand Down
14 changes: 0 additions & 14 deletions src/sentry/api/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@ class OrganizationSavedSearchDeletedEvent(analytics.Event):
)


class FunctionTimerEvent(analytics.Event):
type = "function_timer.timed"

attributes = (
analytics.Attribute("function_name"),
analytics.Attribute("duration"),
analytics.Attribute("organization_id"),
analytics.Attribute("project_id"),
analytics.Attribute("group_id", required=False),
analytics.Attribute("frame_abs_path", required=False),
)


class GroupSimilarIssuesEmbeddingsCountEvent(analytics.Event):
type = "group_similar_issues_embeddings.count"

Expand All @@ -48,5 +35,4 @@ class GroupSimilarIssuesEmbeddingsCountEvent(analytics.Event):

analytics.register(OrganizationSavedSearchCreatedEvent)
analytics.register(OrganizationSavedSearchDeletedEvent)
analytics.register(FunctionTimerEvent)
analytics.register(GroupSimilarIssuesEmbeddingsCountEvent)
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/event_ai_suggested_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def describe_event_for_ai(event, model):
detailed = model.startswith("gpt-4")
data = {}

msg = event.get("message")
msg = event.get("logentry")
if msg:
data["message"] = msg

Expand Down
14 changes: 3 additions & 11 deletions src/sentry/api/endpoints/issues/related_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from sentry.api.api_publish_status import ApiPublishStatus
from sentry.api.base import region_silo_endpoint
from sentry.api.bases.group import GroupEndpoint
from sentry.issues.related import find_related_issues # To be deprecated
from sentry.issues.related import RELATED_ISSUES_ALGORITHMS
from sentry.models.group import Group
from sentry.types.ratelimit import RateLimit, RateLimitCategory
Expand Down Expand Up @@ -35,13 +34,6 @@ def get(self, request: Request, group: Group) -> Response:
:pparam Group group: the group object
"""
# The type of related issues to retrieve. Can be either `same_root_cause` or `trace_connected`.
related_type = request.query_params.get("type")
related_issues: list[dict[str, str | list[int] | dict[str, str]]] = []

if related_type in RELATED_ISSUES_ALGORITHMS:
data, meta = RELATED_ISSUES_ALGORITHMS[related_type](group)
return Response({"type": related_type, "data": data, "meta": meta})
else:
# XXX: We will be deprecating this approach soon
related_issues = find_related_issues(group)
return Response({"data": [related_set for related_set in related_issues]})
related_type = request.query_params["type"]
data, meta = RELATED_ISSUES_ALGORITHMS[related_type](group)
return Response({"type": related_type, "data": data, "meta": meta})
4 changes: 2 additions & 2 deletions src/sentry/api/endpoints/organization_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,8 @@ class OrganizationMetricsDataEndpoint(OrganizationEndpoint):
Based on `OrganizationSessionsEndpoint`.
"""

# still 40 req/s but allows for bursts of 200 up to req/s for dashboard loading
default_rate_limit = RateLimit(limit=200, window=5)
# 60 req/s to allow for metric dashboard loading
default_rate_limit = RateLimit(limit=60, window=1)

rate_limits = {
"GET": {
Expand Down
34 changes: 21 additions & 13 deletions src/sentry/api/endpoints/organization_unsubscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class OrganizationUnsubscribeBase(Endpoint, Generic[T]):

object_type = "unknown"

def fetch_instance(self, request: Request, organization_slug: str, id: int) -> T:
def fetch_instance(self, request: Request, organization_id_or_slug: int | str, id: int) -> T:
raise NotImplementedError()

def unsubscribe(self, request: Request, instance: T):
Expand All @@ -46,10 +46,12 @@ def unsubscribe(self, request: Request, instance: T):
def add_instance_data(self, data: dict[str, Any], instance: T) -> dict[str, Any]:
return data

def get(self, request: Request, organization_slug: str, id: int, **kwargs) -> Response:
def get(
self, request: Request, organization_id_or_slug: int | str, id: int, **kwargs
) -> Response:
if not request.user_from_signed_request:
raise NotFound()
instance = self.fetch_instance(request, organization_slug, id)
instance = self.fetch_instance(request, organization_id_or_slug, id)
view_url = ""
if hasattr(instance, "get_absolute_url"):
view_url = str(instance.get_absolute_url())
Expand All @@ -65,10 +67,12 @@ def get(self, request: Request, organization_slug: str, id: int, **kwargs) -> Re
}
return Response(self.add_instance_data(data, instance), 200)

def post(self, request: Request, organization_slug: str, id: int, **kwargs) -> Response:
def post(
self, request: Request, organization_id_or_slug: int | str, id: int, **kwargs
) -> Response:
if not request.user_from_signed_request:
raise NotFound()
instance = self.fetch_instance(request, organization_slug, id)
instance = self.fetch_instance(request, organization_id_or_slug, id)

if request.data.get("cancel"):
self.unsubscribe(request, instance)
Expand All @@ -79,16 +83,18 @@ def post(self, request: Request, organization_slug: str, id: int, **kwargs) -> R
class OrganizationUnsubscribeProject(OrganizationUnsubscribeBase[Project]):
object_type = "project"

def fetch_instance(self, request: Request, organization_slug: str, id: int) -> Project:
def fetch_instance(
self, request: Request, organization_id_or_slug: int | str, id: int
) -> Project:
try:
project = Project.objects.select_related("organization").get(id=id)
except Project.DoesNotExist:
raise NotFound()
if str(organization_slug).isdecimal():
if project.organization.id != int(organization_slug):
if str(organization_id_or_slug).isdecimal():
if project.organization.id != int(organization_id_or_slug):
raise NotFound()
else:
if project.organization.slug != organization_slug:
if project.organization.slug != organization_id_or_slug:
raise NotFound()
if not OrganizationMember.objects.filter(
user_id=request.user.pk, organization_id=project.organization_id
Expand All @@ -115,16 +121,18 @@ def unsubscribe(self, request: Request, instance: Project):
class OrganizationUnsubscribeIssue(OrganizationUnsubscribeBase[Group]):
object_type = "issue"

def fetch_instance(self, request: Request, organization_slug: str, issue_id: int) -> Group:
def fetch_instance(
self, request: Request, organization_id_or_slug: int | str, issue_id: int
) -> Group:
try:
issue = Group.objects.get_from_cache(id=issue_id)
except Group.DoesNotExist:
raise NotFound()
if str(organization_slug).isdecimal():
if issue.organization.id != int(organization_slug):
if str(organization_id_or_slug).isdecimal():
if issue.organization.id != int(organization_id_or_slug):
raise NotFound()
else:
if issue.organization.slug != organization_slug:
if issue.organization.slug != organization_id_or_slug:
raise NotFound()

if not OrganizationMember.objects.filter(
Expand Down
34 changes: 17 additions & 17 deletions src/sentry/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1643,47 +1643,47 @@ def create_group_urls(name_prefix: str) -> list[URLPattern | URLResolver]:
),
# Monitors
re_path(
r"^(?P<organization_slug>[^\/]+)/monitors/$",
r"^(?P<organization_id_or_slug>[^\/]+)/monitors/$",
OrganizationMonitorIndexEndpoint.as_view(),
name="sentry-api-0-organization-monitor-index",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/monitors-stats/$",
r"^(?P<organization_id_or_slug>[^\/]+)/monitors-stats/$",
OrganizationMonitorIndexStatsEndpoint.as_view(),
name="sentry-api-0-organization-monitor-index-stats",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/processing-errors/$",
r"^(?P<organization_id_or_slug>[^\/]+)/processing-errors/$",
OrganizationMonitorProcessingErrorsIndexEndpoint.as_view(),
name="sentry-api-0-organization-monitor-processing-errors-index",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/monitors-schedule-data/$",
r"^(?P<organization_id_or_slug>[^\/]+)/monitors-schedule-data/$",
OrganizationMonitorScheduleSampleDataEndpoint.as_view(),
name="sentry-api-0-organization-monitors-schedule-sample-data",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/$",
r"^(?P<organization_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/$",
OrganizationMonitorDetailsEndpoint.as_view(),
name="sentry-api-0-organization-monitor-details",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/environments/(?P<environment>[^\/]+)$",
r"^(?P<organization_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/environments/(?P<environment>[^\/]+)$",
OrganizationMonitorEnvironmentDetailsEndpoint.as_view(),
name="sentry-api-0-organization-monitor-environment-details",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/stats/$",
r"^(?P<organization_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/stats/$",
OrganizationMonitorStatsEndpoint.as_view(),
name="sentry-api-0-organization-monitor-stats",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/checkins/$",
r"^(?P<organization_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/checkins/$",
OrganizationMonitorCheckInIndexEndpoint.as_view(),
name="sentry-api-0-organization-monitor-check-in-index",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/attachment/$",
r"^(?P<organization_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/attachment/$",
method_dispatch(
GET=OrganizationMonitorCheckInAttachmentEndpoint.as_view(),
OPTIONS=OrganizationMonitorCheckInAttachmentEndpoint.as_view(),
Expand Down Expand Up @@ -2120,12 +2120,12 @@ def create_group_urls(name_prefix: str) -> list[URLPattern | URLResolver]:
),
# Unsubscribe from organization notifications
re_path(
r"^(?P<organization_slug>[^/]+)/unsubscribe/project/(?P<id>\d+)/$",
r"^(?P<organization_id_or_slug>[^/]+)/unsubscribe/project/(?P<id>\d+)/$",
OrganizationUnsubscribeProject.as_view(),
name="sentry-api-0-organization-unsubscribe-project",
),
re_path(
r"^(?P<organization_slug>[^/]+)/unsubscribe/issue/(?P<id>\d+)/$",
r"^(?P<organization_id_or_slug>[^/]+)/unsubscribe/issue/(?P<id>\d+)/$",
OrganizationUnsubscribeIssue.as_view(),
name="sentry-api-0-organization-unsubscribe-issue",
),
Expand Down Expand Up @@ -2743,22 +2743,22 @@ def create_group_urls(name_prefix: str) -> list[URLPattern | URLResolver]:
name="sentry-api-0-project-statistical-detector",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/attachment/$",
r"^(?P<organization_id_or_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/checkins/(?P<checkin_id>[^\/]+)/attachment/$",
ProjectMonitorCheckInAttachmentEndpoint.as_view(),
name="sentry-api-0-project-monitor-check-in-attachment",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/$",
r"^(?P<organization_id_or_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/$",
ProjectMonitorDetailsEndpoint.as_view(),
name="sentry-api-0-project-monitor-details",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/checkins/$",
r"^(?P<organization_id_or_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/checkins/$",
ProjectMonitorCheckInIndexEndpoint.as_view(),
name="sentry-api-0-project-monitor-check-in-index",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/environments/(?P<environment>[^\/]+)$",
r"^(?P<organization_id_or_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/environments/(?P<environment>[^\/]+)$",
ProjectMonitorEnvironmentDetailsEndpoint.as_view(),
name="sentry-api-0-project-monitor-environment-details",
),
Expand All @@ -2768,12 +2768,12 @@ def create_group_urls(name_prefix: str) -> list[URLPattern | URLResolver]:
name="sentry-api-0-project-processing-errors-details",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/processing-errors/$",
r"^(?P<organization_id_or_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/processing-errors/$",
ProjectMonitorProcessingErrorsIndexEndpoint.as_view(),
name="sentry-api-0-project-monitor-processing-errors-index",
),
re_path(
r"^(?P<organization_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/stats/$",
r"^(?P<organization_id_or_slug>[^\/]+)/(?P<project_id_or_slug>[^\/]+)/monitors/(?P<monitor_id_or_slug>[^\/]+)/stats/$",
ProjectMonitorStatsEndpoint.as_view(),
name="sentry-api-0-project-monitor-stats",
),
Expand Down
Loading

0 comments on commit 422da91

Please sign in to comment.