Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
Add validation for duplicated database entries
Browse files Browse the repository at this point in the history
  • Loading branch information
Diogo Nicoleti authored and diogonicoleti committed Nov 23, 2019
1 parent f9cfc56 commit 6965864
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 12 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,16 @@ func Parse(path string) Config {
if err := yaml.Unmarshal(bts, &cfg); err != nil {
log.WithError(err).Fatalf("failed to unmarshall config file: %s", path)
}
return cfg
return validate(cfg)
}

func validate(config Config) Config {
names := make(map[string]bool)
for _, conf := range config.Databases {
if names[conf.Name] {
log.Fatalf("failed to validate configuration. A database named '%s' has already been declared'", conf.Name)
}
names[conf.Name] = true
}
return config
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func watch(db *sql.DB, reg prometheus.Registerer, name string) {
reg.MustRegister(gauges.ScheduledCheckpoints())
reg.MustRegister(gauges.BuffersMaxWrittenClean())
reg.MustRegister(gauges.BuffersWritten())
//reg.MustRegister(gauges.DeadTuples())
reg.MustRegister(gauges.DeadTuples())
reg.MustRegister(gauges.HeapBlocksHit())
reg.MustRegister(gauges.HeapBlocksRead())
reg.MustRegister(gauges.IndexScans())
Expand Down

0 comments on commit 6965864

Please sign in to comment.