Skip to content

Commit 511f67d

Browse files
committed
Properly shut down crawler in case one prospector is misconfigured
If one prospector started to already send data and a second one was misconfigured, the beat paniced during shutdown. This is no prevented by properly shutting down the crawler also on error. Closes #3917
1 parent aec81e3 commit 511f67d

File tree

8 files changed

+36
-2
lines changed

8 files changed

+36
-2
lines changed

CHANGELOG.asciidoc

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ https://github.com/elastic/beats/compare/v5.1.1...master[Check the HEAD diff]
6161
- Downgrade Elasticsearch per batch item failure log to debug level. {issue}3953[3953]
6262
- Allow log lines without a program name in the Syslog fileset. {pull}3944[3944]
6363
- Fix panic in JSON decoding code if the input line is "null". {pull}4042[4042]
64+
- Properly shut down crawler in case one prospector is misconfigured. {pull}4037[4037]
6465

6566
*Heartbeat*
6667
- Add default ports in HTTP monitor. {pull}3924[3924]

filebeat/beater/filebeat.go

+1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ func (fb *Filebeat) Run(b *beat.Beat) error {
184184

185185
err = crawler.Start(registrar, config.ProspectorReload)
186186
if err != nil {
187+
crawler.Stop()
187188
return err
188189
}
189190

filebeat/crawler/crawler.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (c *Crawler) startProspector(config *common.Config, states []file.State) er
7676

7777
err = p.LoadStates(states)
7878
if err != nil {
79-
return fmt.Errorf("error loading states for propsector %v: %v", p.ID(), err)
79+
return fmt.Errorf("error loading states for prospector %v: %v", p.ID(), err)
8080
}
8181

8282
c.prospectors[p.ID()] = p

filebeat/prospector/prospector.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (p *Prospector) Start() {
148148
logp.Info("Prospector channel stopped")
149149
return
150150
case <-p.beatDone:
151-
logp.Info("Prospector channel stopped")
151+
logp.Info("Prospector channel stopped because beat is stopping.")
152152
return
153153
case event := <-p.harvesterChan:
154154
// No stopping on error, because on error it is expected that beatDone is closed

filebeat/prospector/prospector_log.go

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ func NewLog(p *Prospector) (*Log, error) {
3232
config: p.config,
3333
}
3434

35+
if len(p.config.Paths) == 0 {
36+
return nil, fmt.Errorf("each prospector must have at least one path defined")
37+
}
38+
3539
return prospectorer, nil
3640
}
3741

filebeat/prospector/prospector_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ func TestProspectorFileExclude(t *testing.T) {
2828

2929
prospector := Prospector{
3030
config: prospectorConfig{
31+
Paths: []string{"test.log"},
3132
ExcludeFiles: []match.Matcher{match.MustCompile(`\.gz$`)},
3233
},
3334
}

filebeat/tests/system/config/filebeat.yml.j2

+3
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ filebeat.prospectors:
8282
max_lines: {{ max_lines|default(500) }}
8383
{% endif %}
8484
{% endif %}
85+
{% if prospector_raw %}
86+
{{prospector_raw}}
87+
{% endif %}
8588

8689
filebeat.spool_size:
8790
filebeat.shutdown_timeout: {{ shutdown_timeout|default(0) }}

filebeat/tests/system/test_shutdown.py

+24
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,27 @@ def nasa_logs(self):
146146
self.copy_files(["logs/nasa-50k.log"],
147147
source_dir="../files",
148148
target_dir="log")
149+
150+
def test_stopping_empty_path(self):
151+
"""
152+
Test filebeat stops properly when 1 prospector has an invalid config.
153+
"""
154+
155+
prospector_raw = """
156+
- input_type: log
157+
paths: []
158+
"""
159+
160+
self.render_config_template(
161+
path=os.path.abspath(self.working_dir) + "/log/*",
162+
prospector_raw=prospector_raw,
163+
)
164+
filebeat = self.start_beat()
165+
time.sleep(2)
166+
167+
# Wait until first flush
168+
self.wait_until(
169+
lambda: self.log_contains_count("No paths were defined for prospector") >= 1,
170+
max_timeout=5)
171+
172+
filebeat.check_wait(exit_code=1)

0 commit comments

Comments
 (0)