From 1f812daf98d3691285017ccb89099c3370c18c49 Mon Sep 17 00:00:00 2001 From: chrismark Date: Wed, 2 Sep 2020 11:20:53 +0300 Subject: [PATCH 1/4] Handle input-not-finished errors in config reload Signed-off-by: chrismark --- filebeat/input/log/input.go | 2 +- filebeat/input/runnerfactory.go | 2 +- libbeat/cfgfile/list.go | 8 +++++++- {filebeat/input => libbeat/common}/errors.go | 5 +++-- 4 files changed, 12 insertions(+), 5 deletions(-) rename {filebeat/input => libbeat/common}/errors.go (98%) diff --git a/filebeat/input/log/input.go b/filebeat/input/log/input.go index a1837bbd471..365da416ed3 100644 --- a/filebeat/input/log/input.go +++ b/filebeat/input/log/input.go @@ -175,7 +175,7 @@ func (p *Input) loadStates(states []file.State) error { // In case a input is tried to be started with an unfinished state matching the glob pattern if !state.Finished { - return &input.ErrInputNotFinished{State: state.String()} + return &common.ErrInputNotFinished{State: state.String()} } // Convert state to current identifier if different diff --git a/filebeat/input/runnerfactory.go b/filebeat/input/runnerfactory.go index afd67d4e08a..f4973e47948 100644 --- a/filebeat/input/runnerfactory.go +++ b/filebeat/input/runnerfactory.go @@ -59,7 +59,7 @@ func (r *RunnerFactory) Create( func (r *RunnerFactory) CheckConfig(cfg *common.Config) error { _, err := r.Create(pipeline.NewNilPipeline(), cfg) - if _, ok := err.(*ErrInputNotFinished); ok { + if _, ok := err.(*common.ErrInputNotFinished); ok { // error is related to state, and hence config can be considered valid return nil } diff --git a/libbeat/cfgfile/list.go b/libbeat/cfgfile/list.go index fc50baa3345..a4d7662dcfa 100644 --- a/libbeat/cfgfile/list.go +++ b/libbeat/cfgfile/list.go @@ -92,7 +92,13 @@ func (r *RunnerList) Reload(configs []*reload.ConfigWithMeta) error { for hash, config := range startList { runner, err := createRunner(r.factory, r.pipeline, config) if err != nil { - r.logger.Errorf("Error creating runner from config: %s", err) + if _, ok := err.(*common.ErrInputNotFinished); ok { + // error is related to state, we should not log at error level + r.logger.Debugf("Error creating runner from config: %s", err) + return nil + } else { + r.logger.Errorf("Error creating runner from config: %s", err) + } errs = append(errs, errors.Wrap(err, "Error creating runner from config")) continue } diff --git a/filebeat/input/errors.go b/libbeat/common/errors.go similarity index 98% rename from filebeat/input/errors.go rename to libbeat/common/errors.go index 098156abf91..c3ad682712b 100644 --- a/filebeat/input/errors.go +++ b/libbeat/common/errors.go @@ -15,10 +15,10 @@ // specific language governing permissions and limitations // under the License. -package input +package common import ( - "fmt" +"fmt" ) // ErrInputNotFinished struct for reporting errors related to not finished inputs @@ -30,3 +30,4 @@ type ErrInputNotFinished struct { func (e *ErrInputNotFinished) Error() string { return fmt.Sprintf("Can only start an input when all related states are finished: %+v", e.State) } + From 05db8451bc0b5ede7221a35d2e6a4c9d6618caa7 Mon Sep 17 00:00:00 2001 From: chrismark Date: Wed, 2 Sep 2020 11:28:51 +0300 Subject: [PATCH 2/4] add changelog entry Signed-off-by: chrismark --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index c85bf81e5f3..2aa9ef4111a 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -167,6 +167,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - [Metricbeat][Kubernetes] Change cluster_ip field from ip to keyword. {pull}20571[20571] - Rename cloud.provider `az` value to `azure` inside the add_cloud_metadata processor. {pull}20689[20689] - Add missing country_name geo field in `add_host_metadata` and `add_observer_metadata` processors. {issue}20796[20796] {pull}20811[20811] +- [Autodiscover] Handle input-not-finished errors in config reload. {pull}20915[20915] *Auditbeat* From 46ca73dfe06c28b4f1962f06a8a4bc6e376e29a8 Mon Sep 17 00:00:00 2001 From: chrismark Date: Wed, 2 Sep 2020 11:30:02 +0300 Subject: [PATCH 3/4] fix Signed-off-by: chrismark --- libbeat/cfgfile/list.go | 1 - 1 file changed, 1 deletion(-) diff --git a/libbeat/cfgfile/list.go b/libbeat/cfgfile/list.go index a4d7662dcfa..9b62d95f6a9 100644 --- a/libbeat/cfgfile/list.go +++ b/libbeat/cfgfile/list.go @@ -95,7 +95,6 @@ func (r *RunnerList) Reload(configs []*reload.ConfigWithMeta) error { if _, ok := err.(*common.ErrInputNotFinished); ok { // error is related to state, we should not log at error level r.logger.Debugf("Error creating runner from config: %s", err) - return nil } else { r.logger.Errorf("Error creating runner from config: %s", err) } From 4b9a860c6396c8128cabc9f0b8928d57ce53eaef Mon Sep 17 00:00:00 2001 From: chrismark Date: Wed, 2 Sep 2020 11:34:05 +0300 Subject: [PATCH 4/4] fmt code Signed-off-by: chrismark --- libbeat/common/errors.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libbeat/common/errors.go b/libbeat/common/errors.go index c3ad682712b..68fecb8f550 100644 --- a/libbeat/common/errors.go +++ b/libbeat/common/errors.go @@ -18,7 +18,7 @@ package common import ( -"fmt" + "fmt" ) // ErrInputNotFinished struct for reporting errors related to not finished inputs @@ -30,4 +30,3 @@ type ErrInputNotFinished struct { func (e *ErrInputNotFinished) Error() string { return fmt.Sprintf("Can only start an input when all related states are finished: %+v", e.State) } -