Skip to content
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

Merged
merged 2 commits into from
Jun 21, 2018

Conversation

vjsamuel
Copy link
Contributor

Allow filebeat to configure an array of inputs using co.elastic.logs/inputs: [stringified json] and co.elastic.metrics/modules to do the same for metricbeat.

@elasticmachine
Copy link
Collaborator

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 {

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 {

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

@ruflin ruflin added module review Filebeat Filebeat Metricbeat Metricbeat containers Related to containers use case labels Jun 20, 2018
@ruflin ruflin requested a review from exekias June 20, 2018 08:22
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 {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruflin modified.

Copy link
Contributor

@exekias exekias left a 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 {
Copy link
Contributor

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{}
Copy link
Contributor

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

@exekias exekias merged commit 0576fe6 into elastic:master Jun 21, 2018
@vjsamuel vjsamuel deleted the add_json_hint branch June 21, 2018 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
containers Related to containers use case Filebeat Filebeat Metricbeat Metricbeat module review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants