config: apply environment overrides before unmarshal - #902
Conversation
karimra
left a comment
There was a problem hiding this comment.
The real problem is that _ has two meanings. In log-file it is a dash, and log-file is a struct field. In clustering.locker.address it is a level of nesting, and that key lives inside a map[string]any. envToMap cannot know which meaning to use. Moving the call does not fix this. It only changes a silent failure into a crash at startup.
Could you apply the _ splitting only to the free-form sections (clustering, outputs, inputs, processors, loader, actions)? For the other keys, viper's AutomaticEnv and the key replacer already work, because those keys are struct fields with known names. This way the guessing happens only where the keys are not known in advance.
1a74abf to
38c435e
Compare
|
Thanks for the clarification. I updated the implementation so underscore splitting is limited to the free-form sections: clustering, outputs, inputs, processors, loader, and actions. Known struct-backed fields continue through Viper AutomaticEnv/key replacement. I also added regression coverage for GNMIC_LOG_FILE and GNMIC_CLUSTER_NAME alongside GNMIC_CLUSTERING_LOCKER_ADDRESS, and updated the existing environment helper tests to reflect the scoped behavior. Full go test ./..., go vet ./..., and git diff --check pass locally. |
Fixes #833
Nested free-form collector configuration supplied through
GNMIC_*environment variables was not reflected in the unmarshaled
Config.Apply environment-backed free-form configuration before unmarshaling,
while limiting underscore-based nesting to sections whose keys are not
known ahead of time:
clusteringoutputsinputsprocessorsloaderactionsKnown struct-backed configuration such as
cluster-name,log-file,and
formatcontinues to use Viper'sAutomaticEnvand environmentkey replacer. This avoids treating underscores in variables such as
GNMIC_LOG_FILEas nesting separators while still supporting nestedvalues such as
GNMIC_CLUSTERING_LOCKER_ADDRESS.Regression coverage verifies:
GNMIC_LOG_FILEandGNMIC_CLUSTER_NAMEoverride their fieldsGNMIC_CLUSTERING_LOCKER_ADDRESSoverrides nested free-form configTesting:
go test ./pkg/config -count=1go test ./... -count=1go vet ./...git diff --check