-
Notifications
You must be signed in to change notification settings - Fork 169
Fix config parsing for structs and pointers to structs #345
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,13 +99,7 @@ func (cfg *Config) Unmarshal(componentParser *config.Parser) error { | |
// which is a problem when unmarshalling custom agent monitor configs. Here we use a map of lowercase to supported | ||
// case tag key names and update the keys where applicable. | ||
yamlTags := yamlTagsFromStruct(monitorConfigType) | ||
for key, val := range allSettings { | ||
updatedKey := yamlTags[key] | ||
if updatedKey != "" { | ||
delete(allSettings, key) | ||
allSettings[updatedKey] = val | ||
} | ||
} | ||
recursivelyCapitalizeConfigKeys(allSettings, yamlTags) | ||
|
||
asBytes, err := yaml.Marshal(allSettings) | ||
if err != nil { | ||
|
@@ -131,6 +125,19 @@ func (cfg *Config) Unmarshal(componentParser *config.Parser) error { | |
return nil | ||
} | ||
|
||
func recursivelyCapitalizeConfigKeys(settings map[string]interface{}, yamlTags map[string]string) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a viper-centric issue I wonder if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rmfitzpatrick - I've moved these methods to a helper and exposed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do indeed! |
||
for key, val := range settings { | ||
updatedKey := yamlTags[key] | ||
if updatedKey != "" { | ||
delete(settings, key) | ||
settings[updatedKey] = val | ||
if m, ok := val.(map[string]interface{}); ok { | ||
recursivelyCapitalizeConfigKeys(m, yamlTags) | ||
} | ||
} | ||
} | ||
} | ||
|
||
func getStringSliceFromAllSettings(allSettings map[string]interface{}, key string, errToReturn error) ([]string, error) { | ||
var items []string | ||
if value, ok := allSettings[key]; ok { | ||
|
@@ -165,11 +172,20 @@ func yamlTagsFromStruct(s reflect.Type) map[string]string { | |
} | ||
|
||
fieldType := field.Type | ||
if fieldType.Kind() == reflect.Struct { | ||
switch fieldType.Kind() { | ||
case reflect.Struct: | ||
otherFields := yamlTagsFromStruct(fieldType) | ||
for k, v := range otherFields { | ||
yamlTags[k] = v | ||
} | ||
case reflect.Ptr: | ||
fieldTypeElem := fieldType.Elem() | ||
if fieldTypeElem.Kind() == reflect.Struct { | ||
otherFields := yamlTagsFromStruct(fieldTypeElem) | ||
for k, v := range otherFields { | ||
yamlTags[k] = v | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
receivers: | ||
smartagent/exec: | ||
type: telegraf/exec | ||
commands: [ 'powershell.exe -Command "\Monitoring\Get_Directory.ps1"' ] | ||
telegrafParser: | ||
dataFormat: "influx" | ||
smartagent/kubernetes_volumes: | ||
type: kubernetes-volumes | ||
kubeletAPI: | ||
authType: serviceAccount | ||
url: https://192.168.99.103:10250 | ||
|
||
processors: | ||
nop: | ||
|
||
exporters: | ||
nop: | ||
|
||
service: | ||
pipelines: | ||
metrics: | ||
receivers: | ||
- smartagent/exec | ||
- smartagent/kubernetes_volumes | ||
processors: [nop] | ||
exporters: [nop] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should fix the issue reported in #322, not being able to set
authType
inkubelet.APIConfig
.