From 2d97df87df03c2d2c0043acd6e29ccb11c942993 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 2 Oct 2024 11:56:49 +0300 Subject: [PATCH 1/2] Avoid too big alert logs --- lib/sanbase/alerts/alert.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sanbase/alerts/alert.ex b/lib/sanbase/alerts/alert.ex index 1138eb3b96..6a0075d2af 100644 --- a/lib/sanbase/alerts/alert.ex +++ b/lib/sanbase/alerts/alert.ex @@ -333,7 +333,7 @@ defimpl Sanbase.Alert, for: Any do slugs = Map.keys(template_kv) Logger.info( - "[maybe_extend_payload_telegram_channel_#{user_trigger.id}] [user_trigger: #{inspect(user_trigger)}] [payload: #{inspect(payload)}] [slugs: #{inspect(slugs)}]]" + "[maybe_extend_payload_telegram_channel_#{user_trigger.id}] [user_trigger: #{inspect(user_trigger.id)}]]" ) if length(slugs) > 0 do From 8de562d4b235479de7978b44702afc2d815d301a Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Wed, 2 Oct 2024 12:01:31 +0300 Subject: [PATCH 2/2] Fix alert evaluation match error in case of timeout --- lib/sanbase/alerts/evaluator/scheduler.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/sanbase/alerts/evaluator/scheduler.ex b/lib/sanbase/alerts/evaluator/scheduler.ex index f0d7a07f53..1c94cd769c 100644 --- a/lib/sanbase/alerts/evaluator/scheduler.ex +++ b/lib/sanbase/alerts/evaluator/scheduler.ex @@ -288,15 +288,18 @@ defmodule Sanbase.Alert.Scheduler do # without using any synchronization technique. grouped_by_user = Enum.group_by(triggers, fn %{user: user} -> user.id end) + # On timeout, the map returns {:error, :timeout} tuple, so instead of using map_type: :flat_map, + # we need to use map_type: :map and flatten the result with List.flatten/1, otherwise + # a matching error is raised grouped_by_user |> Sanbase.Parallel.map( fn {_user_id, triggers} -> send_triggers_sequentially(triggers) end, max_concurrency: 15, ordered: false, - map_type: :flat_map, - timeout: 60_000, + map_type: :map, on_timeout: :kill_task ) + |> List.flatten() |> Enum.reject(&match?({:exit, :timeout}, &1)) |> report_sending_alert_timeout(triggers, info_map) |> Enum.unzip()