Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log sampler config and validation errors #228

Merged
merged 3 commits into from
Mar 24, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions config/file_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/fsnotify/fsnotify"
"github.com/go-playground/validator"
libhoney "github.com/honeycombio/libhoney-go"
"github.com/sirupsen/logrus"
viper "github.com/spf13/viper"
)

Expand Down Expand Up @@ -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, ".")
Expand All @@ -307,16 +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 {
return err
return fmt.Errorf("Failed to unmarshal sampler rule: %w", err)
}
v := validator.New()
err = v.Struct(i)
if err != nil {
return err
return fmt.Errorf("Failed to validate sampler rule: %w", err)
}
}

Expand All @@ -336,18 +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 {
return err
return fmt.Errorf("Failed to unmarshal dataset sampler rule: %w", err)
}
v := validator.New()
err = v.Struct(i)
if err != nil {
return err
return fmt.Errorf("Failed to validate dataset sampler rule: %w", err)
}
}
}
Expand Down