From 1cdccef80448270d154df432babf63f4f38793cb Mon Sep 17 00:00:00 2001 From: Michaela Wheeler Date: Thu, 19 Dec 2024 10:17:29 +1100 Subject: [PATCH] WIP --- .../alerts/models/alert_receive_channel.py | 2 +- engine/apps/api/tests/test_alert_group.py | 1 - engine/apps/metrics_exporter/helpers.py | 20 ++++++------------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/engine/apps/alerts/models/alert_receive_channel.py b/engine/apps/alerts/models/alert_receive_channel.py index 02b3f025b..4fd926ac4 100644 --- a/engine/apps/alerts/models/alert_receive_channel.py +++ b/engine/apps/alerts/models/alert_receive_channel.py @@ -790,6 +790,6 @@ def listen_for_alertreceivechannel_model_save( # delete connected auth tokens instance.auth_tokens.all().delete() - metrics_remove_deleted_integration_from_cache(instance, instance.organization) + metrics_remove_deleted_integration_from_cache(instance) else: metrics_update_integration_cache(instance) diff --git a/engine/apps/api/tests/test_alert_group.py b/engine/apps/api/tests/test_alert_group.py index 1994860df..61a72e933 100644 --- a/engine/apps/api/tests/test_alert_group.py +++ b/engine/apps/api/tests/test_alert_group.py @@ -933,7 +933,6 @@ def test_get_filter_by_teams( # check the "No team" case response = client.get(url + "?team=null", **make_user_auth_headers(user, token)) assert response.status_code == status.HTTP_200_OK - print() assert len(response.data["results"]) == 1 assert {ag["pk"] for ag in response.data["results"]} == {alert_group_0.public_primary_key} diff --git a/engine/apps/metrics_exporter/helpers.py b/engine/apps/metrics_exporter/helpers.py index e0b22338a..50e0dc413 100644 --- a/engine/apps/metrics_exporter/helpers.py +++ b/engine/apps/metrics_exporter/helpers.py @@ -150,37 +150,29 @@ def get_default_states_dict() -> AlertGroupStateDict: def metrics_update_integration_cache(integration: "AlertReceiveChannel") -> None: """Update integration data in metrics cache""" - metrics_cache_timeout = get_metrics_cache_timeout(integration.organization.id) - metric_alert_groups_total_key = get_metric_alert_groups_total_key(integration.organization.id) - metric_alert_groups_response_time_key = get_metric_alert_groups_response_time_key(integration.organization.id) - print(integration.organization.id) - print("cccc") + metrics_cache_timeout = get_metrics_cache_timeout(integration.organization_id) + metric_alert_groups_total_key = get_metric_alert_groups_total_key(integration.organization_id) + metric_alert_groups_response_time_key = get_metric_alert_groups_response_time_key(integration.organization_id) for team in _get_teams_for_cache(integration.organization): - print(team) for metric_key in [metric_alert_groups_total_key, metric_alert_groups_response_time_key]: - print(metric_key) metric_cache = cache.get(metric_key, {}) - print(metric_cache) integration_metric_cache = metric_cache.get((integration.id,team.team_id)) - print(integration_metric_cache) if integration_metric_cache: cache_updated = False - print("eeee") if integration_metric_cache["integration_name"] != integration.emojized_verbal_name: - print("dddd") integration_metric_cache["integration_name"] = integration.emojized_verbal_name cache_updated = True if cache_updated: cache.set(metric_key, metric_cache, timeout=metrics_cache_timeout) -def metrics_remove_deleted_integration_from_cache(integration: "AlertReceiveChannel", organization: "Organization"): +def metrics_remove_deleted_integration_from_cache(integration: "AlertReceiveChannel"): """Remove data related to deleted integration from metrics cache""" metrics_cache_timeout = get_metrics_cache_timeout(integration.organization_id) - metric_alert_groups_total_key = get_metric_alert_groups_total_key(integration.organization.id) + metric_alert_groups_total_key = get_metric_alert_groups_total_key(integration.organization_id) metric_alert_groups_response_time_key = get_metric_alert_groups_response_time_key(integration.organization_id) - for team in _get_teams_for_cache(organization): + for team in _get_teams_for_cache(integration.organization): for metric_key in [metric_alert_groups_total_key, metric_alert_groups_response_time_key]: metric_cache = cache.get(metric_key) if metric_cache: