Skip to content

Commit

Permalink
adds config validation, similar to cortex (#1939)
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-d authored Apr 15, 2020
1 parent f86785b commit e9789f7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
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

0 comments on commit e9789f7

Please sign in to comment.