Skip to content

Commit

Permalink
Make file system metadata values strings (#36697)
Browse files Browse the repository at this point in the history
To better align with ECS and better store the values in Elasticsearch.
  • Loading branch information
rdner authored Sep 28, 2023
1 parent 017b589 commit 8dcf23c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]

*Filebeat*

- Switch types of `log.file.device`, `log.file.inode`, `log.file.idxhi`, `log.file.idxlo` and `log.file.vol` fields to strings to better align with ECS and integrations. {pull}36697[36697]

*Heartbeat*

Expand Down
5 changes: 3 additions & 2 deletions libbeat/reader/readfile/fs_metafields_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package readfile
import (
"fmt"
"os"
"strconv"

"github.com/elastic/beats/v7/libbeat/common/file"
"github.com/elastic/elastic-agent-libs/mapstr"
Expand All @@ -34,11 +35,11 @@ const (

func setFileSystemMetadata(fi os.FileInfo, fields mapstr.M) error {
osstate := file.GetOSState(fi)
_, err := fields.Put(deviceIDKey, osstate.Device)
_, err := fields.Put(deviceIDKey, strconv.FormatUint(osstate.Device, 10))
if err != nil {
return fmt.Errorf("failed to set %q: %w", deviceIDKey, err)
}
_, err = fields.Put(inodeKey, osstate.Inode)
_, err = fields.Put(inodeKey, osstate.InodeString())
if err != nil {
return fmt.Errorf("failed to set %q: %w", inodeKey, err)
}
Expand Down
7 changes: 4 additions & 3 deletions libbeat/reader/readfile/fs_metafields_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package readfile
import (
"fmt"
"os"
"strconv"

"github.com/elastic/beats/v7/libbeat/common/file"
"github.com/elastic/elastic-agent-libs/mapstr"
Expand All @@ -33,15 +34,15 @@ const (

func setFileSystemMetadata(fi os.FileInfo, fields mapstr.M) error {
osstate := file.GetOSState(fi)
_, err := fields.Put(idxhiKey, osstate.IdxHi)
_, err := fields.Put(idxhiKey, strconv.FormatUint(osstate.IdxHi, 10))
if err != nil {
return fmt.Errorf("failed to set %q: %w", idxhiKey, err)
}
_, err = fields.Put(idxloKey, osstate.IdxLo)
_, err = fields.Put(idxloKey, strconv.FormatUint(osstate.IdxLo, 10))
if err != nil {
return fmt.Errorf("failed to set %q: %w", idxloKey, err)
}
_, err = fields.Put(volKey, osstate.Vol)
_, err = fields.Put(volKey, strconv.FormatUint(osstate.Vol, 10))
if err != nil {
return fmt.Errorf("failed to set %q: %w", volKey, err)
}
Expand Down
4 changes: 2 additions & 2 deletions libbeat/reader/readfile/metafields_other_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ func checkFields(t *testing.T, expected, actual mapstr.M) {

dev, err := actual.GetValue(deviceIDKey)
require.NoError(t, err)
require.Equal(t, uint64(17), dev)
require.Equal(t, "17", dev)
err = actual.Delete(deviceIDKey)
require.NoError(t, err)

inode, err := actual.GetValue(inodeKey)
require.NoError(t, err)
require.Equal(t, uint64(999), inode)
require.Equal(t, "999", inode)
err = actual.Delete(inodeKey)
require.NoError(t, err)

Expand Down
6 changes: 3 additions & 3 deletions libbeat/reader/readfile/metafields_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ func checkFields(t *testing.T, expected, actual mapstr.M) {

idxhi, err := actual.GetValue(idxhiKey)
require.NoError(t, err)
require.Equal(t, uint64(100), idxhi)
require.Equal(t, "100", idxhi)
err = actual.Delete(idxhiKey)
require.NoError(t, err)

idxlo, err := actual.GetValue(idxloKey)
require.NoError(t, err)
require.Equal(t, uint64(200), idxlo)
require.Equal(t, "200", idxlo)
err = actual.Delete(idxloKey)
require.NoError(t, err)

vol, err := actual.GetValue(volKey)
require.NoError(t, err)
require.Equal(t, uint64(300), vol)
require.Equal(t, "300", vol)
err = actual.Delete(volKey)
require.NoError(t, err)

Expand Down

0 comments on commit 8dcf23c

Please sign in to comment.