Skip to content

Commit

Permalink
Change hpcloud tailer library to poll mode to workaround bugs in the …
Browse files Browse the repository at this point in the history
…event driven code within the library

Had to rework tests with some waits for messages because polling is slower
There are several longer sleeps in the promtail_test which are not ideal and have been marked with FIXME to remove once we have a better solution
  • Loading branch information
slim-bean committed Mar 29, 2019
1 parent 16e63cf commit c994823
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/promtail/promtail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ func fileRoll(t *testing.T, filename string, prefix string) int {
}
time.Sleep(1 * time.Millisecond)
}

//FIXME this is a hack to make sure the hpcloud tail polling implementation reads all lines before we roll the file
time.Sleep(300 * time.Millisecond)

if err = os.Rename(filename, filename+".1"); err != nil {
t.Fatal("Failed to rename file for test: ", err)
}
Expand All @@ -195,6 +199,9 @@ func fileRoll(t *testing.T, filename string, prefix string) int {
time.Sleep(1 * time.Millisecond)
}

//FIXME this is a hack to make sure the hpcloud tail polling implementation reads all lines before we roll the file
time.Sleep(300 * time.Millisecond)

return 200
}

Expand Down Expand Up @@ -224,6 +231,9 @@ func symlinkRoll(t *testing.T, testDir string, filename string, prefix string) i
time.Sleep(1 * time.Millisecond)
}

//FIXME this is a hack to make sure the hpcloud tail polling implementation reads all lines before we roll the file
time.Sleep(300 * time.Millisecond)

// Remove the link, make a new file, link to the new file.
if err := os.Remove(filename); err != nil {
t.Fatal(err)
Expand All @@ -245,6 +255,9 @@ func symlinkRoll(t *testing.T, testDir string, filename string, prefix string) i
time.Sleep(1 * time.Millisecond)
}

//FIXME this is a hack to make sure the hpcloud tail polling implementation reads all lines before we roll the file
time.Sleep(300 * time.Millisecond)

return 200

}
Expand Down
42 changes: 42 additions & 0 deletions pkg/promtail/targets/filetarget_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func TestLongPositionsSyncDelayStillSavesCorrectPosition(t *testing.T) {
time.Sleep(1 * time.Millisecond)
}

countdown := 10000
for len(client.messages) != 10 && countdown > 0 {
time.Sleep(1 * time.Millisecond)
countdown--
}

target.Stop()
ps.Stop()

Expand Down Expand Up @@ -155,6 +161,12 @@ func TestWatchEntireDirectory(t *testing.T) {
time.Sleep(1 * time.Millisecond)
}

countdown := 10000
for len(client.messages) != 10 && countdown > 0 {
time.Sleep(1 * time.Millisecond)
countdown--
}

target.Stop()
ps.Stop()

Expand Down Expand Up @@ -238,6 +250,12 @@ func TestFileRolls(t *testing.T) {
time.Sleep(1 * time.Millisecond)
}

countdown := 10000
for len(client.messages) != 10 && countdown > 0 {
time.Sleep(1 * time.Millisecond)
countdown--
}

// Rename the log file to something not in the pattern, then create a new file with the same name.
err = os.Rename(logFile, dirName+"/test.log.1")
if err != nil {
Expand All @@ -256,6 +274,12 @@ func TestFileRolls(t *testing.T) {
time.Sleep(1 * time.Millisecond)
}

countdown = 10000
for len(client.messages) != 20 && countdown > 0 {
time.Sleep(1 * time.Millisecond)
countdown--
}

target.Stop()
positions.Stop()

Expand Down Expand Up @@ -324,6 +348,12 @@ func TestResumesWhereLeftOff(t *testing.T) {
time.Sleep(1 * time.Millisecond)
}

countdown := 10000
for len(client.messages) != 10 && countdown > 0 {
time.Sleep(1 * time.Millisecond)
countdown--
}

target.Stop()
ps.Stop()

Expand Down Expand Up @@ -352,6 +382,12 @@ func TestResumesWhereLeftOff(t *testing.T) {
time.Sleep(1 * time.Millisecond)
}

countdown = 10000
for len(client.messages) != 20 && countdown > 0 {
time.Sleep(1 * time.Millisecond)
countdown--
}

target2.Stop()
ps2.Stop()

Expand Down Expand Up @@ -431,6 +467,12 @@ func TestGlobWithMultipleFiles(t *testing.T) {
time.Sleep(1 * time.Millisecond)
}

countdown := 10000
for len(client.messages) != 20 && countdown > 0 {
time.Sleep(1 * time.Millisecond)
countdown--
}

target.Stop()
ps.Stop()

Expand Down
1 change: 1 addition & 0 deletions pkg/promtail/targets/tailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func newTailer(logger log.Logger, handler api.EntryHandler, positions *positions

tail, err := tail.TailFile(filename, tail.Config{
Follow: true,
Poll: true,
ReOpen: reOpen,
Location: &tail.SeekInfo{
Offset: positions.Get(filename),
Expand Down

0 comments on commit c994823

Please sign in to comment.