Skip to content

Commit

Permalink
libbeat/beat: introduce Beat.OutputConfigReloader (#28048)
Browse files Browse the repository at this point in the history
Introduce Beat.OutputConfigReloader, an optional
reload.Reloadable that may be set by a beat.Creator
in order to watch output config changes.
  • Loading branch information
axw authored Oct 4, 2021
1 parent 813e0e3 commit 67f2e2b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ The list below covers the major changes between 7.0.0-rc2 and master only.
- Add sorting to array fields for generated data files (*-generated.json) {pull}25320[25320]
- Update to go-concert 0.2.0 {pull}27162[27162]
- Update Go version to 1.16.5. {issue}26182[26182] {pull}26186[26186]
- Introduce `libbeat/beat.Beat.OutputConfigReloader` {pull}28048[28048]
7 changes: 7 additions & 0 deletions libbeat/beat/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package beat

import (
"github.com/elastic/beats/v7/libbeat/common"
"github.com/elastic/beats/v7/libbeat/common/reload"
"github.com/elastic/beats/v7/libbeat/instrumentation"
"github.com/elastic/beats/v7/libbeat/keystore"
"github.com/elastic/beats/v7/libbeat/management"
Expand Down Expand Up @@ -63,6 +64,12 @@ type Beat struct {
// pipeline and ML jobs.
Config *BeatConfig // Common Beat configuration data.

// OutputConfigReloader may be set by a Creator to watch for output config changes.
//
// This reloader is called in addition to libbeat's internal output reloader, which
// is responsible for reconfiguring Publisher.
OutputConfigReloader reload.Reloadable

BeatConfig *common.Config // The beat's own configuration section

Fields []byte // Data from fields.yml
Expand Down
5 changes: 5 additions & 0 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,11 @@ func (b *Beat) indexSetupCallback() elasticsearch.ConnectCallback {

func (b *Beat) makeOutputReloader(outReloader pipeline.OutputReloader) reload.Reloadable {
return reload.ReloadableFunc(func(config *reload.ConfigWithMeta) error {
if b.OutputConfigReloader != nil {
if err := b.OutputConfigReloader.Reload(config); err != nil {
return err
}
}
return outReloader.Reload(config, b.createOutput)
})
}
Expand Down

0 comments on commit 67f2e2b

Please sign in to comment.