diff --git a/README.md b/README.md index 4bb62317..95de2f46 100644 --- a/README.md +++ b/README.md @@ -108,11 +108,11 @@ Additionally check out the sparrow [configuration](#configuration) variants. ## Usage -Use `sparrow run` to execute the instance using the binary. A `name` (a valid DNS name) is required to be passed, else +Use `sparrow run` to execute the instance using the binary. A `sparrowName` (a valid DNS name) is required to be passed, else the sparrow will not start: ```sh -sparrow run --name sparrow.telekom.de +sparrow run --sparrowName sparrow.telekom.de ``` ### Container Image diff --git a/cmd/run.go b/cmd/run.go index 365fff27..38f08e13 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -40,7 +40,7 @@ const ( func NewCmdRun() *cobra.Command { flagMapping := config.RunFlagsNameMapping{ ApiAddress: "apiAddress", - Name: "name", + SparrowName: "sparrowName", LoaderType: "loaderType", LoaderInterval: "loaderInterval", LoaderHttpUrl: "loaderHttpUrl", @@ -60,7 +60,7 @@ func NewCmdRun() *cobra.Command { } cmd.PersistentFlags().String(flagMapping.ApiAddress, ":8080", "api: The address the server is listening on") - cmd.PersistentFlags().String(flagMapping.Name, "sparrow", "The DNS name of the sparrow") + cmd.PersistentFlags().String(flagMapping.SparrowName, "sparrow", "The DNS name of the sparrow") cmd.PersistentFlags().StringP(flagMapping.LoaderType, "l", "http", "defines the loader type that will load the checks configuration during the runtime. The fallback is the fileLoader") cmd.PersistentFlags().Int(flagMapping.LoaderInterval, defaultLoaderInterval, "defines the interval the loader reloads the configuration in seconds") @@ -73,7 +73,7 @@ func NewCmdRun() *cobra.Command { cmd.PersistentFlags().String(flagMapping.TargetManagerConfig, "tmconfig.yaml", "target manager: The path to the file to read the target manager config from") _ = viper.BindPFlag(flagMapping.ApiAddress, cmd.PersistentFlags().Lookup(flagMapping.ApiAddress)) - _ = viper.BindPFlag(flagMapping.Name, cmd.PersistentFlags().Lookup(flagMapping.Name)) + _ = viper.BindPFlag(flagMapping.SparrowName, cmd.PersistentFlags().Lookup(flagMapping.SparrowName)) _ = viper.BindPFlag(flagMapping.LoaderType, cmd.PersistentFlags().Lookup(flagMapping.LoaderType)) _ = viper.BindPFlag(flagMapping.LoaderInterval, cmd.PersistentFlags().Lookup(flagMapping.LoaderInterval)) _ = viper.BindPFlag(flagMapping.LoaderHttpUrl, cmd.PersistentFlags().Lookup(flagMapping.LoaderHttpUrl)) @@ -97,7 +97,7 @@ func run(fm *config.RunFlagsNameMapping) func(cmd *cobra.Command, args []string) cfg.SetTargetManagerConfig(config.NewTargetManagerConfig(viper.GetString(fm.TargetManagerConfig))) cfg.SetApiAddress(viper.GetString(fm.ApiAddress)) - cfg.SetName(viper.GetString(fm.Name)) + cfg.SetName(viper.GetString(fm.SparrowName)) cfg.SetLoaderType(viper.GetString(fm.LoaderType)) cfg.SetLoaderInterval(viper.GetInt(fm.LoaderInterval)) @@ -107,7 +107,6 @@ func run(fm *config.RunFlagsNameMapping) func(cmd *cobra.Command, args []string) cfg.SetLoaderHttpRetryCount(viper.GetInt(fm.LoaderHttpRetryCount)) cfg.SetLoaderHttpRetryDelay(viper.GetInt(fm.LoaderHttpRetryDelay)) cfg.SetLoaderFilePath(viper.GetString(fm.LoaderFilePath)) - cfg.SetName(viper.GetString(fm.Name)) if err := cfg.Validate(ctx, fm); err != nil { log.Error("Error while validating the config", "error", err) diff --git a/docs/sparrow_run.md b/docs/sparrow_run.md index a8f61f1d..6fb373fa 100644 --- a/docs/sparrow_run.md +++ b/docs/sparrow_run.md @@ -23,7 +23,7 @@ sparrow run [flags] --loaderHttpUrl string http loader: The url where to get the remote configuration --loaderInterval int defines the interval the loader reloads the configuration in seconds (default 300) -l, --loaderType string defines the loader type that will load the checks configuration during the runtime. The fallback is the fileLoader (default "http") - --name string The DNS name of the sparrow (default "sparrow") + --sparrowName string The DNS name of the sparrow (default "sparrow") --tmconfig string target manager: The path to the file to read the target manager config from (default "tmconfig.yaml") ``` diff --git a/pkg/config/flags.go b/pkg/config/flags.go index 50177a2a..2509c186 100644 --- a/pkg/config/flags.go +++ b/pkg/config/flags.go @@ -19,8 +19,8 @@ package config type RunFlagsNameMapping struct { - ApiAddress string - Name string + ApiAddress string + SparrowName string LoaderType string LoaderInterval string diff --git a/pkg/config/validate.go b/pkg/config/validate.go index 50d0befc..8ffc4a3c 100644 --- a/pkg/config/validate.go +++ b/pkg/config/validate.go @@ -37,7 +37,7 @@ func (c *Config) Validate(ctx context.Context, fm *RunFlagsNameMapping) error { if !isDNSName(c.Name) { ok = false - log.Error("The name of the sparrow must be DNS compliant", fm.Name, c.Name) + log.Error("The name of the sparrow must be DNS compliant", fm.SparrowName, c.Name) } switch c.Loader.Type { //nolint:gocritic diff --git a/pkg/sparrow/run.go b/pkg/sparrow/run.go index 29e74cf9..3d61ec08 100644 --- a/pkg/sparrow/run.go +++ b/pkg/sparrow/run.go @@ -159,10 +159,15 @@ func (s *Sparrow) updateCheckTargets(cfg any) any { return checkCfg } - actual, ok := checkCfg["targets"].([]string) + actuali, ok := checkCfg["targets"].([]any) if !ok { return checkCfg } + + var actual []string + for _, v := range actuali { + actual = append(actual, v.(string)) + } var urls []string gt := s.targets.GetTargets() @@ -177,7 +182,7 @@ func (s *Sparrow) updateCheckTargets(cfg any) any { urls = append(urls, t.Url) } - checkCfg["targets"] = append(checkCfg["targets"].([]string), urls...) + checkCfg["targets"] = append(actual, urls...) return checkCfg } diff --git a/pkg/sparrow/run_test.go b/pkg/sparrow/run_test.go index fdd790f1..4b7896cc 100644 --- a/pkg/sparrow/run_test.go +++ b/pkg/sparrow/run_test.go @@ -269,7 +269,7 @@ func TestSparrow_updateCheckTargets(t *testing.T) { { name: "config with targets", config: map[string]any{ - "targets": []string{"https://gitlab.com"}, + "targets": []any{"https://gitlab.com"}, }, globalTargets: gt, expected: map[string]any{ @@ -279,7 +279,7 @@ func TestSparrow_updateCheckTargets(t *testing.T) { { name: "config has a target already present in global targets - no duplicates", config: map[string]any{ - "targets": []string{"https://localhost.de"}, + "targets": []any{"https://localhost.de"}, }, globalTargets: gt, expected: map[string]any{ @@ -289,7 +289,7 @@ func TestSparrow_updateCheckTargets(t *testing.T) { { name: "global targets contains self - do not add to config", config: map[string]any{ - "targets": []string{"https://localhost.de"}, + "targets": []any{"https://localhost.de"}, }, globalTargets: append(gt, checks.GlobalTarget{ Url: "https://wonderhost.usa",