Skip to content
Draft
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
10 changes: 0 additions & 10 deletions plugins/inputs/tail/tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ var (

type Tail struct {
Files []string `toml:"files"`
FromBeginning bool `toml:"from_beginning" deprecated:"1.34.0;1.40.0;use 'initial_read_offset' with value 'beginning' instead"`
InitialReadOffset string `toml:"initial_read_offset"`
Pipe bool `toml:"pipe"`
WatchMethod string `toml:"watch_method"`
Expand Down Expand Up @@ -82,15 +81,6 @@ func (t *Tail) SetParserFunc(fn telegraf.ParserFunc) {
}

func (t *Tail) Init() error {
// Backward compatibility setting
if t.InitialReadOffset == "" {
if t.FromBeginning {
t.InitialReadOffset = "beginning"
} else {
t.InitialReadOffset = "saved-or-end"
}
}

// Check settings
switch t.InitialReadOffset {
case "":
Expand Down
50 changes: 6 additions & 44 deletions plugins/inputs/tail/tail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,65 +996,27 @@ func TestInvalidInitialReadOffset(t *testing.T) {
require.ErrorContains(t, plugin.Init(), "invalid 'initial_read_offset' setting")
}

func TestSetInitialValueForInitialReadOffset(t *testing.T) {
tests := []struct {
name string
InitialReadOffset string
FromBeginning bool
expected string
}{
{
name: "Set InitialReadOffset to beginning when from_beginning set to true and initial_read_offset not set",
FromBeginning: true,
expected: "beginning",
},
{
name: "Set InitialReadOffset to saved-or-end when from_beginning set to false and initial_read_offset not set",
expected: "saved-or-end",
},
{
name: "Ignore from_beginning when initial_read_offset is set",
InitialReadOffset: "end",
expected: "end",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tt := newTail()
tt.FromBeginning = test.FromBeginning
tt.InitialReadOffset = test.InitialReadOffset
require.NoError(t, tt.Init())
require.Equal(t, test.expected, tt.InitialReadOffset)
})
}
}

func TestInitInitialReadOffset(t *testing.T) {
tests := []struct {
name string
InitialReadOffset string
FromBeginning bool
initialReadOffset string
expected string
}{
{
name: "Set InitialReadOffset to beginning when from_beginning set to true and initial_read_offset not set",
FromBeginning: true,
expected: "beginning",
name: "Default to saved-or-end when initial_read_offset not set",
expected: "saved-or-end",
},
{
name: "Ignore from_beginning when initial_read_offset is set",
FromBeginning: true,
InitialReadOffset: "end",
name: "Keep initial_read_offset when set",
initialReadOffset: "end",
expected: "end",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
tt := newTail()
tt.FromBeginning = test.FromBeginning
tt.InitialReadOffset = test.InitialReadOffset
tt.InitialReadOffset = test.initialReadOffset
require.NoError(t, tt.Init())
require.Equal(t, test.expected, tt.InitialReadOffset)
})
Expand Down
Loading