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

libbeat/processors/cache: add logging for file read/write #38052

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,13 +185,14 @@
// 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
err = dec.Decode(&e)
if err != nil {
if err != io.EOF {

Check failure on line 194 in libbeat/processors/cache/file_store.go

View workflow job for this annotation

GitHub Actions / lint (windows)

comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
switch err := err.(type) {

Check failure on line 195 in libbeat/processors/cache/file_store.go

View workflow job for this annotation

GitHub Actions / lint (windows)

type switch on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
case *json.SyntaxError:
c.log.Errorw("failed to read state element", "error", err, "path", c.path, "offset", err.Offset)
default:
Expand All @@ -209,6 +210,7 @@
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 @@
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 @@
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 @@
}
// 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)
}
Loading