Skip to content

Commit

Permalink
libbeat/processors/cache: add logging for file read/write (elastic#38052
Browse files Browse the repository at this point in the history
)
  • Loading branch information
efd6 authored Feb 19, 2024
1 parent ac74059 commit b9a75c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ Setting environmental variable ELASTIC_NETINFO:false in Elastic Agent pod will d
- Add support for PEM-based Okta auth in CEL. {pull}37813[37813]
- Add ETW input. {pull}36915[36915]
- Update CEL mito extensions to v1.9.0 to add keys/values helper. {pull}37971[37971]
- Add logging for cache processor file reads and writes. {pull}38052[38052]

*Auditbeat*

Expand Down
5 changes: 5 additions & 0 deletions libbeat/processors/cache/file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ func (c *fileStore) readState() {
// through all the elements. If any survive the filter, we
// were alive, otherwise delete the file.

c.log.Infow("reading state from file", "id", c.id, "path", c.path)
dec := json.NewDecoder(f)
for {
var e CacheEntry
Expand All @@ -209,6 +210,7 @@ func (c *fileStore) readState() {
heap.Push(&c.expiries, &e)
}

c.log.Infow("got state from file", "id", c.id, "entries", len(c.cache))
if len(c.cache) != 0 {
return
}
Expand Down Expand Up @@ -243,6 +245,7 @@ func (c *fileStore) writeState(final bool) {
if !c.dirty {
return
}
c.log.Infow("write state to file", "id", c.id, "path", c.path)
if len(c.cache) == 0 && final {
err := os.Remove(c.path)
if err != nil {
Expand Down Expand Up @@ -278,6 +281,7 @@ func (c *fileStore) writeState(final bool) {
if err != nil {
c.log.Errorw("failed to finalize writing state", "error", err)
}
c.log.Infow("write state to file sync and replace succeeded", "id", c.id, "path", c.path)
}()

enc := json.NewEncoder(f)
Expand All @@ -297,4 +301,5 @@ func (c *fileStore) writeState(final bool) {
}
// Only mark as not dirty if we succeeded in the write.
c.dirty = false
c.log.Infow("write state to file succeeded", "id", c.id, "path", c.path)
}

0 comments on commit b9a75c9

Please sign in to comment.