-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add ability to configure autodiscover with JSON hints #7372
Conversation
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
@@ -64,6 +65,16 @@ func getStringAsList(input string) []string { | |||
return list | |||
} | |||
|
|||
func GetHintAsConfig(hints common.MapStr, key, config string) []common.MapStr { |
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.
exported function GetHintAsConfig should have comment or be unexported
@@ -64,6 +65,16 @@ func getStringAsList(input string) []string { | |||
return list | |||
} | |||
|
|||
func GetHintAsConfig(hints common.MapStr, key, config string) []common.MapStr { |
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.
exported function GetHintAsConfig should have comment or be unexported
func GetHintAsConfig(hints common.MapStr, key, config string) []common.MapStr { | ||
if str := GetHintString(hints, key, config); str != "" { | ||
cfg := []common.MapStr{} | ||
if err := json.Unmarshal([]byte(str), &cfg); err == nil { |
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.
Should we have a debug log when there is an error? like this we could also use err != nil
and then a continue which is what I expected first when I read the code.
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.
@ruflin modified.
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.
Thank you for this code @vjsamuel! This is looking great!
I have some doubts about the annotation name, what do you think about using justco.elastic.logs
and co.elastic.metrics
? Maybe co.elastic.logs.raw
... I'm not sure.
That would make clear that you are overriding any other possible hint. Also, we need to avoid the word inputs
, as Filebeat modules would also work with this code.
I have some concerns around security, as this effectively allows users to spawn any conf. So far current hints are mostly for untrusted users. any opinions here?
Docs need to be updated (https://github.com/elastic/beats/blob/master/metricbeat/docs/autodiscover-hints.asciidoc and https://github.com/elastic/beats/blob/master/filebeat/docs/autodiscover-hints.asciidoc)
@@ -64,6 +66,19 @@ func getStringAsList(input string) []string { | |||
return list | |||
} | |||
|
|||
// GetHintAsConfig can read a hint in the form of a stringified JSON and return a common.MapStr | |||
func GetHintAsConfig(hints common.MapStr, key, config string) []common.MapStr { |
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.
this should probably be GetHintAsConfigs
, as it returns a list
// GetHintAsConfig can read a hint in the form of a stringified JSON and return a common.MapStr | ||
func GetHintAsConfig(hints common.MapStr, key, config string) []common.MapStr { | ||
if str := GetHintString(hints, key, config); str != "" { | ||
cfg := []common.MapStr{} |
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.
Would it make sense to accept both a list or a single config {...}
? I guess in most cases the user wants just a config, with some special exceptions where you may want more
Allow filebeat to configure an array of inputs using
co.elastic.logs/inputs: [stringified json]
andco.elastic.metrics/modules
to do the same for metricbeat.