Skip to content

Commit 71e46e3

Browse files
sophiewaldmanJoaoBraveCoding
authored andcommitted
chore(linter): Fix issues flagged by updated golangci-lint version (grafana#19206)
1 parent b4a6bf9 commit 71e46e3

File tree

211 files changed

+417
-427
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+417
-427
lines changed

clients/cmd/docker-driver/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func Test_parsePipeline(t *testing.T) {
8787
}
8888
defer os.Remove(f.Name())
8989

90-
_, err = f.Write([]byte(fmt.Sprintf("pipeline_stages:\n%s", pipelineString)))
90+
_, err = fmt.Fprintf(f, "pipeline_stages:\n%s", pipelineString)
9191
if err != nil {
9292
t.Fatal(err)
9393
}

clients/cmd/promtail/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,11 @@ func main() {
103103
}
104104

105105
// Init the logger which will honor the log level set in cfg.Server
106-
if reflect.DeepEqual(&config.Config.ServerConfig.Config.LogLevel, &log.Level{}) {
106+
if reflect.DeepEqual(&config.ServerConfig.LogLevel, &log.Level{}) {
107107
fmt.Println("Invalid log level")
108108
exit(1)
109109
}
110-
serverCfg := &config.Config.ServerConfig.Config
110+
serverCfg := &config.ServerConfig.Config
111111
serverCfg.Log = util_log.InitLogger(serverCfg, prometheus.DefaultRegisterer, false)
112112

113113
// Use Stderr instead of files for the klog.
@@ -119,7 +119,7 @@ func main() {
119119

120120
// Set the global debug variable in the stages package which is used to conditionally log
121121
// debug messages which otherwise cause huge allocations processing log lines for log messages never printed
122-
if config.Config.ServerConfig.Config.LogLevel.String() == "debug" {
122+
if config.ServerConfig.LogLevel.String() == "debug" {
123123
stages.Debug = true
124124
}
125125

clients/pkg/logentry/stages/decolorize.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ func (m *decolorizeStage) Run(in chan Entry) chan Entry {
1919
for e := range in {
2020
decolorizedLine, _ := decolorizer.Process(
2121
e.Timestamp.Unix(),
22-
[]byte(e.Entry.Line),
22+
[]byte(e.Line),
2323
nil,
2424
)
25-
e.Entry.Line = string(decolorizedLine)
25+
e.Line = string(decolorizedLine)
2626
out <- e
2727
}
2828
}()

clients/pkg/logentry/stages/eventlogmessage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func SanitizeFullLabelName(input string) string {
155155
}
156156
var validSb strings.Builder
157157
for i, b := range input {
158-
if !((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_' || (b >= '0' && b <= '9' && i > 0)) {
158+
if (b < 'a' || b > 'z') && (b < 'A' || b > 'Z') && b != '_' && (b < '0' || b > '9' || i <= 0) {
159159
validSb.WriteRune('_')
160160
} else {
161161
validSb.WriteRune(b)

clients/pkg/logentry/stages/geoip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (g *geoIPStage) Run(in chan Entry) chan Entry {
111111
defer close(out)
112112
defer g.close()
113113
for e := range in {
114-
g.process(e.Labels, e.Extracted, &e.Timestamp, &e.Entry.Line)
114+
g.process(e.Labels, e.Extracted, &e.Timestamp, &e.Line)
115115
out <- e
116116
}
117117
}()

clients/pkg/logentry/stages/labels_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestLabelsPipelineWithMissingKey_Labels(t *testing.T) {
6969

7070
_ = processEntries(pl, newEntry(nil, nil, testLabelsLogLineWithMissingKey, time.Now()))
7171

72-
expectedLog := "level=debug msg=\"failed to convert extracted label value to string\" err=\"Can't convert <nil> to string\" type=null"
72+
expectedLog := "level=debug msg=\"failed to convert extracted label value to string\" err=\"can't convert <nil> to string\" type=null"
7373
if !(strings.Contains(buf.String(), expectedLog)) {
7474
t.Errorf("\nexpected: %s\n+actual: %s", expectedLog, buf.String())
7575
}

clients/pkg/logentry/stages/limit_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,12 @@ func TestLimitByLabelPipeline(t *testing.T) {
124124
var hasTotal, hasByLabel bool
125125
mfs, _ := registry.Gather()
126126
for _, mf := range mfs {
127-
if *mf.Name == "logentry_dropped_lines_total" {
127+
switch *mf.Name {
128+
case "logentry_dropped_lines_total":
128129
hasTotal = true
129130
assert.Len(t, mf.Metric, 1)
130131
assert.Equal(t, 8, int(mf.Metric[0].Counter.GetValue()))
131-
} else if *mf.Name == "logentry_dropped_lines_by_label_total" {
132+
case "logentry_dropped_lines_by_label_total":
132133
hasByLabel = true
133134
assert.Len(t, mf.Metric, 2)
134135
assert.Equal(t, 4, int(mf.Metric[0].Counter.GetValue()))

clients/pkg/logentry/stages/multiline.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ func (m *multilineStage) flush(out chan Entry, s *multilineState) {
212212
collapsed := Entry{
213213
Extracted: extracted,
214214
Entry: api.Entry{
215-
Labels: s.startLineEntry.Entry.Labels.Clone(),
215+
Labels: s.startLineEntry.Labels.Clone(),
216216
Entry: logproto.Entry{
217-
Timestamp: s.startLineEntry.Entry.Entry.Timestamp,
217+
Timestamp: s.startLineEntry.Timestamp,
218218
Line: s.buffer.String(),
219219
},
220220
},

clients/pkg/logentry/stages/output_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestPipelineWithMissingKey_Output(t *testing.T) {
6363
}
6464
Debug = true
6565
_ = processEntries(pl, newEntry(nil, nil, testOutputLogLineWithMissingKey, time.Now()))
66-
expectedLog := "level=debug msg=\"extracted output could not be converted to a string\" err=\"Can't convert <nil> to string\" type=null"
66+
expectedLog := "level=debug msg=\"extracted output could not be converted to a string\" err=\"can't convert <nil> to string\" type=null"
6767
if !(strings.Contains(buf.String(), expectedLog)) {
6868
t.Errorf("\nexpected: %s\n+actual: %s", expectedLog, buf.String())
6969
}

clients/pkg/logentry/stages/pack_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func TestPackPipeline(t *testing.T) {
8383

8484
// Unmarshal the packed object and validate line1
8585
w := &Packed{}
86-
assert.NoError(t, json.Unmarshal([]byte(out1.Entry.Entry.Line), w))
86+
assert.NoError(t, json.Unmarshal([]byte(out1.Line), w))
8787
expectedPackedLabels := map[string]string{
8888
"pod": "foo-xsfs3",
8989
"container": "foo",
@@ -93,7 +93,7 @@ func TestPackPipeline(t *testing.T) {
9393

9494
// Validate line 2
9595
w = &Packed{}
96-
assert.NoError(t, json.Unmarshal([]byte(out2.Entry.Entry.Line), w))
96+
assert.NoError(t, json.Unmarshal([]byte(out2.Line), w))
9797
expectedPackedLabels = map[string]string{
9898
"pod": "foo-vvsdded",
9999
"container": "bar",

0 commit comments

Comments
 (0)