Flush metrics only after all service inputs have stopped
This commit is contained in:
parent
741331308a
commit
6d2b2a0b29
|
@ -315,6 +315,12 @@ func jitterInterval(ininterval, injitter time.Duration) time.Duration {
|
|||
func (a *Agent) Run(shutdown chan struct{}) error {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
flusherShutdown := make(chan struct{})
|
||||
defer func() {
|
||||
close(flusherShutdown)
|
||||
wg.Wait()
|
||||
}()
|
||||
|
||||
a.Config.Agent.FlushInterval.Duration = jitterInterval(
|
||||
a.Config.Agent.FlushInterval.Duration,
|
||||
a.Config.Agent.FlushJitter.Duration)
|
||||
|
@ -353,7 +359,7 @@ func (a *Agent) Run(shutdown chan struct{}) error {
|
|||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if err := a.flusher(shutdown, metricC); err != nil {
|
||||
if err := a.flusher(flusherShutdown, metricC); err != nil {
|
||||
log.Printf("Flusher routine failed, exiting: %s\n", err.Error())
|
||||
close(shutdown)
|
||||
}
|
||||
|
@ -373,8 +379,6 @@ func (a *Agent) Run(shutdown chan struct{}) error {
|
|||
}
|
||||
}
|
||||
|
||||
defer wg.Wait()
|
||||
|
||||
for {
|
||||
if err := a.gatherParallel(metricC); err != nil {
|
||||
log.Printf(err.Error())
|
||||
|
|
Loading…
Reference in New Issue