Optimize getting response time for alert groups (#2296)

Optimize getting response time for alert groups in calculation metrics
task

## 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)
This commit is contained in:
Yulya Artyukhina 2023-06-21 10:16:35 +02:00 committed by GitHub
parent 861a419b92
commit af939dc83a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -113,17 +113,13 @@ def calculate_and_cache_metrics(organization_id, force=False):
},
)[state] = integration.alert_groups.filter(alert_group_filter).count()
# calculate response time
all_response_time = []
alert_groups = integration.alert_groups.filter(started_at__gte=response_time_period)
for alert_group in alert_groups:
if alert_group.response_time:
all_response_time.append(int(alert_group.response_time.total_seconds()))
elif alert_group.state != AlertGroupState.FIRING:
# get calculated value from current alert group information
response_time = alert_group._get_response_time()
if response_time:
all_response_time.append(int(response_time.total_seconds()))
# get response time
all_response_time = integration.alert_groups.filter(
started_at__gte=response_time_period,
response_time__isnull=False,
).values_list("response_time", flat=True)
all_response_time_seconds = [int(response_time.total_seconds()) for response_time in all_response_time]
metric_alert_group_response_time[integration.id] = {
"integration_name": integration.emojized_verbal_name,
@ -132,7 +128,7 @@ def calculate_and_cache_metrics(organization_id, force=False):
"org_id": integration.organization.org_id,
"slug": instance_slug,
"id": instance_id,
"response_time": all_response_time,
"response_time": all_response_time_seconds,
}
metric_alert_groups_total_key = get_metric_alert_groups_total_key(organization_id)