Skip to content

Commit

Permalink
PMM-13054 refactor the for loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ademidoff committed Jun 17, 2024
1 parent d6c02e0 commit 1cf8a41
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions managed/services/supervisord/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ func (l *Logs) victoriaMetricsTargets(ctx context.Context) ([]byte, error) {
func readLog(name string, readLines int) ([]byte, time.Time, error) {
var (
m time.Time
res []byte
lineCount int
)
f, err := os.Open(name) //nolint:gosec
Expand All @@ -298,10 +297,10 @@ func readLog(name string, readLines int) ([]byte, time.Time, error) {
lineCount = readLines
}

res = make([]byte, 0)
res := []byte{}

reader := bufio.NewReader(f)
for lineCount >= 0 {
for {
b, err := reader.ReadBytes('\n')
if err == io.EOF {
// A special case when the last line does not end with a new line
Expand All @@ -321,6 +320,10 @@ func readLog(name string, readLines int) ([]byte, time.Time, error) {
// Do not decrease the counter for unlimited line count
lineCount--
}

if lineCount == 0 {
break
}
}

return res, m, nil
Expand Down

0 comments on commit 1cf8a41

Please sign in to comment.