Skip to content

Commit

Permalink
chore: Clean up lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jaqx0r committed Jul 17, 2024
1 parent 97cf805 commit ee521cd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 78 deletions.
68 changes: 0 additions & 68 deletions internal/tailer/logstream/decode.go

This file was deleted.

6 changes: 3 additions & 3 deletions internal/tailer/logstream/filestream.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (fs *fileStream) stream(ctx context.Context, wg *sync.WaitGroup, waker wake
}
}

if err != nil && err != io.EOF {
if err != nil && !errors.Is(err, io.EOF) {
logErrors.Add(fs.sourcename, 1)
// TODO: This could be generalised to check for any retryable
// errors, and end on unretriables; e.g. ESTALE looks
Expand All @@ -129,7 +129,7 @@ func (fs *fileStream) stream(ctx context.Context, wg *sync.WaitGroup, waker wake
}

// If we have read no bytes and are at EOF, check for truncation and rotation.
if err == io.EOF && count == 0 {
if errors.Is(err, io.EOF) && count == 0 {
glog.V(2).Infof("stream(%s): eof an no bytes", fs.sourcename)
// Both rotation and truncation need to stat, so check for
// rotation first. It is assumed that rotation is the more
Expand Down Expand Up @@ -193,7 +193,7 @@ func (fs *fileStream) stream(ctx context.Context, wg *sync.WaitGroup, waker wake
Sleep:
// If we get here it's because we've stalled. First test to see if it's
// time to exit.
if err == io.EOF {
if errors.Is(err, io.EOF) {
if oneShot == OneShotEnabled {
// Exit now, because oneShot means read only to EOF.
glog.V(2).Infof("stream(%s): EOF in one shot mode, exiting", fs.sourcename)
Expand Down
12 changes: 6 additions & 6 deletions internal/tailer/logstream/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ package logstream
import (
"bytes"
"context"
"expvar"
"io"
"time"

"github.com/google/mtail/internal/logline"
)

// logLines counts the number of lines read per log file.
// var logLines = expvar.NewMap("log_lines_total")
var logLines = expvar.NewMap("log_lines_total")

// LineReader reads lines from input and sends lines through the channel
type LineReader struct {
Expand All @@ -26,7 +27,6 @@ type LineReader struct {
size int
buf []byte
off int // tracks the start of the next line in buf
end int // tracks the end of the next line in buf
}

// NewLineReader creates a new LineReader
Expand All @@ -44,9 +44,7 @@ func NewLineReader(sourcename string, lines chan<- *logline.LogLine, f io.Reader
// ReadAndSend reads bytes from f, attempts to find line endings in the bytes read, and sends them to the lines channel. It manages the read buffer size to make sure we can always read size bytes.
func (lr *LineReader) ReadAndSend(ctx context.Context) (count int, err error) {
if cap(lr.buf)-len(lr.buf) < lr.size {
len := len(lr.buf)
lr.buf = append(make([]byte, 0, len+lr.size), lr.buf...)

lr.buf = append(make([]byte, 0, len(lr.buf)+lr.size), lr.buf...)
}
count, err = lr.f.Read(lr.buf[len(lr.buf):cap(lr.buf)])
if lr.staleTimer != nil {
Expand All @@ -55,7 +53,9 @@ func (lr *LineReader) ReadAndSend(ctx context.Context) (count int, err error) {
lr.buf = lr.buf[:len(lr.buf)+count] // reslice to set len
if count > 0 {
lr.staleTimer = time.AfterFunc(time.Hour*24, lr.cancel)
for ok := true; ok; ok = lr.send(ctx) {
ok := true
for ok {
ok = lr.send(ctx)
}
// reslice to drop earlier bytes
lr.buf = lr.buf[lr.off:len(lr.buf)]
Expand Down
3 changes: 2 additions & 1 deletion internal/tailer/logstream/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package logstream
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"testing"
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestReadAndSendSplitBytes(t *testing.T) {
}

count, err := lr.ReadAndSend(context.Background())
if err != nil && err != io.EOF {
if err != nil && !errors.Is(err, io.EOF) {
t.Errorf("ReadAndSend(%v) -> %v", origBytes[chunkOffset:chunkEnd], err)
}
byteCount += count
Expand Down

0 comments on commit ee521cd

Please sign in to comment.