Skip to content

Commit

Permalink
feat(config): add -exact-config command line argument (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchrome authored Feb 6, 2024
1 parent 67d4abb commit 3f4e51e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 2 additions & 1 deletion carbon-clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func main() {
configFile := flag.String("config", "/etc/carbon-clickhouse/carbon-clickhouse.conf", "Filename of config")
printDefaultConfig := flag.Bool("config-print-default", false, "Print default config")
checkConfig := flag.Bool("check-config", false, "Check config and exit")
exactConfig := flag.Bool("exact-config", false, "Ensure that all config params are contained in the target struct.")
printVersion := flag.Bool("version", false, "Print version")
cat := flag.String("cat", "", "Print RowBinary file in TabSeparated format")
bincat := flag.String("recover", "", "Read all good records from corrupted data file. Write binary data to stdout")
Expand Down Expand Up @@ -102,7 +103,7 @@ func main() {

app := carbon.New(*configFile)

if err = app.ParseConfig(); err != nil {
if err = app.ParseConfig(*exactConfig); err != nil {
log.Fatal(err)
}

Expand Down
8 changes: 4 additions & 4 deletions carbon/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func New(configFilename string) *App {
}

// configure loads config from config file, schemas.conf, aggregation.conf
func (app *App) configure() error {
cfg, err := ReadConfig(app.ConfigFilename)
func (app *App) configure(exactConfig bool) error {
cfg, err := ReadConfig(app.ConfigFilename, exactConfig)
if err != nil {
return err
}
Expand Down Expand Up @@ -88,11 +88,11 @@ func (app *App) configure() error {
}

// ParseConfig loads config from config file
func (app *App) ParseConfig() error {
func (app *App) ParseConfig(exactConfig bool) error {
app.Lock()
defer app.Unlock()

return app.configure()
return app.configure(exactConfig)
}

// Stop all socket listeners
Expand Down
13 changes: 11 additions & 2 deletions carbon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func PrintDefaultConfig() error {
}

// ReadConfig ...
func ReadConfig(filename string) (*Config, error) {
func ReadConfig(filename string, exactConfig bool) (*Config, error) {
var err error

cfg := NewConfig()
Expand All @@ -265,9 +265,18 @@ func ReadConfig(filename string) (*Config, error) {
// @TODO: fix for config starts with [logging]
body = strings.Replace(body, "\n[logging]\n", "\n[[logging]]\n", -1)

if _, err := toml.Decode(body, cfg); err != nil {
md, err := toml.Decode(body, cfg)

if err != nil {
return nil, err
}

if exactConfig {
undecoded := md.Undecoded()
if len(undecoded) > 0 {
return nil, fmt.Errorf("Config file (%s) contains unknown keys: %q", filename, undecoded)
}
}
}

if cfg.Logging == nil {
Expand Down

0 comments on commit 3f4e51e

Please sign in to comment.