From 0b47a8fb6351e846d10b95ce794c9b8d1f299d3d Mon Sep 17 00:00:00 2001 From: Andrey Oleynik Date: Fri, 26 Apr 2024 14:37:49 +0300 Subject: [PATCH 1/5] enable searching for alert groups --- engine/apps/api/views/alert_group.py | 6 ++++++ engine/settings/base.py | 1 + 2 files changed, 7 insertions(+) diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index cfcc8f6133..1abe73c788 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -37,6 +37,7 @@ ) from common.api_helpers.mixins import PreviewTemplateMixin, PublicPrimaryKeyMixin, TeamFilteringMixin from common.api_helpers.paginators import AlertGroupCursorPaginator +from django.conf import settings def get_integration_queryset(request): @@ -277,6 +278,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 36de8578aa..4d6ee669b1 100644 --- a/engine/settings/base.py +++ b/engine/settings/base.py @@ -71,6 +71,7 @@ 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") From 977c3f43405debcbdffb1a43e272be5a8ba9b4d1 Mon Sep 17 00:00:00 2001 From: Andrey Oleynik Date: Fri, 26 Apr 2024 14:38:08 +0300 Subject: [PATCH 2/5] fix search param --- .../src/models/alertgroup/alertgroup.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.ts b/grafana-plugin/src/models/alertgroup/alertgroup.ts index 7a73a4df4b..8dde9f5688 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.ts @@ -53,17 +53,20 @@ export class AlertGroupStore { ); const timestamp = new Date().getTime(); this.latestFetchAlertGroupsTimestamp = timestamp; + const query = { + ...this.incidentFilters, + perpage: this.alertsSearchResult?.page_size, + cursor: this.incidentsCursor, + is_root: true + }; + if (this.incidentFilters && !this.incidentFilters.search) { + query.search = search; + } const { data: { results, next: nextRaw, previous: previousRaw, page_size }, } = await onCallApi().GET('/alertgroups/', { params: { - query: { - ...this.incidentFilters, - search, - perpage: this.alertsSearchResult?.page_size, - cursor: this.incidentsCursor, - is_root: true, - }, + query: query, }, }); From dc2341185ef8fad24d67198a998f6a2331880eec Mon Sep 17 00:00:00 2001 From: Andrey Oleynik Date: Sat, 27 Apr 2024 13:02:56 +0300 Subject: [PATCH 3/5] update alertgroup query Co-authored-by: Joey Orlando --- grafana-plugin/src/models/alertgroup/alertgroup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.ts b/grafana-plugin/src/models/alertgroup/alertgroup.ts index 8dde9f5688..ce9ac17ef2 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.ts @@ -66,7 +66,7 @@ export class AlertGroupStore { data: { results, next: nextRaw, previous: previousRaw, page_size }, } = await onCallApi().GET('/alertgroups/', { params: { - query: query, + query, }, }); From 78dbb8279292c1c64788ea665a94c0be72b9130b Mon Sep 17 00:00:00 2001 From: Andrey Oleynik Date: Sat, 27 Apr 2024 14:25:44 +0300 Subject: [PATCH 4/5] lint --- engine/apps/api/views/alert_group.py | 2 +- grafana-plugin/src/models/alertgroup/alertgroup.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index 1abe73c788..da337b2624 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -1,6 +1,7 @@ import typing from datetime import timedelta +from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.db.models import Count, Max, Q from django.utils import timezone @@ -37,7 +38,6 @@ ) from common.api_helpers.mixins import PreviewTemplateMixin, PublicPrimaryKeyMixin, TeamFilteringMixin from common.api_helpers.paginators import AlertGroupCursorPaginator -from django.conf import settings def get_integration_queryset(request): diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.ts b/grafana-plugin/src/models/alertgroup/alertgroup.ts index ce9ac17ef2..17856722d8 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.ts @@ -57,10 +57,10 @@ export class AlertGroupStore { ...this.incidentFilters, perpage: this.alertsSearchResult?.page_size, cursor: this.incidentsCursor, - is_root: true + is_root: true, }; if (this.incidentFilters && !this.incidentFilters.search) { - query.search = search; + query.search = search; } const { data: { results, next: nextRaw, previous: previousRaw, page_size }, From 94f4edec0c7a19fce2d478b9d90ce841ca43989f Mon Sep 17 00:00:00 2001 From: Andrey Oleynik Date: Wed, 1 May 2024 14:11:01 +0300 Subject: [PATCH 5/5] add search query param condition --- .../src/models/alertgroup/alertgroup.ts | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/grafana-plugin/src/models/alertgroup/alertgroup.ts b/grafana-plugin/src/models/alertgroup/alertgroup.ts index 17856722d8..8b07e9f422 100644 --- a/grafana-plugin/src/models/alertgroup/alertgroup.ts +++ b/grafana-plugin/src/models/alertgroup/alertgroup.ts @@ -53,20 +53,17 @@ export class AlertGroupStore { ); const timestamp = new Date().getTime(); this.latestFetchAlertGroupsTimestamp = timestamp; - const query = { - ...this.incidentFilters, - perpage: this.alertsSearchResult?.page_size, - cursor: this.incidentsCursor, - is_root: true, - }; - if (this.incidentFilters && !this.incidentFilters.search) { - query.search = search; - } const { data: { results, next: nextRaw, previous: previousRaw, page_size }, } = await onCallApi().GET('/alertgroups/', { params: { - query, + query: { + ...this.incidentFilters, + search: this.incidentFilters?.search || search, + perpage: this.alertsSearchResult?.page_size, + cursor: this.incidentsCursor, + is_root: true, + }, }, });