Add service dependencies feature flag (#5420)

# What this PR does

Adds `service_dependencies` feature flag

## Which issue(s) this PR closes

Related to https://github.com/grafana/oncall-private/issues/2977

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required)
- [x] Added the relevant release notes label (see labels prefixed w/
`release:`). These labels dictate how your PR will
    show up in the autogenerated release notes.
This commit is contained in:
Julia Artyukhina 2025-01-20 16:49:59 +01:00 committed by GitHub
parent 2a87bea6ed
commit 94e5d490b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 35 additions and 0 deletions

View file

@ -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
@ -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

View file

@ -916,6 +916,8 @@ class AlertGroupView(
@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)

View file

@ -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):
@ -72,4 +73,7 @@ class FeaturesAPIView(APIView):
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

View file

@ -76,6 +76,7 @@ FEATURE_ALERT_GROUP_SEARCH_ENABLED = getenv_boolean("FEATURE_ALERT_GROUP_SEARCH_
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")