From 55ed4faf54b6cd8280f1bac4a4f787346034e6c2 Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Mon, 19 Feb 2024 17:06:51 +1030 Subject: [PATCH] libbeat/processors/cache: add logging for file read/write --- CHANGELOG.next.asciidoc | 1 + libbeat/processors/cache/file_store.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 5f64d98eb96f..1af61048fdce 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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}[] *Auditbeat* diff --git a/libbeat/processors/cache/file_store.go b/libbeat/processors/cache/file_store.go index 1ab4ab21ae4e..d3820600acff 100644 --- a/libbeat/processors/cache/file_store.go +++ b/libbeat/processors/cache/file_store.go @@ -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 @@ -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 } @@ -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 { @@ -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) @@ -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) }