Combine libbeat/beat and libbeat/publisher/beat package + move all beat instance handling to libbeat/cmd package#4821
Conversation
- 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)
c32b0e7 to
ebcf8dd
Compare
| "github.com/elastic/beats/libbeat/logp" | ||
| "github.com/elastic/beats/libbeat/publisher/beat" | ||
|
|
||
| "github.com/elastic/beats/filebeat/harvester" |
There was a problem hiding this comment.
do you started to separate filebeat from libbeat imports on purpose?
There was a problem hiding this comment.
yes :)
I did find it weird for filebeat having import order filebeat>libbeat and for packetbeat it being the other way around.
There was a problem hiding this comment.
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.
| // +build !integration | ||
|
|
||
| package beat | ||
| package instance |
There was a problem hiding this comment.
If we have an instance package, it would kind of make sense to have this under the beat package?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Some more cleanup on instance or cmd package would be nice. But this was nothing I wanted to touch right now.
There was a problem hiding this comment.
Yeah, also see some other cleanups coming but this is big enough already :-)
| @@ -1,39 +0,0 @@ | |||
| package beater | |||
There was a problem hiding this comment.
I like this change but not sure how it is related to the rest of the changes?
There was a problem hiding this comment.
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.
|
In general I like the changes you made. I'm not a big fan of the 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. |
andrewkroh
left a comment
There was a problem hiding this comment.
LGTM. I left some comments about the pre-existing godocs.
libbeat/beat/beat.go
Outdated
| ) | ||
|
|
||
| // Creator initializes and configures a new Beater instance used to execute | ||
| // the beat its run-loop. |
libbeat/beat/beat.go
Outdated
| 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 |
There was a problem hiding this comment.
It would be nice to include in the comment what's blocking this from happening or when it can be done.
libbeat/beat/beat.go
Outdated
| // XXX: remove Config from public interface | ||
| Config *BeatConfig // Common Beat configuration data. | ||
|
|
||
| BeatConfig *common.Config // The beats it's own configuration section |
libbeat/beat/info.go
Outdated
| // BeatInfo stores a beats instance meta data. | ||
| type BeatInfo struct { | ||
| type Info struct { | ||
| Beat string // The actual beat its name |
winlogbeat/beater/winlogbeat.go
Outdated
| @@ -49,21 +48,19 @@ func New(b *beat.Beat, _ *common.Config) (beat.Beater, error) { | |||
| // XXX: winlogbeat validates top-level config -> ignore beater config and | |||
There was a problem hiding this comment.
This comment can be removed now that I removed the validation code.
winlogbeat/config/config.go
Outdated
| @@ -23,26 +23,12 @@ type Validator interface { | |||
| Validate() error | |||
There was a problem hiding this comment.
Can this interface be removed too? I think it predates ucfg.
| 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"` |
There was a problem hiding this comment.
Not sure what raw was doing but want to make sure it didn't disappear by accident.
There was a problem hiding this comment.
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.
This PR moves some types and functionality to
libbeat/beatandlibbeat/cmd. Thelibbeat/beatpackage only defines some common/important types and interfaces to be used by actual beats, without providing real implementations. With these changes, thepublisher/libbeat/beatfinally could be fully merged intolibbeat/beatFor examplebeat.Client,beat.Pipeline,beat.Info, .... Setting up a beats instance is moved tolibbeat/cmd/instancepackage (due to lack of a better name), as the different commands implemented bylibbeat/cmddo rely on a shared view of an actual configured instance. The move was also required to resolve quite a number of circular imports, as theinstancepackage 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.
libbeat/publisher/beattolibbeat/beatlibbeat/beatdefines shared type/interfaces between libbeat and the actual beat => reduce public interface (exports) inlibbeat/beatto fields/types really being used/sharedpacketbeat -devicein favor ofpacketbeat device. Removes some clunky hack we used to have for supporting the-deviceflag.common.BeatInfotobeat.Info