Skip to content

Commit

Permalink
Add service dependencies feature flag (#5420)
Browse files Browse the repository at this point in the history
# What this PR does

Adds `service_dependencies` feature flag

## Which issue(s) this PR closes

Related to grafana/oncall-private#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.
  • Loading branch information
Ferril authored Jan 20, 2025
1 parent 2a87bea commit 94e5d49
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
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

0 comments on commit 94e5d49

Please sign in to comment.