Skip to content

Commit

Permalink
fix(agent): Only rotate log on SIGHUP if needed (influxdata#12740)
Browse files Browse the repository at this point in the history
  • Loading branch information
powersj authored Mar 1, 2023
1 parent d4926c6 commit 3f3885a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion internal/rotate/file_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ func (w *FileWriter) Close() (err error) {
defer w.Unlock()

// Rotate before closing
if err = w.rotate(); err != nil {
if err := w.rotateIfNeeded(); err != nil {
return err
}

// Close the file if we did not rotate
if err := w.current.Close(); err != nil {
return err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/rotate/file_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func TestFileWriter_DeleteArchives(t *testing.T) {
}
}

func TestFileWriter_CloseRotates(t *testing.T) {
func TestFileWriter_CloseDoesNotRotate(t *testing.T) {
tempDir := t.TempDir()
maxSize := int64(9)
writer, err := NewFileWriter(filepath.Join(tempDir, "test.log"), 0, maxSize, -1)
Expand All @@ -138,5 +138,5 @@ func TestFileWriter_CloseRotates(t *testing.T) {

files, _ := os.ReadDir(tempDir)
assert.Equal(t, 1, len(files))
assert.Regexp(t, "^test\\.[^\\.]+\\.log$", files[0].Name())
assert.Regexp(t, "^test.log$", files[0].Name())
}

0 comments on commit 3f3885a

Please sign in to comment.