Skip to content

Commit 9d43e0c

Browse files
committed
chore: fix lint and tests
Signed-off-by: Christoph Maser <[email protected]>
1 parent dff810e commit 9d43e0c

7 files changed

+22
-15
lines changed

Diff for: exporter.go

+11-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ const (
4141
)
4242

4343
type rsyslogExporter struct {
44-
started bool
45-
logfile *os.File
4644
scanner *bufio.Scanner
4745
pointStore
4846
}
@@ -74,6 +72,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
7472
return err
7573
}
7674
for _, p := range a.toPoints() {
75+
// nolint:errcheck
7776
re.set(p)
7877
}
7978

@@ -83,6 +82,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
8382
return err
8483
}
8584
for _, p := range i.toPoints() {
85+
// nolint:errcheck
8686
re.set(p)
8787
}
8888

@@ -92,6 +92,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
9292
return err
9393
}
9494
for _, p := range u.toPoints() {
95+
// nolint:errcheck
9596
re.set(p)
9697
}
9798

@@ -101,6 +102,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
101102
return err
102103
}
103104
for _, p := range q.toPoints() {
105+
// nolint:errcheck
104106
re.set(p)
105107
}
106108

@@ -110,6 +112,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
110112
return err
111113
}
112114
for _, p := range r.toPoints() {
115+
// nolint:errcheck
113116
re.set(p)
114117
}
115118
case rsyslogDynStat:
@@ -118,6 +121,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
118121
return err
119122
}
120123
for _, p := range s.toPoints() {
124+
// nolint:errcheck
121125
re.set(p)
122126
}
123127
case rsyslogDynafileCache:
@@ -126,6 +130,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
126130
return err
127131
}
128132
for _, p := range d.toPoints() {
133+
// nolint:errcheck
129134
re.set(p)
130135
}
131136
case rsyslogForward:
@@ -134,6 +139,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
134139
return err
135140
}
136141
for _, p := range f.toPoints() {
142+
// nolint:errcheck
137143
re.set(p)
138144
}
139145
case rsyslogKubernetes:
@@ -142,6 +148,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
142148
return err
143149
}
144150
for _, p := range k.toPoints() {
151+
// nolint:errcheck
145152
re.set(p)
146153
}
147154
case rsyslogOmkafka:
@@ -150,6 +157,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
150157
return err
151158
}
152159
for _, p := range o.toPoints() {
160+
// nolint:errcheck
153161
re.set(p)
154162
}
155163

@@ -214,6 +222,7 @@ func (re *rsyslogExporter) run(silent bool) {
214222
Type: counter,
215223
Description: "Counts errors during stats line handling",
216224
}
225+
// nolint:errcheck
217226
re.set(errorPoint)
218227
for re.scanner.Scan() {
219228
err := re.handleStatLine(re.scanner.Bytes())

Diff for: exporter_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
func testHelper(t *testing.T, line []byte, testCase []*testUnit) {
2222
exporter := newRsyslogExporter()
23+
// nolint:errcheck
2324
exporter.handleStatLine(line)
2425

2526
for _, k := range exporter.keys() {
@@ -37,6 +38,7 @@ func testHelper(t *testing.T, line []byte, testCase []*testUnit) {
3738
}
3839
}
3940

41+
// nolint:errcheck
4042
exporter.handleStatLine(line)
4143

4244
for _, item := range testCase {
@@ -275,6 +277,7 @@ func TestHandleUnknown(t *testing.T) {
275277
unknownLog := []byte(`2017-08-30T08:10:04.786350+00:00 some-node.example.org rsyslogd-pstats: {"a":"b"}`)
276278

277279
exporter := newRsyslogExporter()
280+
// nolint:errcheck
278281
exporter.handleStatLine(unknownLog)
279282

280283
if want, got := 0, len(exporter.keys()); want != got {

Diff for: input_imudp_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ var (
1919
inputIMUDPLog = []byte(`{ "name": "test_input_imudp", "origin": "imudp", "called.recvmmsg":1000, "called.recvmsg":2000, "msgs.received":500}`)
2020
)
2121

22-
func TestgetInputIMUDP(t *testing.T) {
22+
func TestGetInputIMUDP(t *testing.T) {
2323
logType := getStatType(inputIMUDPLog)
2424
if logType != rsyslogInputIMDUP {
2525
t.Errorf("detected pstat type should be %d but is %d", rsyslogInputIMDUP, logType)
2626
}
2727

28-
pstat, err := newInputIMUDPFromJSON([]byte(inputLog))
28+
pstat, err := newInputIMUDPFromJSON([]byte(inputIMUDPLog))
2929
if err != nil {
3030
t.Fatalf("expected parsing input stat not to fail, got: %v", err)
3131
}
@@ -34,11 +34,11 @@ func TestgetInputIMUDP(t *testing.T) {
3434
t.Errorf("want '%s', got '%s'", want, got)
3535
}
3636

37-
if want, got := int64(1000), pstat.Recvmsg; want != got {
37+
if want, got := int64(1000), pstat.Recvmmsg; want != got {
3838
t.Errorf("want '%d', got '%d'", want, got)
3939
}
4040

41-
if want, got := int64(2000), pstat.Recvmmsg; want != got {
41+
if want, got := int64(2000), pstat.Recvmsg; want != got {
4242
t.Errorf("want '%d', got '%d'", want, got)
4343
}
4444

Diff for: inputs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919
inputLog = []byte(`{"name":"test_input", "origin":"imuxsock", "submitted":1000}`)
2020
)
2121

22-
func TestgetInput(t *testing.T) {
22+
func TestGetInput(t *testing.T) {
2323
logType := getStatType(inputLog)
2424
if logType != rsyslogInput {
2525
t.Errorf("detected pstat type should be %d but is %d", rsyslogInput, logType)

Diff for: main.go

+1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ func main() {
5757
prometheus.MustRegister(exporter)
5858
http.Handle(*metricPath, promhttp.Handler())
5959
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
60+
// nolint:errcheck
6061
w.Write([]byte(`<html>
6162
<head><title>Rsyslog exporter</title></head>
6263
<body>

Diff for: point_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestCounter(t *testing.T) {
3434
t.Errorf("want '%v', got '%v'", want, got)
3535
}
3636

37-
wanted := `Desc{fqName: "rsyslog_my counter", help: "", constLabels: {}, variableLabels: []}`
37+
wanted := `Desc{fqName: "rsyslog_my counter", help: "", constLabels: {}, variableLabels: {}}`
3838
if want, got := wanted, p1.promDescription().String(); want != got {
3939
t.Errorf("want '%s', got '%s'", want, got)
4040
}
@@ -55,7 +55,7 @@ func TestGauge(t *testing.T) {
5555
t.Errorf("want '%v', got '%v'", want, got)
5656
}
5757

58-
wanted := `Desc{fqName: "rsyslog_my gauge", help: "", constLabels: {}, variableLabels: []}`
58+
wanted := `Desc{fqName: "rsyslog_my gauge", help: "", constLabels: {}, variableLabels: {}}`
5959
if want, got := wanted, p1.promDescription().String(); want != got {
6060
t.Errorf("want '%s', got '%s'", want, got)
6161
}

Diff for: queues_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ func TestQueueToPoints(t *testing.T) {
7171
t.Errorf("want '%s', got '%s'", want, got)
7272
}
7373

74-
if want, got := int64(10), point.Value; want != got {
75-
}
76-
77-
if want, got := gauge, point.Type; want != got {
78-
}
79-
8074
if want, got := "main Q", point.LabelValue; want != got {
8175
t.Errorf("wanted '%s', got '%s'", want, got)
8276
}

0 commit comments

Comments
 (0)