forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix harvester shutdown for prospector reloading
There are two options for stopping a harvester or a prospector. Either the harvester and prospector finish sending all events and stop them self or they are killed because the output is blocking. In case of shutting down filebeat without using `shutdown_timeout` filebeat is expected to shut down as fast as possible. This means channels are directly closed and the events are not passed through to the registry. In case of dynamic prospector reloading, prospectors and harvesters must be stopped properly as otherwise no new harvester for the same file can be started. To make this possible the following changes were made: * Introduce harvester tracking in prospector to better control / manage the harvesters. The implementation is based on a harvester registry which starts and stops the harvesters * Use an outlet to send events from harvester to prospector. This outlet has an additional signal to have two options on when the outlet should be finished. Like this the outlet can be stopped by the harvester itself or globally through closing beatDone. * Introduce more done channels in prospector to make shutdown more fine grained * Add system tests to verify new behaviour Closes elastic#3546
- Loading branch information
Showing
10 changed files
with
374 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package channel | ||
|
||
import ( | ||
"sync" | ||
"sync/atomic" | ||
|
||
"github.com/elastic/beats/filebeat/input" | ||
) | ||
|
||
type Outlet struct { | ||
wg *sync.WaitGroup | ||
done <-chan struct{} | ||
signal <-chan struct{} | ||
channel chan *input.Event | ||
isOpen int32 // atomic indicator | ||
} | ||
|
||
func NewOutlet( | ||
done <-chan struct{}, | ||
c chan *input.Event, | ||
wg *sync.WaitGroup, | ||
) *Outlet { | ||
return &Outlet{ | ||
done: done, | ||
channel: c, | ||
wg: wg, | ||
isOpen: 1, | ||
} | ||
} | ||
|
||
// SetSignal sets the signal channel for OnEventSignal | ||
func (o *Outlet) SetSignal(signal <-chan struct{}) { | ||
o.signal = signal | ||
} | ||
|
||
func (o *Outlet) OnEvent(event *input.Event) bool { | ||
open := atomic.LoadInt32(&o.isOpen) == 1 | ||
if !open { | ||
return false | ||
} | ||
|
||
if o.wg != nil { | ||
o.wg.Add(1) | ||
} | ||
|
||
select { | ||
case <-o.done: | ||
if o.wg != nil { | ||
o.wg.Done() | ||
} | ||
atomic.StoreInt32(&o.isOpen, 0) | ||
return false | ||
case o.channel <- event: | ||
return true | ||
} | ||
} | ||
|
||
// OnEventSignal can be stopped by the signal that is set with SetSignal | ||
// This does not close the outlet. Only OnEvent does close the outlet. | ||
func (o *Outlet) OnEventSignal(event *input.Event) bool { | ||
open := atomic.LoadInt32(&o.isOpen) == 1 | ||
if !open { | ||
return false | ||
} | ||
|
||
if o.wg != nil { | ||
o.wg.Add(1) | ||
} | ||
|
||
select { | ||
case <-o.signal: | ||
if o.wg != nil { | ||
o.wg.Done() | ||
} | ||
o.signal = nil | ||
return false | ||
case o.channel <- event: | ||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.