From a290cd0d02d4ba0181bbaee9862681c0fa2c65f3 Mon Sep 17 00:00:00 2001 From: Agustin Pazos Date: Thu, 29 Jun 2023 11:13:30 -0300 Subject: [PATCH] Add alert client to pipeline --- pipeline/cmd/main.go | 16 ++++++++++++++++ pipeline/config/config.go | 2 +- pipeline/internal/alert/alert.go | 30 ++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 pipeline/internal/alert/alert.go diff --git a/pipeline/cmd/main.go b/pipeline/cmd/main.go index d8051c6eb..4b6795e9b 100644 --- a/pipeline/cmd/main.go +++ b/pipeline/cmd/main.go @@ -10,10 +10,12 @@ import ( "github.com/aws/aws-sdk-go-v2/aws" awsconfig "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/credentials" + "github.com/wormhole-foundation/wormhole-explorer/common/client/alert" "github.com/wormhole-foundation/wormhole-explorer/common/logger" "github.com/wormhole-foundation/wormhole-explorer/pipeline/config" "github.com/wormhole-foundation/wormhole-explorer/pipeline/healthcheck" "github.com/wormhole-foundation/wormhole-explorer/pipeline/http/infrastructure" + pipelineAlert "github.com/wormhole-foundation/wormhole-explorer/pipeline/internal/alert" "github.com/wormhole-foundation/wormhole-explorer/pipeline/internal/db" "github.com/wormhole-foundation/wormhole-explorer/pipeline/internal/metrics" "github.com/wormhole-foundation/wormhole-explorer/pipeline/internal/sns" @@ -172,3 +174,17 @@ func newMetrics(cfg *config.Configuration) metrics.Metrics { } return metrics.NewPrometheusMetrics(cfg.Enviroment, cfg.P2pNetwork) } + +func newAlertClient(cfg *config.Configuration) (alert.AlertClient, error) { + if !cfg.AlertEnabled { + return alert.NewDummyClient(), nil + } + + alertConfig := alert.AlertConfig{ + Enviroment: cfg.Enviroment, + P2PNetwork: cfg.P2pNetwork, + ApiKey: cfg.AlertApiKey, + Enabled: cfg.AlertEnabled, + } + return alert.NewAlertService(alertConfig, pipelineAlert.LoadAlerts) +} diff --git a/pipeline/config/config.go b/pipeline/config/config.go index e0f219072..c0740719f 100644 --- a/pipeline/config/config.go +++ b/pipeline/config/config.go @@ -22,7 +22,7 @@ type Configuration struct { SNSUrl string `env:"SNS_URL"` PprofEnabled bool `env:"PPROF_ENABLED,default=false"` AlertEnabled bool `env:"ALERTS_ENABLED,default=false"` - AlertApiKeys string `env:"ALERT_API_KEY"` + AlertApiKey string `env:"ALERT_API_KEY"` MetricsEnabled bool `env:"METRICS_ENABLED,default=false"` } diff --git a/pipeline/internal/alert/alert.go b/pipeline/internal/alert/alert.go new file mode 100644 index 000000000..187ef1410 --- /dev/null +++ b/pipeline/internal/alert/alert.go @@ -0,0 +1,30 @@ +package alert + +import ( + "fmt" + + "github.com/wormhole-foundation/wormhole-explorer/common/client/alert" +) + +// alert key constants definition. +const ( + ErrorDecodeWatcherEvent = "ERROR_DECODE_WATCHER_EVENT" +) + +func LoadAlerts(cfg alert.AlertConfig) map[string]alert.Alert { + alerts := make(map[string]alert.Alert) + messagePrefix := alert.GetMessagePrefix(cfg.Enviroment, cfg.P2PNetwork) + + // Alert error devoding watcher event. + alerts[ErrorDecodeWatcherEvent] = alert.Alert{ + Alias: "Error decoding watcher event", + Message: fmt.Sprintf("%s %s", messagePrefix, "Error decoding watcher event"), + Description: "An error was found decoding the watcher event.", + Actions: []string{""}, + Tags: []string{cfg.Enviroment, cfg.P2PNetwork, "pipeline", "watcher", "mongo"}, + Entity: "pipeline", + Priority: alert.CRITICAL, + } + + return alerts +}