To validate the configuration options for each check and abort reconcilation if they're invalid.
Closes #97
Changes
Not much, I've added a Validate function to the checks.Runtime interface so every check implements its own validation logic. Then I'm validating the config in the check factory before initializing the checks.
For additional information look at the commits.
Tests done
I've provided some unit tests for each config validation.
Manual e2e test
With valid config:
$ go run main.go run --config .tmp/config/start-config.yaml
Using config file: .tmp/config/start-config.yaml
{"time":"2024-02-12T11:20:49.471564989+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/cmd.NewCmdRun.run.func1","file":"/home/installadm/dev/github/sparrow/cmd/run.go","line":81},"msg":"Running sparrow"}
{"time":"2024-02-12T11:20:49.471685957+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/api.(*api).Run.func1","file":"/home/installadm/dev/github/sparrow/pkg/api/api.go","line":78},"msg":"Serving Api","addr":":8080"}
{"time":"2024-02-12T11:20:49.47170494+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).Reconcile","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":81},"msg":"Starting global gitlabTargetManager reconciler"}
{"time":"2024-02-12T11:21:19.497599176+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/config.(*FileLoader).Run","file":"/home/installadm/dev/github/sparrow/pkg/config/file.go","line":79},"msg":"Successfully got local runtime configuration"}
{"time":"2024-02-12T11:21:19.497736345+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/checks/dns.(*DNS).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/dns/dns.go","line":87},"msg":"Starting dns check","interval":"20s"}
{"time":"2024-02-12T11:21:19.497789328+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":81},"msg":"Starting healthcheck","interval":"10s"}
{"time":"2024-02-12T11:21:19.497812373+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/checks/latency.(*Latency).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/latency/latency.go","line":85},"msg":"Starting latency check","interval":"20s"}
With invalid configs for all checks:
$ go run main.go run --config .tmp/config/start-config.yaml
Using config file: .tmp/config/start-config.yaml
{"time":"2024-02-12T11:18:47.836790767+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/cmd.NewCmdRun.run.func1","file":"/home/installadm/dev/github/sparrow/cmd/run.go","line":81},"msg":"Running sparrow"}
{"time":"2024-02-12T11:18:47.836938644+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).Reconcile","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":81},"msg":"Starting global gitlabTargetManager reconciler"}
{"time":"2024-02-12T11:18:47.836998613+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/api.(*api).Run.func1","file":"/home/installadm/dev/github/sparrow/pkg/api/api.go","line":78},"msg":"Serving Api","addr":":8080"}
{"time":"2024-02-12T11:19:17.863099724+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/config.(*FileLoader).Run","file":"/home/installadm/dev/github/sparrow/pkg/config/file.go","line":79},"msg":"Successfully got local runtime configuration"}
{"time":"2024-02-12T11:19:17.863263753+01:00","level":"ERROR","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow.(*Sparrow).ReconcileChecks","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/run.go","line":145},"msg":"Failed to create checks from config","error":"invalid configuration field 'timeout' in check 'health': timeout must be at least 1s\ninvalid configuration field 'interval' in check 'latency': interval must be at least 100ms\ninvalid configuration field 'targets' in check 'dns': target URLs must not start with 'https://' or 'http://'"}
Motivation
To validate the configuration options for each check and abort reconcilation if they're invalid.
Closes #97
Changes
Not much, I've added a
Validate
function to thechecks.Runtime
interface so every check implements its own validation logic. Then I'm validating the config in the check factory before initializing the checks.For additional information look at the commits.
Tests done
I've provided some unit tests for each config validation.
Manual e2e test
With valid config:
With invalid configs for all checks:
TODO