From b26239ba065d15228a8adb552c9f778799e07248 Mon Sep 17 00:00:00 2001 From: Sohom Bhattacharjee Date: Tue, 2 Jul 2024 04:29:05 +0530 Subject: [PATCH] minor fixes and typo --- alert/processAlert.go | 8 ++++---- docker-compose.yml | 6 +++--- enrichment/getPromQlEnrichment.go | 5 ++++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/alert/processAlert.go b/alert/processAlert.go index 552a557..a45dde4 100644 --- a/alert/processAlert.go +++ b/alert/processAlert.go @@ -51,7 +51,6 @@ func ProcessAlert(a types.Alert) { actionMap := action.GetActionMap() // these are used to capture the result of the enrichments - var err error resMap := make(map[string]interface{}, len(p.Enrichments)) // process enrichments @@ -59,10 +58,11 @@ func ProcessAlert(a types.Alert) { logr.Info("processing enrichment : ", v.EnrichmentName) if f, ok := (*enrichmentMap)[v.EnrichmentName]; ok { - resMap[v.StepName], err = f(a, v) + tt, err := f(a, v) if err != nil { - fmt.Println(err) + logr.Error("error from processing function") } + resMap[v.StepName] = tt } else { logr.Info("no enrichment found with name: ", v.EnrichmentName) } @@ -75,7 +75,7 @@ func ProcessAlert(a types.Alert) { if f, ok := (*actionMap)[v.ActionName]; ok { err := f(a, v, resMap) if err != nil { - fmt.Println(err) + logr.Error("error processing action:", err) } } else { logr.Info("no action found with name: ", v.ActionName) diff --git a/docker-compose.yml b/docker-compose.yml index 3b0e816..8418d96 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "3.5" services: toy_alert_manager: container_name: toy_alert_manager - image: tam:0.0.1 + image: alertmanager:0.0.1 restart: always network_mode: host ulimits: @@ -11,10 +11,10 @@ services: soft: 1000000 hard: 1000000 volumes: - - ./alert-manager-config-2.yml:/alert-manager-config-2.yml + - ./alert-manager-config.yml:/alert-manager-config.yml command: - server - --config-file - - "./alert-manager-config-2.yml" + - "./alert-manager-config.yml" - --log-level - DEBUG diff --git a/enrichment/getPromQlEnrichment.go b/enrichment/getPromQlEnrichment.go index e029b4f..dcb73c6 100644 --- a/enrichment/getPromQlEnrichment.go +++ b/enrichment/getPromQlEnrichment.go @@ -51,6 +51,9 @@ func GetPromQLEnrichment(alert types.Alert, e types.Enrichment) (interface{}, er if err != nil { return nil, fmt.Errorf("error unmarshaling JSON: %v", err) } - + // check if result is empty + if len(pres.Data.Result) <= 0 { + return "", nil + } return fmt.Sprint(pres.Data.Result[0].Value[1]), nil }