Skip to content

Commit

Permalink
Log warning on unused config keys (#3458)
Browse files Browse the repository at this point in the history
* Log warning on unused config keys

* Comments

* Remove unused config

* Remove unused config
  • Loading branch information
severinson authored Mar 14, 2024
1 parent be3b40c commit 2b9a81c
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
3 changes: 1 addition & 2 deletions cmd/armada/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ func main() {
common.ConfigureLogging()
common.BindCommandlineArguments()

// TODO Load relevant config in one place: don't use viper here and in the config package
// (currently in common).
// TODO Load relevant config in one place: don't use viper here and in LoadConfig.
var config configuration.ArmadaConfig
userSpecifiedConfigs := viper.GetStringSlice(CustomConfigLocation)
common.LoadConfig(&config, "./config/armada", userSpecifiedConfigs)
Expand Down
7 changes: 0 additions & 7 deletions config/armada/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,10 @@ submission:
defaultActiveDeadline: "72h" # 3 days.
defaultActiveDeadlineByResourceRequest:
nvidia.com/gpu: "336h" # 14 days.
eventRetention:
expiryEnabled: true
retentionDuration: 336h
metrics:
refreshInterval: 5m
pulsar:
URL: "pulsar://pulsar:6650"
jobsetEventsTopic: "events"
redisFromPulsarSubscription: "RedisFromPulsar"
hostnameSuffix: "svc"
certNameSuffix: "ingress-tls-certificate"
dedupTable: pulsar_submit_dedup
maxConnectionsPerBroker: 1
compressionType: zlib
Expand Down
2 changes: 0 additions & 2 deletions config/binoculars/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ cordon:
armadaproject.io/cordon-reason: "binoculars"
armadaproject.io/cordon-user: "<user>"
auth:
basicAuth:
enableAuthentication: false
anonymousAuth: true
impersonateUsers: false
kubernetes:
Expand Down
3 changes: 0 additions & 3 deletions config/lookoutv2/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ tls:
certPath: /certs/tls.crt
keyPath: /certs/tls.key
postgres:
maxOpenConns: 100
maxIdleConns: 25
connMaxLifetime: 30m
connection:
host: postgres
port: 5433
Expand Down
1 change: 0 additions & 1 deletion config/scheduler/config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
cyclePeriod: 1s
schedulePeriod: 10s
maxSchedulingDuration: 5s
maxJobsLeasedPerCall: 1000
executorTimeout: 1h
databaseFetchSize: 1000
pulsarSendTimeout: 5s
Expand Down
6 changes: 0 additions & 6 deletions config/scheduleringester/config.yaml
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
postgres:
maxOpenConns: 10
maxIdleConns: 1
connMaxLifetime: 30m
connection:
host: localhost
port: 5432
user: postgres
password: psw
dbname: postgres
sslmode: disable

metrics:
port: 9003

pulsar:
URL: "pulsar://localhost:6650"
jobsetEventsTopic: "events"
receiveTimeout: 5s
backoffTime: 1s
receiverQueueSize: 100

subscriptionName: "scheduler-ingester"
batchSize: 10000
batchDuration: 500ms
Expand Down
26 changes: 23 additions & 3 deletions internal/common/startup.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import (
"strings"
"time"

"github.com/mitchellh/mapstructure"
"golang.org/x/exp/slices"

"github.com/armadaproject/armada/internal/common/certs"

"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -39,7 +42,7 @@ func BindCommandlineArguments() {
}

// TODO Move code relating to config out of common into a new package internal/serverconfig
func LoadConfig(config interface{}, defaultPath string, overrideConfigs []string) *viper.Viper {
func LoadConfig(config any, defaultPath string, overrideConfigs []string) *viper.Viper {
v := viper.NewWithOptions(viper.KeyDelimiter("::"))
v.SetConfigName(baseConfigFileName)
v.AddConfigPath(defaultPath)
Expand All @@ -48,6 +51,9 @@ func LoadConfig(config interface{}, defaultPath string, overrideConfigs []string
os.Exit(-1)
}
log.Infof("Read base config from %s", v.ConfigFileUsed())
if len(overrideConfigs) > 0 {
log.Infof("Read override config from %v", overrideConfigs)
}

for _, overrideConfig := range overrideConfigs {
v.SetConfigFile(overrideConfig)
Expand All @@ -63,12 +69,26 @@ func LoadConfig(config interface{}, defaultPath string, overrideConfigs []string
v.SetEnvPrefix("ARMADA")
v.AutomaticEnv()

err := v.Unmarshal(config, commonconfig.CustomHooks...)
if err != nil {
var metadata mapstructure.Metadata
customHooks := append(slices.Clone(commonconfig.CustomHooks), func(c *mapstructure.DecoderConfig) { c.Metadata = &metadata })
if err := v.Unmarshal(config, customHooks...); err != nil {
log.Error(err)
os.Exit(-1)
}

// Log a warning if there are config keys that don't match a config item in the struct the yaml is decoded into.
// Since such unused keys indicate there's a typo in the config.
// Also log set and unset keys at a debug level.
if len(metadata.Keys) > 0 {
log.Debugf("Decoded keys: %v", metadata.Keys)
}
if len(metadata.Unused) > 0 {
log.Warnf("Unused keys: %v", metadata.Unused)
}
if len(metadata.Unset) > 0 {
log.Debugf("Unset keys: %v", metadata.Unset)
}

return v
}

Expand Down

0 comments on commit 2b9a81c

Please sign in to comment.