Skip to content

Commit

Permalink
feat: rest network delay checker
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Nov 27, 2024
1 parent 545fda9 commit e925775
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions node/pkg/checker/dal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ func Start(ctx context.Context) error {
}
defer pool.Close()

networkDelayAlarmCount := 0
alarmCount := map[string]int{}
wsDelayAlarmCount := map[string]int{}

for range ticker.C {
err := checkDal(endpoint, key, alarmCount)
err := checkDal(endpoint, key, alarmCount, networkDelayAlarmCount)
if err != nil {
log.Error().Str("Player", "DalChecker").Err(err).Msg("error in checkDal")
}
Expand All @@ -136,7 +137,7 @@ func buildSubscriptionParams(configs []Config) []string {
return params
}

func checkDal(endpoint string, key string, alarmCount map[string]int) error {
func checkDal(endpoint string, key string, alarmCount map[string]int, networkDelayAlarmCount int) error {
msg := ""

now := time.Now()
Expand All @@ -147,6 +148,16 @@ func checkDal(endpoint string, key string, alarmCount map[string]int) error {
)
networkDelay := time.Since(now)

if networkDelay > NetworkDelayThreshold {
networkDelayAlarmCount++
if networkDelayAlarmCount > AlarmOffsetInTotal {
msg += fmt.Sprintf("(DAL) network delay: %s\n", networkDelay)
networkDelayAlarmCount = 0
}
} else {
networkDelayAlarmCount = 0
}

if err != nil {
return err
}
Expand Down

0 comments on commit e925775

Please sign in to comment.