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

feat(config): add -exact-config command line argument #139

Merged
merged 1 commit into from
Feb 6, 2024
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
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
Loading