From 0acb66bd1a86c0b5ff58d6d887d745c4c0632307 Mon Sep 17 00:00:00 2001 From: Andrey Oleynik Date: Tue, 4 Jun 2024 14:51:02 +0300 Subject: [PATCH] conditionally enable searching for alert groups via env var (#4287) # What this PR does re-enables the search for alert groups ## Which issue(s) this PR closes Closes #2232 ## 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. --------- Co-authored-by: Joey Orlando Co-authored-by: Joey Orlando --- engine/apps/api/views/alert_group.py | 6 ++++++ engine/settings/base.py | 1 + grafana-plugin/src/models/alertgroup/alertgroup.ts | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index f47f3ccf..96d49ade 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -1,5 +1,6 @@ import typing +from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.db.models import Count, Max, Q from django_filters import rest_framework as filters @@ -275,6 +276,11 @@ class AlertGroupView( pagination_class = AlertGroupCursorPaginator filter_backends = [SearchFilter, filters.DjangoFilterBackend] + search_fields = ( + ["=public_primary_key", "=inside_organization_number", "web_title_cache"] + if settings.FEATURE_ALERT_GROUP_SEARCH_ENABLED + else [] + ) filterset_class = AlertGroupFilter def get_serializer_class(self): diff --git a/engine/settings/base.py b/engine/settings/base.py index c528ba3c..eef9d16e 100644 --- a/engine/settings/base.py +++ b/engine/settings/base.py @@ -71,6 +71,7 @@ GRAFANA_CLOUD_NOTIFICATIONS_ENABLED = getenv_boolean("GRAFANA_CLOUD_NOTIFICATION FEATURE_LABELS_ENABLED_FOR_ALL = getenv_boolean("FEATURE_LABELS_ENABLED_FOR_ALL", default=False) # Enable labels feature for organizations from the list. Use OnCall organization ID, for this flag FEATURE_LABELS_ENABLED_PER_ORG = getenv_list("FEATURE_LABELS_ENABLED_PER_ORG", default=list()) +FEATURE_ALERT_GROUP_SEARCH_ENABLED = getenv_boolean("FEATURE_ALERT_GROUP_SEARCH_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") diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.ts b/grafana-plugin/src/models/alertgroup/alertgroup.ts index 8241213a..f3c93972 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.ts @@ -65,7 +65,7 @@ export class AlertGroupStore { params: { query: { ...incidentFilters, - search, + search: incidentFilters?.search || search, perpage: this.alertsSearchResult?.page_size, cursor: this.incidentsCursor, is_root: true,