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

Combine libbeat/beat and libbeat/publisher/beat package + move all beat instance handling to libbeat/cmd package #4821

Merged
merged 13 commits into from
Aug 9, 2017

Conversation

urso
Copy link

@urso urso commented Aug 2, 2017

This PR moves some types and functionality to libbeat/beat and libbeat/cmd. The libbeat/beat package only defines some common/important types and interfaces to be used by actual beats, without providing real implementations. With these changes, the publisher/libbeat/beat finally could be fully merged into libbeat/beat For example beat.Client, beat.Pipeline, beat.Info, .... Setting up a beats instance is moved to libbeat/cmd/instance package (due to lack of a better name), as the different commands implemented by libbeat/cmd do rely on a shared view of an actual configured instance. The move was also required to resolve quite a number of circular imports, as the instance package basically needs to import all other libbeat packages (directly/indirectly) in order to setup a working beat.
Setting up and running a beat instance is still somewhat complicated. Did keep me quite busy in hunting chicken and eggs. Let's see if we can refine/cleanup this somewhat more in later PRs.

  • Move actual beat instance with run loop and configurations to libbeat/cmd/instance
  • Move all definitions from libbeat/publisher/beat to libbeat/beat
  • As libbeat/beat defines shared type/interfaces between libbeat and the actual beat => reduce public interface (exports) in libbeat/beat to fields/types really being used/shared
  • Remove packetbeat -device in favor of packetbeat device. Removes some clunky hack we used to have for supporting the -device flag.
  • Move common.BeatInfo to beat.Info

@urso urso added the in progress Pull request is currently in progress. label Aug 2, 2017
urso added 7 commits August 2, 2017 23:13
- only have commonly shared structs/interfaces in libbeat/beat
- move libbeat/beat functionality to libbeat/cmd/instance package
- update imports/dependencies
- start hiding some exported symbols
- move beat.Client, beat.Event, beat.Pipeline to libbeat/beat
- move some shared config objects from beat.BeatConfig to private
cmd/instance package where easily possible (fix import cycles)
@urso urso force-pushed the pipeline/cleanup-pkg branch from c32b0e7 to ebcf8dd Compare August 2, 2017 21:13
@urso urso added the discuss Issue needs further discussion. label Aug 2, 2017
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/publisher/beat"

"github.com/elastic/beats/filebeat/harvester"
Copy link
Contributor

Choose a reason for hiding this comment

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

do you started to separate filebeat from libbeat imports on purpose?

Copy link
Author

Choose a reason for hiding this comment

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

yes :)

I did find it weird for filebeat having import order filebeat>libbeat and for packetbeat it being the other way around.

Copy link
Contributor

Choose a reason for hiding this comment

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

@andrewkroh WDYT? Can we automate that? :-D

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but not with the standard goimports. It would take a customization to goimports, which isn't a bad idea, it would just take a little time.

@@ -1,6 +1,6 @@
// +build !integration

package beat
package instance
Copy link
Contributor

Choose a reason for hiding this comment

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

If we have an instance package, it would kind of make sense to have this under the beat package?

Copy link
Author

Choose a reason for hiding this comment

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

I put it in libbeat/cmd, as the instance package is used by almost all commands defined in libbeat/cmd. This way all code required or requiring a beat instance is combined in libbeat/cmd.

Copy link
Author

Choose a reason for hiding this comment

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

Some more cleanup on instance or cmd package would be nice. But this was nothing I wanted to touch right now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, also see some other cleanups coming but this is big enough already :-)

@@ -1,39 +0,0 @@
package beater
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this change but not sure how it is related to the rest of the changes?

Copy link
Author

Choose a reason for hiding this comment

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

it's mostly for sanity, as I wanted the libbeat/cmd/instance module to be used only internally. The -devices flag always has been a pretty ugly hack, generating some dependency between the beat and some weird global access to libbeat internals.

@ruflin
Copy link
Contributor

ruflin commented Aug 3, 2017

In general I like the changes you made. I'm not a big fan of the cmd package but I don't have a better suggestion at the moment.

It seems some other cleanups / improvements sneaked into this PR like Winlogbeat Settings or packetbeat device removal. As this is a major change in how beats are setup and will break all community beats I would like to see the unrelated changes in other PR's if possible. This will make it much easier later to follow which things belonged together. For example for the device removal the changelog will link to the PR that only did this.

Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM. I left some comments about the pre-existing godocs.

)

// Creator initializes and configures a new Beater instance used to execute
// the beat its run-loop.
Copy link
Member

Choose a reason for hiding this comment

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

s/beat its/beat's/


SetupMLCallback SetupMLCallback // setup callback for ML job configs
InSetupCmd bool // this is set to true when the `setup` command is called

// XXX: remove Config from public interface
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to include in the comment what's blocking this from happening or when it can be done.

// XXX: remove Config from public interface
Config *BeatConfig // Common Beat configuration data.

BeatConfig *common.Config // The beats it's own configuration section
Copy link
Member

Choose a reason for hiding this comment

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

s/beats it's/beat's/


import "github.com/satori/go.uuid"

// BeatInfo stores a beats instance meta data.
type BeatInfo struct {
type Info struct {
Beat string // The actual beat its name
Copy link
Member

Choose a reason for hiding this comment

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

s/beat its/beat's/

@@ -49,21 +48,19 @@ func New(b *beat.Beat, _ *common.Config) (beat.Beater, error) {
// XXX: winlogbeat validates top-level config -> ignore beater config and
Copy link
Member

@andrewkroh andrewkroh Aug 3, 2017

Choose a reason for hiding this comment

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

This comment can be removed now that I removed the validation code.

@@ -23,26 +23,12 @@ type Validator interface {
Validate() error
Copy link
Member

Choose a reason for hiding this comment

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

Can this interface be removed too? I think it predates ucfg.

@urso urso added refactoring review and removed in progress Pull request is currently in progress. labels Aug 8, 2017
@urso urso changed the title [WIP] Combine libbeat/beat and libbeat/publisher/beat package + move all beat instance handling to libbeat/cmd package Combine libbeat/beat and libbeat/publisher/beat package + move all beat instance handling to libbeat/cmd package Aug 8, 2017
IgnoreOlder time.Duration `config:"ignore_older"`
ReadBufferSize uint `config:"read_buffer_size" validate:"min=1"`
FormatBufferSize uint `config:"format_buffer_size" validate:"min=1"`
Raw map[string]interface{} `config:",inline"`
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what raw was doing but want to make sure it didn't disappear by accident.

Copy link
Author

Choose a reason for hiding this comment

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

I guess it used to be for additional 'validation' on allowed settings. But it's not used anymore in any place, so I removed it.

@kvch kvch merged commit 0cacffe into elastic:master Aug 9, 2017
@urso urso mentioned this pull request Aug 20, 2017
22 tasks
@urso urso added the needs_backport PR is waiting to be backported to other branches. label Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Issue needs further discussion. refactoring review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants