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

Log dropped events at the debug level #9251

Merged
merged 6 commits into from
Dec 2, 2018
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha1...master[Check the HEAD d
*Affecting all Beats*

- Fix autodiscover configurations stopping when metadata is missing. {pull}8851[8851]
- Log events at the debug level when dropped by encoding problems. {pull}9251[9251]

*Auditbeat*

Expand Down
1 change: 1 addition & 0 deletions libbeat/outputs/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (c *console) publishEvent(event *publisher.Event) bool {
}

logp.Critical("Unable to encode event: %v", err)
logp.Debug("console", "Failed event: %v", event)
return false
}

Expand Down
1 change: 1 addition & 0 deletions libbeat/outputs/elasticsearch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ func bulkEncodePublishRequest(
}
if err := body.Add(meta, event); err != nil {
logp.Err("Failed to encode event: %s", err)
logp.Debug("elasticsearch", "Failed event: %v", event)
continue
}
okEvents = append(okEvents, data[i])
Expand Down
1 change: 1 addition & 0 deletions libbeat/outputs/fileout/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (out *fileOutput) Publish(
} else {
logp.Warn("Failed to serialize the event: %v", err)
}
logp.Debug("file", "Failed event: %v", event)

dropped++
continue
Expand Down
1 change: 1 addition & 0 deletions libbeat/outputs/kafka/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ func (c *client) getEventMessage(data *publisher.Event) (*message, error) {

serializedEvent, err := c.codec.Encode(c.index, event)
if err != nil {
logp.Debug("kafka", "Failed event: %v", event)
return nil, err
}

Expand Down
8 changes: 6 additions & 2 deletions libbeat/outputs/logstash/enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import (

func makeLogstashEventEncoder(info beat.Info, escapeHTML bool, index string) func(interface{}) ([]byte, error) {
enc := json.New(false, escapeHTML, info.Version)
return func(event interface{}) ([]byte, error) {
return enc.Encode(index, event.(*beat.Event))
return func(event interface{}) (d []byte, err error) {
d, err = enc.Encode(index, event.(*beat.Event))
if err != nil {
debugf("Failed to encode event: %v", event)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should still include an error log here, as we have for the other outputs. Otherwise it's most likely to get unnoticed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are already errors logged for all events failures for both implementations (sync and async). But I wanted to add debug logging only for events failed to encode, and unlike the other outputs, on this one it is not easy to differentiate if it was an encoding event at the point where the general message is logged. This is why I add this debug message here.

}
return
}
}
2 changes: 2 additions & 0 deletions libbeat/outputs/redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ func serializeEvents(
serializedEvent, err := codec.Encode(index, &d.Content)
if err != nil {
logp.Err("Encoding event failed with error: %v", err)
logp.Debug("redis", "Failed event: %v", d.Content)
goto failLoop
}

Expand All @@ -329,6 +330,7 @@ failLoop:
serializedEvent, err := codec.Encode(index, &d.Content)
if err != nil {
logp.Err("Encoding event failed with error: %v", err)
logp.Debug("redis", "Failed event: %v", d.Content)
i++
continue
}
Expand Down