From d3fedfaec0d97c015bbebc60cff4eb3aea81b2c3 Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Mon, 4 Oct 2021 13:15:30 +0800 Subject: [PATCH] libbeat/beat: introduce Beat.OutputConfigReloader (#28048) Introduce Beat.OutputConfigReloader, an optional reload.Reloadable that may be set by a beat.Creator in order to watch output config changes. (cherry picked from commit 67f2e2b0bc875902423631eeaf12de0971fbd157) --- CHANGELOG-developer.next.asciidoc | 1 + libbeat/beat/beat.go | 7 +++++++ libbeat/cmd/instance/beat.go | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/CHANGELOG-developer.next.asciidoc b/CHANGELOG-developer.next.asciidoc index d6a94d46f2f..4b89ac3260a 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -114,3 +114,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] diff --git a/libbeat/beat/beat.go b/libbeat/beat/beat.go index 10840899805..9413fcae087 100644 --- a/libbeat/beat/beat.go +++ b/libbeat/beat/beat.go @@ -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" @@ -64,6 +65,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 diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 06beaaefea9..83f213c0fd4 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -875,6 +875,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) }) }