From a2859553ce13ea3cfd351905adaf2b73e14e784f Mon Sep 17 00:00:00 2001 From: Maxim Mordasov Date: Wed, 22 May 2024 13:02:56 +0100 Subject: [PATCH] Fix AG date range based filters default values (#4354) # What this PR does Fix AG date range based filters default values ## Which issue(s) this PR closes ## Checklist - [ ] 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: Michael Derynck --- engine/apps/api/views/alert_group.py | 11 ++--------- grafana-plugin/src/pages/incidents/Incidents.tsx | 4 +--- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index f7590152..1c6ce144 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -1,9 +1,7 @@ import typing -from datetime import timedelta from django.core.exceptions import ObjectDoesNotExist from django.db.models import Count, Max, Q -from django.utils import timezone from django_filters import rest_framework as filters from drf_spectacular.utils import extend_schema, inline_serializer from rest_framework import mixins, serializers, status, viewsets @@ -729,14 +727,9 @@ class AlertGroupView( Retrieve a list of valid filter options that can be used to filter alert groups """ api_root = "/api/internal/v1/" + default_day_range = 30 - now = timezone.now() - week_ago = now - timedelta(days=7) - - default_datetime_range = "{}_{}".format( - week_ago.strftime(DateRangeFilterMixin.DATE_FORMAT), - now.strftime(DateRangeFilterMixin.DATE_FORMAT), - ) + default_datetime_range = f"now-{default_day_range}d_now" filter_options = [ { diff --git a/grafana-plugin/src/pages/incidents/Incidents.tsx b/grafana-plugin/src/pages/incidents/Incidents.tsx index 605499f3..cee71fa2 100644 --- a/grafana-plugin/src/pages/incidents/Incidents.tsx +++ b/grafana-plugin/src/pages/incidents/Incidents.tsx @@ -307,8 +307,6 @@ class _IncidentsPage extends React.Component