Skip to content

Commit

Permalink
Add alert client to pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
walker-16 committed Jun 29, 2023
1 parent cd3e633 commit a290cd0
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
16 changes: 16 additions & 0 deletions pipeline/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion pipeline/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
30 changes: 30 additions & 0 deletions pipeline/internal/alert/alert.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit a290cd0

Please sign in to comment.