diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 4899fde2f69..71851469564 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -91,6 +91,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d - Fix redis key setting not allowing upper case characters. {pull}18854[18854] {issue}18640[18640] - Fix potential race condition in fingerprint processor. {pull}18738[18738] - Fix seccomp policy for calls to `chmod` and `chown`. {pull}20054[20054] +- Fix issue in autodiscover that kept inputs stopped after config updates. {pull}20305[20305] *Auditbeat* diff --git a/filebeat/input/errors.go b/filebeat/input/errors.go new file mode 100644 index 00000000000..098156abf91 --- /dev/null +++ b/filebeat/input/errors.go @@ -0,0 +1,32 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package input + +import ( + "fmt" +) + +// ErrInputNotFinished struct for reporting errors related to not finished inputs +type ErrInputNotFinished struct { + State string +} + +// Error method of ErrInputNotFinished +func (e *ErrInputNotFinished) Error() string { + return fmt.Sprintf("Can only start an input when all related states are finished: %+v", e.State) +} diff --git a/filebeat/input/file/state.go b/filebeat/input/file/state.go index dde3c6c5421..9ce053cdf27 100644 --- a/filebeat/input/file/state.go +++ b/filebeat/input/file/state.go @@ -18,6 +18,7 @@ package file import ( + "fmt" "os" "strconv" "strings" @@ -97,3 +98,19 @@ func (s *State) IsEmpty() bool { len(s.Meta) == 0 && s.Timestamp.IsZero() } + +// String returns string representation of the struct +func (s *State) String() string { + return fmt.Sprintf( + "{Id: %v, Finished: %v, Fileinfo: %v, Source: %v, Offset: %v, Timestamp: %v, TTL: %v, Type: %v, Meta: %v, FileStateOS: %v}", + s.Id, + s.Finished, + s.Fileinfo, + s.Source, + s.Offset, + s.Timestamp, + s.TTL, + s.Type, + s.Meta, + s.FileStateOS) +} diff --git a/filebeat/input/log/input.go b/filebeat/input/log/input.go index b3cf4049551..67bf582eacb 100644 --- a/filebeat/input/log/input.go +++ b/filebeat/input/log/input.go @@ -170,7 +170,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 fmt.Errorf("Can only start an input when all related states are finished: %+v", state) + return &input.ErrInputNotFinished{State: state.String()} } // Update input states and send new states to registry diff --git a/filebeat/input/runnerfactory.go b/filebeat/input/runnerfactory.go index a47e848bc6d..9f802c3a934 100644 --- a/filebeat/input/runnerfactory.go +++ b/filebeat/input/runnerfactory.go @@ -60,5 +60,9 @@ func (r *RunnerFactory) Create( func (r *RunnerFactory) CheckConfig(cfg *common.Config) error { _, err := r.Create(pipeline.NewNilPipeline(), cfg, nil) + if _, ok := err.(*ErrInputNotFinished); ok { + // error is related to state, and hence config can be considered valid + return nil + } return err }