From 9bb54d114400839622e905a87d8758863db1a901 Mon Sep 17 00:00:00 2001 From: Jodi Jang Date: Thu, 25 Jul 2024 15:04:55 -0700 Subject: [PATCH 1/3] chore(similarity): Turn on ML grouping for new EA projects --- src/sentry/api/endpoints/team_projects.py | 15 +++++ .../api/endpoints/test_team_projects.py | 67 +++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/src/sentry/api/endpoints/team_projects.py b/src/sentry/api/endpoints/team_projects.py index 8541eb43ed71f9..d4042db696c7fb 100644 --- a/src/sentry/api/endpoints/team_projects.py +++ b/src/sentry/api/endpoints/team_projects.py @@ -1,3 +1,5 @@ +import time + from django.db import IntegrityError, router, transaction from drf_spectacular.utils import OpenApiResponse, extend_schema from rest_framework import serializers, status @@ -21,6 +23,7 @@ from sentry.apidocs.utils import inline_sentry_response_serializer from sentry.constants import RESERVED_PROJECT_SLUGS, ObjectStatus from sentry.models.project import Project +from sentry.seer.similarity.utils import SEER_ELIGIBLE_PLATFORMS from sentry.signals import project_created from sentry.utils.snowflake import MaxSnowflakeRetryError @@ -214,4 +217,16 @@ def post(self, request: Request, team) -> Response: sender=self, ) + # Create project option to turn on ML similarity feature for new EA projects + seer_eligible_platform = ( + project.platform and project.platform in SEER_ELIGIBLE_PLATFORMS + ) + if ( + project + and project.organization.flags + and project.organization.flags.early_adopter + and seer_eligible_platform + ): + project.update_option("sentry:similarity_backfill_completed", int(time.time())) + return Response(serialize(project, request.user), status=201) diff --git a/tests/sentry/api/endpoints/test_team_projects.py b/tests/sentry/api/endpoints/test_team_projects.py index 03ebcb4eff6084..9dc8e66091f4f3 100644 --- a/tests/sentry/api/endpoints/test_team_projects.py +++ b/tests/sentry/api/endpoints/test_team_projects.py @@ -3,6 +3,7 @@ from sentry.api.endpoints.organization_projects_experiment import DISABLED_FEATURE_ERROR_STRING from sentry.constants import RESERVED_PROJECT_SLUGS from sentry.ingest import inbound_filters +from sentry.models.options.project_option import ProjectOption from sentry.models.project import Project from sentry.models.rule import Rule from sentry.notifications.types import FallthroughChoiceType @@ -65,6 +66,14 @@ def test_simple(self): assert project.platform == "python" assert project.teams.first() == self.team + # Assert project option is not set for non-EA organizations + assert ( + ProjectOption.objects.get_value( + project=project, key="sentry:similarity_backfill_completed" + ) + is None + ) + def test_invalid_numeric_slug(self): response = self.get_error_response( self.organization.slug, @@ -228,3 +237,61 @@ def test_default_inbound_filters(self): } assert javascript_filter_states["web-crawlers"] assert javascript_filter_states["filtered-transaction"] + + def test_similarity_project_option_valid(self): + """ + Test that project option for similarity grouping is created for EA organizations + where the project platform is python and seer eligible. + """ + + self.organization.flags.early_adopter = True + self.organization.save() + response = self.get_success_response( + self.organization.slug, + self.team.slug, + **self.data, + status_code=201, + ) + + project = Project.objects.get(id=response.data["id"]) + assert project.name == "foo" + assert project.slug == "bar" + assert project.platform == "python" + assert project.teams.first() == self.team + + assert ( + ProjectOption.objects.get_value( + project=project, key="sentry:similarity_backfill_completed" + ) + is not None + ) + + def test_similarity_project_option_invalid(self): + """ + Test that project option for similarity grouping is not created for EA organizations + where the project platform is not seer eligible. + """ + + self.organization.flags.early_adopter = True + self.organization.save() + response = self.get_success_response( + self.organization.slug, + self.team.slug, + name="foo", + slug="bar", + platform="php", + status_code=201, + ) + + project = Project.objects.get(id=response.data["id"]) + assert project.name == "foo" + assert project.slug == "bar" + assert project.platform == "php" + assert project.teams.first() == self.team + + assert ( + ProjectOption.objects.get_value( + project=project, key="sentry:similarity_backfill_completed" + ) + is None + ) From 412694dce0ee343c8538c6c739a78fde2e4131ba Mon Sep 17 00:00:00 2001 From: Jodi Jang Date: Thu, 25 Jul 2024 15:41:07 -0700 Subject: [PATCH 2/3] fix: Clean up logic --- src/sentry/api/endpoints/team_projects.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/sentry/api/endpoints/team_projects.py b/src/sentry/api/endpoints/team_projects.py index d4042db696c7fb..fb21d86495f4ba 100644 --- a/src/sentry/api/endpoints/team_projects.py +++ b/src/sentry/api/endpoints/team_projects.py @@ -218,12 +218,9 @@ def post(self, request: Request, team) -> Response: ) # Create project option to turn on ML similarity feature for new EA projects - seer_eligible_platform = ( - project.platform and project.platform in SEER_ELIGIBLE_PLATFORMS - ) + seer_eligible_platform = project.platform in SEER_ELIGIBLE_PLATFORMS if ( - project - and project.organization.flags + project.organization.flags and project.organization.flags.early_adopter and seer_eligible_platform ): From 984aeb3121a7b9c1c2a67efad56f196cd850b6b6 Mon Sep 17 00:00:00 2001 From: Jodi Jang Date: Fri, 26 Jul 2024 08:15:22 -0700 Subject: [PATCH 3/3] ref: Reword --- src/sentry/api/endpoints/team_projects.py | 4 ++-- tests/sentry/api/endpoints/test_team_projects.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/sentry/api/endpoints/team_projects.py b/src/sentry/api/endpoints/team_projects.py index fb21d86495f4ba..2772cec9ae0733 100644 --- a/src/sentry/api/endpoints/team_projects.py +++ b/src/sentry/api/endpoints/team_projects.py @@ -218,11 +218,11 @@ def post(self, request: Request, team) -> Response: ) # Create project option to turn on ML similarity feature for new EA projects - seer_eligible_platform = project.platform in SEER_ELIGIBLE_PLATFORMS + is_seer_eligible_platform = project.platform in SEER_ELIGIBLE_PLATFORMS if ( project.organization.flags and project.organization.flags.early_adopter - and seer_eligible_platform + and is_seer_eligible_platform ): project.update_option("sentry:similarity_backfill_completed", int(time.time())) diff --git a/tests/sentry/api/endpoints/test_team_projects.py b/tests/sentry/api/endpoints/test_team_projects.py index 9dc8e66091f4f3..6e8b9b0899dc7f 100644 --- a/tests/sentry/api/endpoints/test_team_projects.py +++ b/tests/sentry/api/endpoints/test_team_projects.py @@ -241,7 +241,7 @@ def test_default_inbound_filters(self): def test_similarity_project_option_valid(self): """ Test that project option for similarity grouping is created for EA organizations - where the project platform is python and seer eligible. + where the project platform is Seer-eligible. """ self.organization.flags.early_adopter = True