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

Add service dependencies feature flag #5420

Merged
merged 2 commits into from
Jan 20, 2025
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
28 changes: 28 additions & 0 deletions engine/apps/api/tests/test_alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,9 @@ def test_alert_group_affected_services(
make_user_for_organization,
make_user_auth_headers,
make_alert_group_label_association,
settings,
):
settings.FEATURE_SERVICE_DEPENDENCIES_ENABLED = True
_, token, alert_groups = alert_group_internal_api_setup
resolved_ag, ack_ag, new_ag, silenced_ag = alert_groups
organization = new_ag.channel.organization
Expand Down Expand Up @@ -2454,3 +2456,29 @@ def test_alert_group_affected_services(
},
]
assert response.json() == expected


@pytest.mark.django_db
def test_alert_group_service_dependencies_feature_not_enabled(
alert_group_internal_api_setup,
make_user_for_organization,
make_user_auth_headers,
make_alert_group_label_association,
settings,
):
settings.FEATURE_SERVICE_DEPENDENCIES_ENABLED = False
_, token, alert_groups = alert_group_internal_api_setup
_, _, new_ag, _ = alert_groups
organization = new_ag.channel.organization
user = make_user_for_organization(organization)

# set firing alert group service label
make_alert_group_label_association(organization, new_ag, key_name="service_name", value_name="service-a")

client = APIClient()
url = reverse("api-internal:alertgroup-filter-affected-services")

url = f"{url}?service=service-1"
response = client.get(url, format="json", **make_user_auth_headers(user, token))

assert response.status_code == status.HTTP_404_NOT_FOUND
2 changes: 2 additions & 0 deletions engine/apps/api/views/alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,8 @@ def escalation_snapshot(self, request, pk=None):
@action(methods=["get"], detail=False)
def filter_affected_services(self, request):
"""Given a list of service names, return the ones that have active alerts."""
if not settings.FEATURE_SERVICE_DEPENDENCIES_ENABLED:
raise NotFound
organization = self.request.auth.organization
services = self.request.query_params.getlist("service", [])
url_builder = UIURLBuilder(organization)
Expand Down
4 changes: 4 additions & 0 deletions engine/apps/api/views/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Feature(enum.StrEnum):
GRAFANA_ALERTING_V2 = "grafana_alerting_v2"
LABELS = "labels"
GOOGLE_OAUTH2 = "google_oauth2"
SERVICE_DEPENDENCIES = "service_dependencies"


class FeaturesAPIView(APIView):
Expand Down Expand Up @@ -72,4 +73,7 @@ def _get_enabled_features(self, request):
if settings.GOOGLE_OAUTH2_ENABLED:
enabled_features.append(Feature.GOOGLE_OAUTH2)

if settings.FEATURE_SERVICE_DEPENDENCIES_ENABLED:
enabled_features.append(Feature.SERVICE_DEPENDENCIES)

return enabled_features
1 change: 1 addition & 0 deletions engine/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
FEATURE_ALERT_GROUP_SEARCH_CUTOFF_DAYS = getenv_integer("FEATURE_ALERT_GROUP_SEARCH_CUTOFF_DAYS", default=None)
FEATURE_NOTIFICATION_BUNDLE_ENABLED = getenv_boolean("FEATURE_NOTIFICATION_BUNDLE_ENABLED", default=True)
FEATURE_DECLARE_INCIDENT_STEP_ENABLED = getenv_boolean("FEATURE_DECLARE_INCIDENT_STEP_ENABLED", default=False)
FEATURE_SERVICE_DEPENDENCIES_ENABLED = getenv_boolean("FEATURE_SERVICE_DEPENDENCIES_ENABLED", default=False)

TWILIO_API_KEY_SID = os.environ.get("TWILIO_API_KEY_SID")
TWILIO_API_KEY_SECRET = os.environ.get("TWILIO_API_KEY_SECRET")
Expand Down
Loading