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

Commit 6965864

Browse files
Diogo Nicoletidiogonicoleti
authored andcommitted
Add validation for duplicated database entries
1 parent f9cfc56 commit 6965864

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

config/config.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,16 @@ func Parse(path string) Config {
2525
if err := yaml.Unmarshal(bts, &cfg); err != nil {
2626
log.WithError(err).Fatalf("failed to unmarshall config file: %s", path)
2727
}
28-
return cfg
28+
return validate(cfg)
29+
}
30+
31+
func validate(config Config) Config {
32+
names := make(map[string]bool)
33+
for _, conf := range config.Databases {
34+
if names[conf.Name] {
35+
log.Fatalf("failed to validate configuration. A database named '%s' has already been declared'", conf.Name)
36+
}
37+
names[conf.Name] = true
38+
}
39+
return config
2940
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func watch(db *sql.DB, reg prometheus.Registerer, name string) {
8484
reg.MustRegister(gauges.ScheduledCheckpoints())
8585
reg.MustRegister(gauges.BuffersMaxWrittenClean())
8686
reg.MustRegister(gauges.BuffersWritten())
87-
//reg.MustRegister(gauges.DeadTuples())
87+
reg.MustRegister(gauges.DeadTuples())
8888
reg.MustRegister(gauges.HeapBlocksHit())
8989
reg.MustRegister(gauges.HeapBlocksRead())
9090
reg.MustRegister(gauges.IndexScans())

0 commit comments

Comments
 (0)