-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 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 #3546 * review added (cherry picked from commit 15b32e4)
- Loading branch information
Showing
10 changed files
with
384 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,90 @@ | ||
package channel | ||
|
||
import ( | ||
"sync" | ||
"sync/atomic" | ||
|
||
"github.com/elastic/beats/filebeat/input" | ||
) | ||
|
||
// Outlet struct is used to be passed to an object which needs an outlet | ||
// | ||
// The difference between signal and done channel is as following: | ||
// - signal channel can be added through SetSignal and is used to | ||
// interrupt events sent through OnEventSignal- | ||
// - done channel is used to close and stop the outlet | ||
// | ||
// If SetSignal is used, it must be ensure that there is only one event producer. | ||
type Outlet struct { | ||
wg *sync.WaitGroup // Use for counting active events | ||
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 | ||
// If SetSignal is used, it must be ensure that only one producer exists. | ||
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. | ||
// If OnEventSignal is used, it must be ensured that only one producer is used. | ||
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.