Skip to content

Commit

Permalink
chore: fix lint and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMeier committed Feb 20, 2025
1 parent dff810e commit d918a13
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 15 deletions.
13 changes: 11 additions & 2 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ const (
)

type rsyslogExporter struct {
started bool
logfile *os.File
scanner *bufio.Scanner
pointStore
}
Expand Down Expand Up @@ -74,6 +72,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
return err
}
for _, p := range a.toPoints() {
// nolint:errcheck
re.set(p)
}

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

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

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

Expand All @@ -110,6 +112,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
return err
}
for _, p := range r.toPoints() {
// nolint:errcheck
re.set(p)
}
case rsyslogDynStat:
Expand All @@ -118,6 +121,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
return err
}
for _, p := range s.toPoints() {
// nolint:errcheck
re.set(p)
}
case rsyslogDynafileCache:
Expand All @@ -126,6 +130,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
return err
}
for _, p := range d.toPoints() {
// nolint:errcheck
re.set(p)
}
case rsyslogForward:
Expand All @@ -134,6 +139,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
return err
}
for _, p := range f.toPoints() {
// nolint:errcheck
re.set(p)
}
case rsyslogKubernetes:
Expand All @@ -142,6 +148,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
return err
}
for _, p := range k.toPoints() {
// nolint:errcheck
re.set(p)
}
case rsyslogOmkafka:
Expand All @@ -150,6 +157,7 @@ func (re *rsyslogExporter) handleStatLine(rawbuf []byte) error {
return err
}
for _, p := range o.toPoints() {
// nolint:errcheck
re.set(p)
}

Expand Down Expand Up @@ -214,6 +222,7 @@ func (re *rsyslogExporter) run(silent bool) {
Type: counter,
Description: "Counts errors during stats line handling",
}
// nolint:errcheck
re.set(errorPoint)
for re.scanner.Scan() {
err := re.handleStatLine(re.scanner.Bytes())
Expand Down
3 changes: 3 additions & 0 deletions exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

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

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

// nolint:errcheck
exporter.handleStatLine(line)

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

exporter := newRsyslogExporter()
// nolint:errcheck
exporter.handleStatLine(unknownLog)

if want, got := 0, len(exporter.keys()); want != got {
Expand Down
8 changes: 4 additions & 4 deletions input_imudp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ var (
inputIMUDPLog = []byte(`{ "name": "test_input_imudp", "origin": "imudp", "called.recvmmsg":1000, "called.recvmsg":2000, "msgs.received":500}`)
)

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

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion inputs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var (
inputLog = []byte(`{"name":"test_input", "origin":"imuxsock", "submitted":1000}`)
)

func TestgetInput(t *testing.T) {
func TestGetInput(t *testing.T) {
logType := getStatType(inputLog)
if logType != rsyslogInput {
t.Errorf("detected pstat type should be %d but is %d", rsyslogInput, logType)
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func main() {
prometheus.MustRegister(exporter)
http.Handle(*metricPath, promhttp.Handler())
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// nolint:errcheck
w.Write([]byte(`<html>
<head><title>Rsyslog exporter</title></head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions point_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestCounter(t *testing.T) {
t.Errorf("want '%v', got '%v'", want, got)
}

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

wanted := `Desc{fqName: "rsyslog_my gauge", help: "", constLabels: {}, variableLabels: []}`
wanted := `Desc{fqName: "rsyslog_my gauge", help: "", constLabels: {}, variableLabels: {}}`
if want, got := wanted, p1.promDescription().String(); want != got {
t.Errorf("want '%s', got '%s'", want, got)
}
Expand Down
6 changes: 0 additions & 6 deletions queues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ func TestQueueToPoints(t *testing.T) {
t.Errorf("want '%s', got '%s'", want, got)
}

if want, got := int64(10), point.Value; want != got {
}

if want, got := gauge, point.Type; want != got {
}

if want, got := "main Q", point.LabelValue; want != got {
t.Errorf("wanted '%s', got '%s'", want, got)
}
Expand Down

0 comments on commit d918a13

Please sign in to comment.