Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
mwheeler-ep committed Dec 18, 2024
1 parent cea470f commit 1cdccef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion engine/apps/alerts/models/alert_receive_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion engine/apps/api/tests/test_alert_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down
20 changes: 6 additions & 14 deletions engine/apps/metrics_exporter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1cdccef

Please sign in to comment.