Browse Source

ref: delete sentry-functions (#70091)

feature was never launched, causing some issues with import cycles while
upgrading django-stubs

<!-- Describe your PR here. -->

---------

Co-authored-by: getsantry[bot] <66042841+getsantry[bot]@users.noreply.github.com>
anthony sottile 10 months ago
parent
commit
7196177711

+ 0 - 1
pyproject.toml

@@ -394,7 +394,6 @@ module = [
     "sentry.plugins.providers.base",
     "sentry.plugins.providers.repository",
     "sentry.receivers.releases",
-    "sentry.receivers.sentry_apps",
     "sentry.release_health.metrics_sessions_v2",
     "sentry.release_health.tasks",
     "sentry.replays.endpoints.project_replay_clicks_index",

+ 0 - 77
src/sentry/api/endpoints/organization_sentry_function.py

@@ -1,77 +0,0 @@
-from uuid import uuid4
-
-from rest_framework import serializers
-from rest_framework.response import Response
-
-from sentry import features
-from sentry.api.api_owners import ApiOwner
-from sentry.api.api_publish_status import ApiPublishStatus
-from sentry.api.base import region_silo_endpoint
-from sentry.api.bases import OrganizationEndpoint
-from sentry.api.helpers.slugs import sentry_slugify
-from sentry.api.serializers import serialize
-from sentry.api.serializers.rest_framework import CamelSnakeSerializer
-from sentry.models.sentryfunction import SentryFunction
-from sentry.utils.cloudfunctions import create_function
-
-
-class EnvVariableSerializer(CamelSnakeSerializer):
-    value = serializers.CharField(required=True, allow_blank=False, allow_null=False)
-    name = serializers.CharField(required=True, allow_blank=False, allow_null=False)
-
-
-class SentryFunctionSerializer(CamelSnakeSerializer):
-    name = serializers.CharField(required=True)
-    author = serializers.CharField(required=False, allow_blank=True, allow_null=True)
-    code = serializers.CharField(required=True)
-    overview = serializers.CharField(required=False, allow_blank=True, allow_null=True)
-    events = serializers.ListField(child=serializers.CharField(), required=False)
-    env_variables = serializers.ListField(child=EnvVariableSerializer())
-
-    def validate_env_variables(self, env_variables):
-        """
-        Convert env_variables from a list of dicts to a dict of key-value pairs
-        """
-        output = {}
-        for env_variable in env_variables:
-            output[env_variable["name"]] = env_variable["value"]
-        return output
-
-
-@region_silo_endpoint
-class OrganizationSentryFunctionEndpoint(OrganizationEndpoint):
-    owner = ApiOwner.INTEGRATIONS
-    publish_status = {
-        "GET": ApiPublishStatus.PRIVATE,
-        "POST": ApiPublishStatus.PRIVATE,
-    }
-
-    # Creating a new sentry function
-
-    def post(self, request, organization):
-        if not features.has("organizations:sentry-functions", organization, actor=request.user):
-            return Response("organizations:sentry-functions flag set to false", status=404)
-        serializer = SentryFunctionSerializer(data=request.data)
-        if not serializer.is_valid():
-            return Response(serializer.errors, status=400)
-
-        data = serializer.validated_data
-        # sentry_slugify ensures the slug is not entirely numeric
-        data["slug"] = sentry_slugify(data["name"])
-
-        # TODO: Make sure the slug is unique
-        # Currently slug unique within organization
-        # In future, may add "global_slug" so users can publish their functions
-        data["organization_id"] = organization.id
-        data["external_id"] = data["slug"] + "-" + uuid4().hex
-        create_function(
-            data["code"], data["external_id"], data.get("overview", None), data["env_variables"]
-        )
-        function = SentryFunction.objects.create(**data)
-        return Response(serialize(function), status=201)
-
-    def get(self, request, organization):
-        if not features.has("organizations:sentry-functions", organization, actor=request.user):
-            return Response("organizations:sentry-functions flag set to false", status=404)
-        functions = SentryFunction.objects.filter(organization=organization)
-        return Response(serialize(list(functions), request.user), status=200)

+ 0 - 87
src/sentry/api/endpoints/organization_sentry_function_details.py

@@ -1,87 +0,0 @@
-from django.http import Http404
-from google.api_core.exceptions import FailedPrecondition, InvalidArgument, NotFound
-from rest_framework.exceptions import ParseError
-from rest_framework.response import Response
-
-from sentry import features
-from sentry.api.api_owners import ApiOwner
-from sentry.api.api_publish_status import ApiPublishStatus
-from sentry.api.base import region_silo_endpoint
-from sentry.api.bases import OrganizationEndpoint
-from sentry.api.endpoints.organization_sentry_function import SentryFunctionSerializer
-from sentry.api.serializers import serialize
-from sentry.api.utils import id_or_slug_path_params_enabled
-from sentry.models.sentryfunction import SentryFunction
-from sentry.utils.cloudfunctions import delete_function, update_function
-
-
-@region_silo_endpoint
-class OrganizationSentryFunctionDetailsEndpoint(OrganizationEndpoint):
-    owner = ApiOwner.INTEGRATIONS
-    publish_status = {
-        "DELETE": ApiPublishStatus.PRIVATE,
-        "GET": ApiPublishStatus.PRIVATE,
-        "PUT": ApiPublishStatus.PRIVATE,
-    }
-
-    def convert_args(self, request, organization_slug, function_id_or_slug, *args, **kwargs):
-        args, kwargs = super().convert_args(request, organization_slug, *args, **kwargs)
-
-        try:
-            if id_or_slug_path_params_enabled(self.convert_args.__qualname__):
-                function = SentryFunction.objects.get(
-                    slug__id_or_slug=function_id_or_slug, organization=kwargs["organization"].id
-                )
-            else:
-                function = SentryFunction.objects.get(
-                    slug=function_id_or_slug, organization=kwargs["organization"].id
-                )
-        except SentryFunction.DoesNotExist:
-            raise Http404
-
-        kwargs["function"] = function
-        return (args, kwargs)
-
-    def get(self, request, organization, function):
-        if not features.has("organizations:sentry-functions", organization, actor=request.user):
-            return Response(status=404)
-        return Response(serialize(function), status=200)
-
-    def put(self, request, organization, function):
-        if not features.has("organizations:sentry-functions", organization, actor=request.user):
-            return Response(status=404)
-        serializer = SentryFunctionSerializer(data=request.data)
-        if not serializer.is_valid():
-            return Response(serializer.errors, status=400)
-
-        data = serializer.validated_data
-
-        try:
-            update_function(
-                data.get("code"),
-                function.external_id,
-                data.get("overview", None),
-                data["env_variables"],
-            )
-            function.update(**data)
-            return Response(serialize(function), status=201)
-        except FailedPrecondition:
-            raise ParseError(detail="Function is currently busy, try again later.")
-
-    def delete(self, request, organization, function):
-        # If the function is being executed, the delete request will stop the function
-        # from executing and delete the function.
-        # If an operation is being performed on the function, the delete request will
-        # not go through
-        try:
-            delete_function(function.external_id)
-        except FailedPrecondition:
-            raise ParseError(detail="Function is currently busy, try again later.")
-        except InvalidArgument:
-            return Response(status=400)
-        except NotFound:
-            return Response(status=404)
-        SentryFunction.objects.filter(
-            organization=organization, name=function.name, external_id=function.external_id
-        ).delete()
-        return Response(status=204)

+ 0 - 1
src/sentry/api/serializers/models/__init__.py

@@ -76,7 +76,6 @@ from .sentry_app import *  # noqa: F401,F403
 from .sentry_app_avatar import *  # noqa: F401,F403
 from .sentry_app_component import *  # noqa: F401,F403
 from .sentry_app_installation import *  # noqa: F401,F403
-from .sentry_function import *  # noqa: F401,F403
 from .servicehook import *  # noqa: F401,F403
 from .tagvalue import *  # noqa: F401,F403
 from .team import *  # noqa: F401,F403

+ 0 - 25
src/sentry/api/serializers/models/sentry_function.py

@@ -1,25 +0,0 @@
-from sentry.api.serializers import Serializer, register
-from sentry.models.sentryfunction import SentryFunction
-
-
-@register(SentryFunction)
-class SentryFunctionSerializer(Serializer):
-    def serialize(self, obj, attrs, user):
-        events = [event for event in obj.events]
-        env_variables = list(
-            map(
-                lambda env_variable: {"name": env_variable[0], "value": env_variable[1]},
-                obj.env_variables.items(),
-            )
-        )
-        data = {
-            "name": obj.name,
-            "slug": obj.slug,
-            "author": obj.author,
-            "code": obj.code,
-            "overview": obj.overview,
-            "external_id": obj.external_id,
-            "events": events,
-            "env_variables": env_variables,
-        }
-        return data

+ 0 - 14
src/sentry/api/urls.py

@@ -460,10 +460,6 @@ from .endpoints.organization_sdk_updates import (
     OrganizationSdkUpdatesEndpoint,
 )
 from .endpoints.organization_search_details import OrganizationSearchDetailsEndpoint
-from .endpoints.organization_sentry_function import OrganizationSentryFunctionEndpoint
-from .endpoints.organization_sentry_function_details import (
-    OrganizationSentryFunctionDetailsEndpoint,
-)
 from .endpoints.organization_sessions import OrganizationSessionsEndpoint
 from .endpoints.organization_shortid import ShortIdLookupEndpoint
 from .endpoints.organization_slugs import SlugsUpdateEndpoint
@@ -1984,16 +1980,6 @@ ORGANIZATION_URLS = [
         OrganizationReplayEventsMetaEndpoint.as_view(),
         name="sentry-api-0-organization-replay-events-meta",
     ),
-    re_path(
-        r"^(?P<organization_slug>[^\/]+)/functions/$",
-        OrganizationSentryFunctionEndpoint.as_view(),
-        name="sentry-api-0-organization-sentry-functions",
-    ),
-    re_path(
-        r"^(?P<organization_slug>[^\/]+)/functions/(?P<function_id_or_slug>[^\/]+)/$",
-        OrganizationSentryFunctionDetailsEndpoint.as_view(),
-        name="sentry-api-0-organization-sentry-function-details",
-    ),
     re_path(
         r"^(?P<organization_slug>[^\/]+)/request-project-creation/$",
         OrganizationRequestProjectCreation.as_view(),

+ 0 - 1
src/sentry/conf/api_pagination_allowlist_do_not_modify.py

@@ -62,7 +62,6 @@ SENTRY_API_PAGINATION_ALLOWLIST_DO_NOT_MODIFY = {
     "OrganizationRepositoriesEndpoint",
     "OrganizationSdkUpdatesEndpoint",
     "OrganizationSearchesEndpoint",
-    "OrganizationSentryFunctionEndpoint",
     "OrganizationStatsEndpoint",
     "OrganizationTagsEndpoint",
     "OrganizationUserDetailsEndpoint",

+ 0 - 2
src/sentry/conf/server.py

@@ -1817,8 +1817,6 @@ SENTRY_FEATURES: dict[str, bool | None] = {
     "organizations:scim-team-roles": False,
     # Enable detecting SDK crashes during event processing
     "organizations:sdk-crash-detection": False,
-    # Enable Sentry Functions
-    "organizations:sentry-functions": False,
     # Replace the footer Sentry logo with a Sentry pride logo
     "organizations:sentry-pride-logo-footer": False,
     # Enable core Session Replay backend APIs

+ 0 - 1
src/sentry/features/temporary.py

@@ -193,7 +193,6 @@ def register_temporary_features(manager: FeatureManager):
     manager.add("organizations:sandbox-kill-switch", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
     manager.add("organizations:scim-team-roles", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
     manager.add("organizations:sdk-crash-detection", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
-    manager.add("organizations:sentry-functions", OrganizationFeature, FeatureHandlerStrategy.INTERNAL)
     manager.add("organizations:sentry-pride-logo-footer", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
     manager.add("organizations:session-replay-a11y-tab", OrganizationFeature, FeatureHandlerStrategy.REMOTE)
     manager.add("organizations:session-replay-accessibility-issues", OrganizationFeature, FeatureHandlerStrategy.REMOTE)

+ 2 - 0
src/sentry/models/sentryfunction.py

@@ -17,6 +17,8 @@ class SentryFunctionManager(BaseManager["SentryFunction"]):
 
 @region_silo_model
 class SentryFunction(DefaultFieldsModel):
+    """UNUSED! WILL BE DELETED!"""
+
     __relocation_scope__ = RelocationScope.Excluded
 
     organization = FlexibleForeignKey("sentry.Organization")

Some files were not shown because too many files changed in this diff