From 7b9f8d8bab939e4af21beb03e2b602058dfc87c9 Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Tue, 16 Mar 2021 16:47:18 +0000 Subject: [PATCH 1/3] log sampler config and validation errors --- config/file_config.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/file_config.go b/config/file_config.go index af9d1054a5..4e43fd2983 100644 --- a/config/file_config.go +++ b/config/file_config.go @@ -12,6 +12,7 @@ import ( "github.com/go-playground/validator" libhoney "github.com/honeycombio/libhoney-go" viper "github.com/spf13/viper" + "github.com/sirupsen/logrus" ) type fileConfig struct { @@ -287,6 +288,8 @@ func (f *fileConfig) validateConditionalConfigs() error { } func (f *fileConfig) validateSamplerConfigs() error { + logrus.Debugf("Sampler rules config - %v+", f.rules) + keys := f.rules.AllKeys() for _, key := range keys { parts := strings.Split(key, ".") @@ -311,11 +314,13 @@ func (f *fileConfig) validateSamplerConfigs() error { } err := f.rules.Unmarshal(i) if err != nil { + logrus.WithError(err).Warn("Failed to unmarshal sampler rule") return err } v := validator.New() err = v.Struct(i) if err != nil { + logrus.WithError(err).Warn("Failed to validate sampler rule") return err } } @@ -342,11 +347,13 @@ func (f *fileConfig) validateSamplerConfigs() error { if sub := f.rules.Sub(datasetName); sub != nil { err := sub.Unmarshal(i) if err != nil { + logrus.WithError(err).Warn("Failed to unmarshal dataset sampler rule") return err } v := validator.New() err = v.Struct(i) if err != nil { + logrus.WithError(err).Warn("Failed to validate dataset sampler rule") return err } } From 39885fc539d7c4f6f2b1f5a921fe84c59636cf9b Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Wed, 24 Mar 2021 10:57:36 +0000 Subject: [PATCH 2/3] fix struct expansion verb --- config/file_config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/file_config.go b/config/file_config.go index 4e43fd2983..521f00b898 100644 --- a/config/file_config.go +++ b/config/file_config.go @@ -288,7 +288,7 @@ func (f *fileConfig) validateConditionalConfigs() error { } func (f *fileConfig) validateSamplerConfigs() error { - logrus.Debugf("Sampler rules config - %v+", f.rules) + logrus.Debugf("Sampler rules config: %+v", f.rules) keys := f.rules.AllKeys() for _, key := range keys { From a7f48509ec4296aa2d76c816a1d869cdbdcd1364 Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Wed, 24 Mar 2021 11:01:47 +0000 Subject: [PATCH 3/3] wrap caught errors to add extra context --- config/file_config.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/config/file_config.go b/config/file_config.go index 521f00b898..1bffdebbb4 100644 --- a/config/file_config.go +++ b/config/file_config.go @@ -11,8 +11,8 @@ import ( "github.com/fsnotify/fsnotify" "github.com/go-playground/validator" libhoney "github.com/honeycombio/libhoney-go" - viper "github.com/spf13/viper" "github.com/sirupsen/logrus" + viper "github.com/spf13/viper" ) type fileConfig struct { @@ -310,18 +310,16 @@ func (f *fileConfig) validateSamplerConfigs() error { case "TotalThroughputSampler": i = &TotalThroughputSamplerConfig{} default: - return errors.New("Invalid or missing default sampler type") + return fmt.Errorf("Invalid or missing default sampler type: %s", t) } err := f.rules.Unmarshal(i) if err != nil { - logrus.WithError(err).Warn("Failed to unmarshal sampler rule") - return err + return fmt.Errorf("Failed to unmarshal sampler rule: %w", err) } v := validator.New() err = v.Struct(i) if err != nil { - logrus.WithError(err).Warn("Failed to validate sampler rule") - return err + return fmt.Errorf("Failed to validate sampler rule: %w", err) } } @@ -341,20 +339,18 @@ func (f *fileConfig) validateSamplerConfigs() error { case "TotalThroughputSampler": i = &TotalThroughputSamplerConfig{} default: - return errors.New("Invalid or missing dataset sampler type") + return fmt.Errorf("Invalid or missing dataset sampler type: %s", t) } datasetName := parts[0] if sub := f.rules.Sub(datasetName); sub != nil { err := sub.Unmarshal(i) if err != nil { - logrus.WithError(err).Warn("Failed to unmarshal dataset sampler rule") - return err + return fmt.Errorf("Failed to unmarshal dataset sampler rule: %w", err) } v := validator.New() err = v.Struct(i) if err != nil { - logrus.WithError(err).Warn("Failed to validate dataset sampler rule") - return err + return fmt.Errorf("Failed to validate dataset sampler rule: %w", err) } } }