Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions generator/apache/apache.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,20 +134,24 @@ func (g *ApacheLogGenerator) worker(workerID int) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0 // Never stop retrying

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker stopping", zap.Int("worker_id", workerID))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
Expand All @@ -156,9 +160,11 @@ func (g *ApacheLogGenerator) worker(workerID int) {
g.logger.Error("Failed to write log",
zap.Int("worker_id", workerID),
zap.Error(err))
timer.Reset(backoffConfig.NextBackOff())
continue
}
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions generator/apache_combined/apache_combined.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,24 @@ func (g *ApacheCombinedLogGenerator) worker(workerID int) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0 // Never stop retrying

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker stopping", zap.Int("worker_id", workerID))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
Expand All @@ -153,9 +157,11 @@ func (g *ApacheCombinedLogGenerator) worker(workerID int) {
g.logger.Error("Failed to write log",
zap.Int("worker_id", workerID),
zap.Error(err))
timer.Reset(backoffConfig.NextBackOff())
continue
}
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions generator/apache_error/apache_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,24 @@ func (g *ApacheErrorLogGenerator) worker(workerID int) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0 // Never stop retrying

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker stopping", zap.Int("worker_id", workerID))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
Expand All @@ -150,9 +154,11 @@ func (g *ApacheErrorLogGenerator) worker(workerID int) {
g.logger.Error("Failed to write log",
zap.Int("worker_id", workerID),
zap.Error(err))
timer.Reset(backoffConfig.NextBackOff())
continue
}
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions generator/filegen/filegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,20 +443,24 @@ func (g *FileLogGenerator) worker(id int, files []string) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0 // Never stop retrying

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker received stop signal", zap.Int("id", id))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
Expand All @@ -471,11 +475,13 @@ func (g *FileLogGenerator) worker(id int, files []string) {
g.logger.Error("Error reading file", zap.String("file", file), zap.Error(err))
generator.BlitzGeneratorWriteErrorsCounter.Add(context.Background(), 1, componentName)
// On error, backoff will automatically handle retry timing
timer.Reset(backoffConfig.NextBackOff())
continue
}

// On success, reset backoff to configured rate
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
fileIdx += g.workers
}
}
Expand Down
12 changes: 9 additions & 3 deletions generator/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,24 @@ func (g *JSONLogGenerator) worker(workerID int) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0 // Never stop retrying

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker stopping", zap.Int("worker_id", workerID))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
Expand All @@ -205,9 +209,11 @@ func (g *JSONLogGenerator) worker(workerID int) {
g.logger.Error("Failed to write log",
zap.Int("worker_id", workerID),
zap.Error(err))
timer.Reset(backoffConfig.NextBackOff())
continue
}
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions generator/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,24 @@ func (g *Generator) worker(workerID int) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker stopping", zap.Int("worker_id", workerID))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
Expand All @@ -174,9 +178,11 @@ func (g *Generator) worker(workerID int) {
g.logger.Error("Failed to write log",
zap.Int("worker_id", workerID),
zap.Error(err))
timer.Reset(backoffConfig.NextBackOff())
continue
}
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions generator/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,24 @@ func (g *Generator) worker(workerID int) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker stopping", zap.Int("worker_id", workerID))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
Expand All @@ -177,9 +181,11 @@ func (g *Generator) worker(workerID int) {
g.logger.Error("Failed to write log",
zap.Int("worker_id", workerID),
zap.Error(err))
timer.Reset(backoffConfig.NextBackOff())
continue
}
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions generator/okta/okta.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,24 @@ func (g *Generator) worker(workerID int) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker stopping", zap.Int("worker_id", workerID))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
Expand All @@ -291,9 +295,11 @@ func (g *Generator) worker(workerID int) {
g.logger.Error("Failed to write log",
zap.Int("worker_id", workerID),
zap.Error(err))
timer.Reset(backoffConfig.NextBackOff())
continue
}
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions generator/paloalto/paloalto.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,34 @@ func (g *Generator) worker(workerID int) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker stopping", zap.Int("worker_id", workerID))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
if err := g.generateAndWrite(workerID); err != nil {
g.logger.Error("Failed to write log", zap.Int("worker_id", workerID), zap.Error(err))
timer.Reset(backoffConfig.NextBackOff())
continue
}
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions generator/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,24 @@ func (g *Generator) worker(workerID int) {
backoffConfig.MaxInterval = 5 * time.Second
backoffConfig.MaxElapsedTime = 0

backoffTicker := backoff.NewTicker(backoffConfig)
defer backoffTicker.Stop()
// Drive the timer from this goroutine only. backoff.ExponentialBackOff is
// not safe for concurrent use, so we never hand it to backoff.NewTicker's
// internal goroutine; instead we own every NextBackOff/Reset call here.
timer := time.NewTimer(backoffConfig.NextBackOff())
defer timer.Stop()

for {
select {
case <-g.stopCh:
g.logger.Debug("Worker stopping", zap.Int("worker_id", workerID))
return
case <-backoffTicker.C:
case <-timer.C:
if g.tracker != nil && !g.tracker.Acquire() {
select {
case <-g.stopCh:
return
case <-g.tracker.ResumeC():
timer.Reset(backoffConfig.NextBackOff())
continue
}
}
Expand All @@ -329,9 +333,11 @@ func (g *Generator) worker(workerID int) {
g.logger.Error("Failed to write log",
zap.Int("worker_id", workerID),
zap.Error(err))
timer.Reset(backoffConfig.NextBackOff())
continue
}
backoffConfig.Reset()
timer.Reset(backoffConfig.NextBackOff())
}
}
}
Expand Down
Loading