Skip to content

Commit

Permalink
libbeat/reader: Fix messge conversion to beat.Event (#30057) (#30084)
Browse files Browse the repository at this point in the history
`Message.ToEvent` was not copying the `Message.Privage` field when
converting a Message to `beat.Event`. This commit fixes it.

Fixes: #30031
(cherry picked from commit 8cc07dd)

Co-authored-by: Tiago Queiroz <[email protected]>
  • Loading branch information
mergify[bot] and belimawr authored Jan 28, 2022
1 parent 8280e8f commit 5eb2a73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions libbeat/reader/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,6 @@ func (m *Message) ToEvent() beat.Event {
Timestamp: m.Ts,
Meta: m.Meta,
Fields: m.Fields,
Private: m.Private,
}
}
15 changes: 15 additions & 0 deletions libbeat/reader/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package reader

import (
"testing"
"time"

"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -55,6 +56,20 @@ func TestToEvent(t *testing.T) {
Message{Content: []byte("my message"), Fields: common.MapStr{"my_field": "my_value"}, Meta: common.MapStr{"meta": "id"}},
beat.Event{Fields: common.MapStr{"message": "my message", "my_field": "my_value"}, Meta: common.MapStr{"meta": "id"}},
},
"content, meta, message and private fields": {
Message{
Ts: time.Date(2022, 1, 9, 10, 42, 0, 0, time.UTC),
Content: []byte("my message"),
Meta: common.MapStr{"foo": "bar"},
Private: 42,
},
beat.Event{
Timestamp: time.Date(2022, 1, 9, 10, 42, 0, 0, time.UTC),
Fields: common.MapStr{"message": "my message"},
Meta: common.MapStr{"foo": "bar"},
Private: 42,
},
},
}

for name, test := range testCases {
Expand Down

0 comments on commit 5eb2a73

Please sign in to comment.