-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add close_removed and close_renamed, deprecate force_close_files #1909
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package harvester | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestForceCloseFiles(t *testing.T) { | ||
|
||
config := defaultConfig | ||
assert.False(t, config.ForceCloseFiles) | ||
assert.False(t, config.CloseRemoved) | ||
assert.False(t, config.CloseRenamed) | ||
|
||
config.ForceCloseFiles = true | ||
config.Validate() | ||
|
||
assert.True(t, config.ForceCloseFiles) | ||
assert.True(t, config.CloseRemoved) | ||
assert.True(t, config.CloseRenamed) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,8 @@ import ( | |
|
||
var ( | ||
ErrFileTruncate = errors.New("detected file being truncated") | ||
ErrForceClose = errors.New("file must be closed") | ||
ErrRenamed = errors.New("file was renamed") | ||
ErrRemoved = errors.New("file was removed") | ||
ErrInactive = errors.New("file inactive") | ||
) | ||
|
||
|
@@ -27,11 +28,12 @@ type logFileReader struct { | |
} | ||
|
||
type LogFileReaderConfig struct { | ||
ForceClose bool | ||
CloseOlder time.Duration | ||
BackoffDuration time.Duration | ||
MaxBackoffDuration time.Duration | ||
BackoffFactor int | ||
CloseRenamed bool | ||
CloseRemoved bool | ||
} | ||
|
||
func NewLogFileReader( | ||
|
@@ -72,8 +74,9 @@ func (r *logFileReader) Read(buf []byte) (int, error) { | |
r.offset += int64(n) | ||
r.lastTimeRead = time.Now() | ||
} | ||
|
||
// reset backoff | ||
if err == nil { | ||
// reset backoff | ||
r.backoff = r.config.BackoffDuration | ||
return n, nil | ||
} | ||
|
@@ -113,16 +116,20 @@ func (r *logFileReader) Read(buf []byte) (int, error) { | |
return n, ErrInactive | ||
} | ||
|
||
if r.config.ForceClose { | ||
// Check if the file name exists (see #93) | ||
if r.config.CloseRenamed { | ||
// Check if the file can still be found under the same path | ||
if !file.IsSameFile(r.fs.Name(), info) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep the code comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't it be: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, changed it again to: |
||
return n, ErrRenamed | ||
} | ||
} | ||
|
||
if r.config.CloseRemoved { | ||
// Check if the file name exists. See https://github.com/elastic/filebeat/issues/93 | ||
_, statErr := os.Stat(r.fs.Name()) | ||
|
||
// Error means file does not exist. If no error, check if same file. If | ||
// not close as rotated. | ||
if statErr != nil || !file.IsSameFile(r.fs.Name(), info) { | ||
logp.Info("Force close file: %s; error: %s", r.fs.Name(), statErr) | ||
// Return directly on windows -> file is closing | ||
return n, ErrForceClose | ||
// Error means file does not exist. | ||
if statErr != nil { | ||
return n, ErrRemoved | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still in alpha, let's remove 'ForceCloseFiles' then. Don't treat config as deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@urso I want to make the migration to 5.0 as seamless as possible. That is why I would prefer to keep this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we want to add a 'deprecated' option to go-ucfg, which will print a warning when option is used.
We can find deprecated options in code by grepping for
config:.*deprecated
. Maybe even with version like:config:",deprecated(5.0)"
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be great TBH. Lets do this as soon as support for this is in ucfg (not a priority).