From 065cc9343aba5c0568c581419ffc4dfde68c15ec Mon Sep 17 00:00:00 2001 From: Ildar Iskhakov Date: Tue, 27 Jun 2023 10:58:16 +0800 Subject: [PATCH] Show 100000+ in stats when there are more than 100000 alert groups in the result (#1901) # What this PR does ## Which issue(s) this PR fixes ## Checklist - [ ] Unit, integration, and e2e (if applicable) tests updated - [ ] Documentation added (or `pr:no public docs` PR label added if not required) - [ ] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required) --- CHANGELOG.md | 1 + engine/apps/api/views/alert_group.py | 17 +++++------------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e254d25a62..88143ff960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Change permissions used during setup to better represent actions being taken by @mderynck ([#2242](https://github.com/grafana/oncall/pull/2242)) +- Display 100000+ in stats when there are more than 100000 alert groups in the result ([#1901](https://github.com/grafana/oncall/pull/1901)) ## v1.3.1 (2023-06-26) diff --git a/engine/apps/api/views/alert_group.py b/engine/apps/api/views/alert_group.py index 1e9f4bef85..164c591928 100644 --- a/engine/apps/api/views/alert_group.py +++ b/engine/apps/api/views/alert_group.py @@ -400,20 +400,13 @@ def enrich(self, alert_groups): @action(detail=False) def stats(self, *args, **kwargs): - alert_groups = self.filter_queryset(self.get_queryset()) - # Only count field is used, other fields left just in case for the backward compatibility + MAX_COUNT = 100001 + alert_groups = self.filter_queryset(self.get_queryset())[:MAX_COUNT] + count = alert_groups.count() + count = f"{MAX_COUNT-1}+" if count == MAX_COUNT else str(count) return Response( { - "count": alert_groups.filter().count(), - "count_previous_same_period": 0, - "alert_group_rate_to_previous_same_period": 1, - "count_escalations": 0, - "count_escalations_previous_same_period": 0, - "escalation_rate_to_previous_same_period": 1, - "average_response_time": None, - "average_response_time_to_previous_same_period": None, - "average_response_time_rate_to_previous_same_period": 0, - "prev_period_in_days": 1, + "count": count, } )