Skip to content

Commit

Permalink
Cherry-pick #20305 to 7.8: [Autodiscovery] Ignore ErrInputNotFinished…
Browse files Browse the repository at this point in the history
… errors in autodiscover config checks (#20339)

* [Autodiscovery] Ignore ErrInputNotFinished errors in autodiscover config checks (#20305)

(cherry picked from commit 7a34167)

* Update CHANGELOG.next.asciidoc
  • Loading branch information
ChrsMark authored Jul 30, 2020
1 parent 6959227 commit 18a1efe
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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*

Expand Down
32 changes: 32 additions & 0 deletions filebeat/input/errors.go
Original file line number Diff line number Diff line change
@@ -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)
}
17 changes: 17 additions & 0 deletions filebeat/input/file/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package file

import (
"fmt"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion filebeat/input/log/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions filebeat/input/runnerfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 18a1efe

Please sign in to comment.