Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress too many bad error messages when reading from corrupted journal in Journalbeat #26224

Merged
merged 1 commit into from
Jun 28, 2021
Merged
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
34 changes: 34 additions & 0 deletions journalbeat/input/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@
package input

import (
"context"
"fmt"
"strings"
"sync"
"syscall"
"time"

"github.com/elastic/beats/v7/libbeat/processors/add_formatted_index"
"github.com/elastic/go-concert/timed"

"github.com/elastic/beats/v7/libbeat/common/acker"
"github.com/elastic/beats/v7/libbeat/common/atomic"
"github.com/elastic/beats/v7/libbeat/common/fmtstr"

"github.com/elastic/beats/v7/journalbeat/checkpoint"
Expand Down Expand Up @@ -158,6 +164,10 @@ func (i *Input) publishAll() {
go func() {
defer wg.Done()

suppressed := atomic.NewBool(false)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

for {
select {
case <-i.done:
Expand All @@ -168,6 +178,10 @@ func (i *Input) publishAll() {
event, err := r.Next()
if event == nil {
if err != nil {
if i.isErrSuppressed(ctx, err, suppressed) {
i.logger.Debugf("Error message suppressed: EBADMSG")
continue
}
i.logger.Errorf("Error while reading event: %v", err)
}
continue
Expand All @@ -191,6 +205,26 @@ func (i *Input) publishAll() {
}
}

// isErrSuppressed checks if the error is due to a corrupt journal. If yes, only the first error message
// is displayed and then it is suppressed for 5 seconds.
func (i *Input) isErrSuppressed(ctx context.Context, err error, suppressed *atomic.Bool) bool {
if strings.Contains(err.Error(), syscall.EBADMSG.Error()) {
if suppressed.Load() {
return true
}

suppressed.Store(true)
go func(ctx context.Context, suppressed *atomic.Bool) {
if err := timed.Wait(ctx, 5*time.Second); err == nil {
suppressed.Store(false)
}

}(ctx, suppressed)
urso marked this conversation as resolved.
Show resolved Hide resolved
}

return false
}

// Stop stops all readers of the input.
func (i *Input) Stop() {
for _, r := range i.readers {
Expand Down