From e67c93b0f5394ca0f45b739dc0132eb72a0de438 Mon Sep 17 00:00:00 2001 From: Andrew Wilkins Date: Wed, 22 Sep 2021 18:16:02 +0800 Subject: [PATCH] libbeat/beat: introduce Beat.OutputConfigReloader Introduce Beat.OutputConfigReloader, an optional reload.Reloadable that may be set by a beat.Creator in order to watch output config changes. --- 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 1957c6f0ca7..2160fd599bc 100644 --- a/CHANGELOG-developer.next.asciidoc +++ b/CHANGELOG-developer.next.asciidoc @@ -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] diff --git a/libbeat/beat/beat.go b/libbeat/beat/beat.go index 60bda39d750..823a34a0e9d 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" @@ -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 diff --git a/libbeat/cmd/instance/beat.go b/libbeat/cmd/instance/beat.go index 00e5f89a1c9..d3f7b449ddc 100644 --- a/libbeat/cmd/instance/beat.go +++ b/libbeat/cmd/instance/beat.go @@ -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) }) }