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

adds config validation, similar to cortex #1939

Merged
merged 1 commit into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions cmd/loki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ func main() {
}
util.InitLogger(&config.Server)

// Validate the config once both the config file has been loaded
// and CLI flags parsed.
err := config.Validate(util.Logger)
if err != nil {
level.Error(util.Logger).Log("msg", "validating config", "err", err.Error())
os.Exit(1)
}

// Setting the environment variable JAEGER_AGENT_HOST enables tracing
trace, err := tracing.NewFromEnv(fmt.Sprintf("loki-%s", config.Target))
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions pkg/loki/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/runtimeconfig"

"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/pkg/errors"
"github.com/weaveworks/common/middleware"
Expand Down Expand Up @@ -73,6 +74,24 @@ func (c *Config) RegisterFlags(f *flag.FlagSet) {
c.RuntimeConfig.RegisterFlags(f)
}

// Validate the config and returns an error if the validation
// doesn't pass
func (c *Config) Validate(log log.Logger) error {
if err := c.SchemaConfig.Validate(); err != nil {
return errors.Wrap(err, "invalid schema config")
}
if err := c.StorageConfig.Validate(); err != nil {
return errors.Wrap(err, "invalid storage config")
}
if err := c.QueryRange.Validate(log); err != nil {
return errors.Wrap(err, "invalid queryrange config")
}
if err := c.TableManager.Validate(); err != nil {
return errors.Wrap(err, "invalid tablemanager config")
}
return nil
}

// Loki is the root datastructure for Loki.
type Loki struct {
cfg Config
Expand Down