Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
efd6 committed Sep 28, 2023
1 parent e0327b6 commit 35de580
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion libbeat/processors/cache/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type memConfig struct {

type fileConfig struct {
ID string `config:"id"`
WriteOutEvery time.Duration `config:"write_frequency"`
WriteOutEvery time.Duration `config:"write_interval"`
}

func (cfg *storeConfig) Validate() error {
Expand Down
2 changes: 1 addition & 1 deletion libbeat/processors/cache/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ put:
backend:
file:
id: aidmaster
write_frequency: 15m
write_interval: 15m
put:
ttl: 168h
key_field: crowdstrike.aid
Expand Down
14 changes: 12 additions & 2 deletions libbeat/processors/cache/file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ func (c *fileStore) readState() {
err = dec.Decode(&e)
if err != nil {
if err != io.EOF {
c.log.Errorw("failed to read state element", "error", err)
switch err := err.(type) {
case *json.SyntaxError:
c.log.Errorw("failed to read state element", "error", err, "path", c.path, "offset", err.Offset)
default:
c.log.Errorw("failed to read state element", "error", err, "path", c.path)
}
}
break
}
Expand Down Expand Up @@ -219,7 +224,7 @@ func (c *fileStore) writeState(final bool) {
}
return
}
f, err := os.CreateTemp("", "")
f, err := os.CreateTemp(filepath.Dir(c.path), "")
if err != nil {
c.log.Errorw("failed to open file to write state", "error", err)
return
Expand All @@ -232,6 +237,11 @@ func (c *fileStore) writeState(final bool) {
}
tmp := f.Name()
defer func() {
err = f.Sync()
if err != nil {
c.log.Errorw("failed to sync file after writing state", "error", err)
return
}
err = f.Close()
if err != nil {
c.log.Errorw("failed to close file after writing state", "error", err)
Expand Down

0 comments on commit 35de580

Please sign in to comment.