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

Early event encoding obscures raw event content in the event log #40509

Closed
cmacknz opened this issue Aug 13, 2024 · 1 comment · Fixed by #40512
Closed

Early event encoding obscures raw event content in the event log #40509

cmacknz opened this issue Aug 13, 2024 · 1 comment · Fixed by #40512
Assignees
Labels
Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@cmacknz
Copy link
Member

cmacknz commented Aug 13, 2024

Looking at recent data in the event log, we are logging the Go representation of the event which now includes the JSON encoded event as an opaque blob. For the log messages below, we need to handle the encoded part correctly in the event before logging it so we can actually see the contents. Currently the logs look like the example below where the problematic part is the EncodedEvent:(*elasticsearch.encodedEvent)(0xc003933700)} key.

{"log.level":"warn","@timestamp":"2024-08-13T14:04:46.708Z","log.logger":"elasticsearch","log.origin":{"function":"github.com/elastic/beats/v7/libbeat/outputs/elasticsearch.(*Client).applyItemStatus","file.name":"elasticsearch/client.go","file.line":489},"message":"Cannot index event publisher.Event{Content:beat.Event{Timestamp:time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC), Meta:null, Fields:null, Private:interface {}(nil), TimeSeries:false}, Flags:0x0, Cache:publisher.EventCache{m:mapstr.M(nil)}, EncodedEvent:(*elasticsearch.encodedEvent)(0xc003933700)} (status=400): 

We need to log the actual JSON content of the event instead of the reference to it. Possibly we need a type used for logging representing this field as json.RawMessage or similar.

We have tests that attempt to verify that the actual event data is in the event log and it did not catch this, possibly because the event content is also contained in the error message from Elasticsearch.

strData := string(data)
eventMsg := "not a number"
if !strings.Contains(strData, eventMsg) {
t.Errorf("expecting to find '%s' on '%s'", eventMsg, eventsLogFile)
t.Errorf("Contents:\n%s", strData)
t.FailNow()
}

@cmacknz cmacknz added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Aug 13, 2024
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants