Skip to content

Commit

Permalink
Move check validation back to top level command to make it reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
rugwirobaker committed Apr 21, 2023
1 parent b27028a commit d551c6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 0 additions & 8 deletions internal/appconfig/toplevelcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ func (chk *ToplevelCheck) toMachineCheck() (*api.MachineCheck, error) {
return api.MachineHTTPHeader{Name: k, Values: []string{v}}
})
}
// minimum interval in flaps is set to 2 seconds.
if res.Interval != nil && res.Interval.Duration.Seconds() < 2 {
return nil, fmt.Errorf("Interval is too short, minimum interval is 2 seconds")
}
// max timeout in flaps in set to 60s
if res.Timeout != nil && res.Timeout.Duration.Seconds() > 60 {
return nil, fmt.Errorf("Timeout is too long, maximum timeout is 60 seconds")
}
return res, nil
}

Expand Down
12 changes: 12 additions & 0 deletions internal/appconfig/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,19 @@ func (cfg *Config) validateChecksSection() (extraInfo string, err error) {
extraInfo += fmt.Sprintf("Can't process top level check '%s': %s\n", name, vErr)
err = ValidationError
}
// minimum interval in flaps is set to 2 seconds.
if check.Interval != nil && check.Interval.Duration.Seconds() < 2 {
extraInfo += fmt.Sprintf("Check '%s' interval is too short: %s, minimum is 2 seconds\n", name, check.Interval.Duration)
err = ValidationError
}

// max timeout in flaps in set to 60s
if check.Timeout != nil && check.Timeout.Duration.Seconds() > 60 {
extraInfo += fmt.Sprintf("Check '%s' timeout is too long: %s, maximum is 60 seconds\n", name, check.Timeout.Duration)
err = ValidationError
}
}

return
}

Expand Down

0 comments on commit d551c6f

Please sign in to comment.