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

[Generator] Fix metricbeat-style custom beats #13293

Merged

Conversation

fearful-symmetry
Copy link
Contributor

This is a draft for now, as I just hacked it into functionality, and now I need to thoroughly test what I've done and clean it up. Also, the config generation stuff isn't something I have much experience with.

So, I noticed that metricbeat-style custom beats have a lot of issues. A few of the smaller ones are fixed in other PRs. This one addresses three major issues:

  • The current custom metricbeat setup uses a different bootstrap as nearly every other beat. This changes it to use the cmd.RootCmd.Execute() init as everything else.

  • The cmd/instance library wasn't properly picking up the beat name. This meant that when you compiled your beat, it would fallback to a default name of beat, meaning that if you followed our instructions, the beat won't run, as it'll look for a config file named beat.yml

  • Modules weren't working properly, as there was no templates in the default config files, leading to a yml block called metricbeat.config.modules which obviously wouldn't work.

This PR changes the beat init, adds a bunch of tempating, and changes the custom beat to use its own config files.

@fearful-symmetry fearful-symmetry added bug :Generator Related to code generators for building custom Beats or modules. Team:Integrations Label for the Integrations team labels Aug 20, 2019
@fearful-symmetry fearful-symmetry requested review from ycombinator and a team August 20, 2019 17:22
@fearful-symmetry fearful-symmetry self-assigned this Aug 20, 2019
@fearful-symmetry
Copy link
Contributor Author

Another thing: There's no make fmt inside the generator...

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Nice job here, all beats based on Metricbeat should be similar.

return nil, errors.Wrap(err, "initialization error")
}
return modulesManager, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should move the one in github.com/elastic/beats/metricbeat/cmd to some reusable place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, I can try that. Might not be a bad idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thinking about this. We'd need to separate out the ModulesManager and root code in metricbeat, since both the user beats and metricbeat share an init() that would fight with each other.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is what I meant with moving to some reusable place 😬 But ok, we can leave this for a future change dedicated only to this.

@fearful-symmetry fearful-symmetry force-pushed the metricbeat-gen-cmd-refactor branch from e148f69 to 7e5f211 Compare August 21, 2019 14:57
@fearful-symmetry fearful-symmetry marked this pull request as ready for review August 21, 2019 16:40
@fearful-symmetry fearful-symmetry marked this pull request as ready for review August 21, 2019 16:41
@fearful-symmetry
Copy link
Contributor Author

Alright, taking this out of draft since I got it working, at least.

@fearful-symmetry
Copy link
Contributor Author

jenkins, test this

@fearful-symmetry
Copy link
Contributor Author

So, there's one ergonomics thing that's bugging me. When you make a new metricset, it starts out as disabled, as well as enabled:false in the yml file. In addition, when you run make update it re-disables the module. It's...not a great setup.

@fearful-symmetry
Copy link
Contributor Author

Fixing the behavior of make configs is probably gonna have to wait, it's a whole different thing, and I'm probably gonna break things if I touch it.

@fearful-symmetry
Copy link
Contributor Author

Jenkins, test this

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

This looks good, if it works for you lets ship it so we can continue with other improvements. Thanks for taking care of this!

{{.BeatName}}.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false

Copy link
Member

Choose a reason for hiding this comment

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

It'd be good if metricbeat would use the same files, so we remember to maintain them. Maybe a way to do it is to generate a custom beat called "metricbeat", and check that these files are the same as the ones for the real Metricbeat.

But let's forget about this by now.

mkdir -p vendor/github.com/elastic
cp -R ${GOPATH}/src/github.com/elastic/beats vendor/github.com/elastic/
mkdir -p vendor/github.com/elastic/beats
git archive --remote ${BEAT_GOPATH}/src/github.com/elastic/beats HEAD | tar -x --exclude=x-pack -C vendor/github.com/elastic/beats
Copy link
Member

Choose a reason for hiding this comment

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

Thanks!

return nil, errors.Wrap(err, "initialization error")
}
return modulesManager, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, this is what I meant with moving to some reusable place 😬 But ok, we can leave this for a future change dedicated only to this.

@jsoriano
Copy link
Member

jsoriano commented Aug 22, 2019

So, there's one ergonomics thing that's bugging me. When you make a new metricset, it starts out as disabled, as well as enabled:false in the yml file. In addition, when you run make update it re-disables the module. It's...not a great setup.

Umm, this is weird, I think we should have the metricset with enabled: true by default. Maybe this comes from a time before having default metricsets.

@fearful-symmetry
Copy link
Contributor Author

jenkins, test this

1 similar comment
@fearful-symmetry
Copy link
Contributor Author

jenkins, test this

@fearful-symmetry fearful-symmetry merged commit ab7b732 into elastic:master Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug :Generator Related to code generators for building custom Beats or modules. Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants