daemon/logger: use strconv instead of fmt.Sprintf()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-10-05 16:25:53 +02:00
parent 7fbf321c2a
commit 533ecb44b1
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 16 additions and 16 deletions

View file

@ -1426,7 +1426,7 @@ func TestCollectBatchWithDuplicateTimestamps(t *testing.T) {
times := maximumLogEventsPerPut
timestamp := time.Now()
for i := 0; i < times; i++ {
line := fmt.Sprintf("%d", i)
line := strconv.Itoa(i)
if i%2 == 0 {
timestamp.Add(1 * time.Nanosecond)
}

View file

@ -4,7 +4,6 @@ import (
"bytes"
"compress/gzip"
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
@ -128,7 +127,7 @@ func BenchmarkJSONFileLoggerLog(b *testing.B) {
bytes.Repeat([]byte("a long string"), 100),
bytes.Repeat([]byte("a really long string"), 10000),
} {
b.Run(fmt.Sprintf("%d", len(data)), func(b *testing.B) {
b.Run(strconv.Itoa(len(data)), func(b *testing.B) {
testMsg := &logger.Message{
Line: data,
Source: "stderr",

View file

@ -3,10 +3,10 @@ package local
import (
"bytes"
"encoding/binary"
"fmt"
"io"
"os"
"path/filepath"
"strconv"
"testing"
"time"
@ -111,7 +111,7 @@ func BenchmarkLogWrite(b *testing.B) {
bytes.Repeat([]byte("a long string"), 100),
bytes.Repeat([]byte("a really long string"), 10000),
} {
b.Run(fmt.Sprintf("%d", len(data)), func(b *testing.B) {
b.Run(strconv.Itoa(len(data)), func(b *testing.B) {
entry := &logdriver.LogEntry{Line: data, Source: "stdout", TimeNano: t.UnixNano()}
b.SetBytes(int64(entry.Size() + encodeBinaryLen + encodeBinaryLen))
b.ResetTimer()

View file

@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"runtime"
"strconv"
"testing"
"time"
@ -827,7 +828,7 @@ func TestBatching(t *testing.T) {
}
for i := 0; i < defaultStreamChannelSize*4; i++ {
if err := loggerDriver.Log(&logger.Message{Line: []byte(fmt.Sprintf("%d", i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
if err := loggerDriver.Log(&logger.Message{Line: []byte(strconv.Itoa(i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
t.Fatal(err)
}
}
@ -845,7 +846,7 @@ func TestBatching(t *testing.T) {
if event, err := message.EventAsMap(); err != nil {
t.Fatal(err)
} else {
if event["line"] != fmt.Sprintf("%d", i) {
if event["line"] != strconv.Itoa(i) {
t.Fatalf("Unexpected event in message %v", event)
}
}
@ -887,7 +888,7 @@ func TestFrequency(t *testing.T) {
}
for i := 0; i < 10; i++ {
if err := loggerDriver.Log(&logger.Message{Line: []byte(fmt.Sprintf("%d", i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
if err := loggerDriver.Log(&logger.Message{Line: []byte(strconv.Itoa(i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
t.Fatal(err)
}
time.Sleep(15 * time.Millisecond)
@ -906,7 +907,7 @@ func TestFrequency(t *testing.T) {
if event, err := message.EventAsMap(); err != nil {
t.Fatal(err)
} else {
if event["line"] != fmt.Sprintf("%d", i) {
if event["line"] != strconv.Itoa(i) {
t.Fatalf("Unexpected event in message %v", event)
}
}
@ -958,7 +959,7 @@ func TestOneMessagePerRequest(t *testing.T) {
}
for i := 0; i < 10; i++ {
if err := loggerDriver.Log(&logger.Message{Line: []byte(fmt.Sprintf("%d", i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
if err := loggerDriver.Log(&logger.Message{Line: []byte(strconv.Itoa(i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
t.Fatal(err)
}
}
@ -976,7 +977,7 @@ func TestOneMessagePerRequest(t *testing.T) {
if event, err := message.EventAsMap(); err != nil {
t.Fatal(err)
} else {
if event["line"] != fmt.Sprintf("%d", i) {
if event["line"] != strconv.Itoa(i) {
t.Fatalf("Unexpected event in message %v", event)
}
}
@ -1050,7 +1051,7 @@ func TestSkipVerify(t *testing.T) {
}
for i := 0; i < defaultStreamChannelSize*2; i++ {
if err := loggerDriver.Log(&logger.Message{Line: []byte(fmt.Sprintf("%d", i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
if err := loggerDriver.Log(&logger.Message{Line: []byte(strconv.Itoa(i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
t.Fatal(err)
}
}
@ -1062,7 +1063,7 @@ func TestSkipVerify(t *testing.T) {
hec.simulateErr(false)
for i := defaultStreamChannelSize * 2; i < defaultStreamChannelSize*4; i++ {
if err := loggerDriver.Log(&logger.Message{Line: []byte(fmt.Sprintf("%d", i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
if err := loggerDriver.Log(&logger.Message{Line: []byte(strconv.Itoa(i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
t.Fatal(err)
}
}
@ -1080,7 +1081,7 @@ func TestSkipVerify(t *testing.T) {
if event, err := message.EventAsMap(); err != nil {
t.Fatal(err)
} else {
if event["line"] != fmt.Sprintf("%d", i) {
if event["line"] != strconv.Itoa(i) {
t.Fatalf("Unexpected event in message %v", event)
}
}
@ -1124,7 +1125,7 @@ func TestBufferMaximum(t *testing.T) {
}
for i := 0; i < 11; i++ {
if err := loggerDriver.Log(&logger.Message{Line: []byte(fmt.Sprintf("%d", i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
if err := loggerDriver.Log(&logger.Message{Line: []byte(strconv.Itoa(i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
t.Fatal(err)
}
}
@ -1193,7 +1194,7 @@ func TestServerAlwaysDown(t *testing.T) {
}
for i := 0; i < 5; i++ {
if err := loggerDriver.Log(&logger.Message{Line: []byte(fmt.Sprintf("%d", i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
if err := loggerDriver.Log(&logger.Message{Line: []byte(strconv.Itoa(i)), Source: "stdout", Timestamp: time.Now()}); err != nil {
t.Fatal(err)
}
}