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(similarity): Turn on ML grouping for new EA projects #75026

Merged
merged 4 commits into from
Jul 26, 2024
Merged
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: 12 additions & 0 deletions src/sentry/api/endpoints/team_projects.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -214,4 +217,13 @@ def post(self, request: Request, team) -> Response:
sender=self,
)

# Create project option to turn on ML similarity feature for new EA projects
is_seer_eligible_platform = project.platform in SEER_ELIGIBLE_PLATFORMS
if (
project.organization.flags
and project.organization.flags.early_adopter
and is_seer_eligible_platform
):
project.update_option("sentry:similarity_backfill_completed", int(time.time()))

return Response(serialize(project, request.user), status=201)
67 changes: 67 additions & 0 deletions tests/sentry/api/endpoints/test_team_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 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
Comment on lines +257 to +260
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to assert on these? Do they have anything to do with the projectoption? (Same question for the test below.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I just included these to ensure that the change doesn't mess up project creation at all


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
)
Loading