Skip to content

Commit 9c29ae4

Browse files
committed
fix lints
1 parent 5f9a12a commit 9c29ae4

File tree

9 files changed

+24
-25
lines changed

9 files changed

+24
-25
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
linters:
22
enable:
33
- asciicheck
4-
- deadcode
54
- depguard
65
- errcheck
76
- errorlint
@@ -17,6 +16,7 @@ linters:
1716
- tparallel
1817
- unconvert
1918
- unparam
19+
- unused
2020
- whitespace
2121
output:
2222
uniq-by-line: false

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cpanato/github_actions_exporter
33
go 1.19
44

55
require (
6-
github.com/go-kit/kit v0.12.0
6+
github.com/go-kit/log v0.2.0
77
github.com/google/go-github/v47 v47.1.0
88
github.com/prometheus/client_golang v1.13.0
99
github.com/prometheus/common v0.37.0
@@ -18,7 +18,6 @@ require (
1818
github.com/beorn7/perks v1.0.1 // indirect
1919
github.com/cespare/xxhash/v2 v2.1.2 // indirect
2020
github.com/davecgh/go-spew v1.1.1 // indirect
21-
github.com/go-kit/log v0.2.0 // indirect
2221
github.com/go-logfmt/logfmt v0.5.1 // indirect
2322
github.com/golang/protobuf v1.5.2 // indirect
2423
github.com/google/go-querystring v1.1.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
6565
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
6666
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
6767
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
68-
github.com/go-kit/kit v0.12.0 h1:e4o3o3IsBfAKQh5Qbbiqyfu97Ku7jrO/JbohvztANh4=
69-
github.com/go-kit/kit v0.12.0/go.mod h1:lHd+EkCZPIwYItmGDDRdhinkzX2A1sj+M9biaEaizzs=
7068
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
7169
github.com/go-kit/log v0.2.0 h1:7i2K3eKTos3Vc0enKCfnVcgHh2olr/MyfboYq7cAcFw=
7270
github.com/go-kit/log v0.2.0/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0=

internal/server/billing_metrics_exporter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"errors"
66
"time"
77

8-
"github.com/go-kit/kit/log"
9-
"github.com/go-kit/kit/log/level"
8+
"github.com/go-kit/log"
9+
"github.com/go-kit/log/level"
1010
"github.com/google/go-github/v47/github"
1111
"golang.org/x/oauth2"
1212
)

internal/server/server.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"net"
88
"net/http"
99
"strings"
10+
"time"
1011

11-
"github.com/go-kit/kit/log"
12-
"github.com/go-kit/kit/log/level"
12+
"github.com/go-kit/log"
13+
"github.com/go-kit/log/level"
1314
"github.com/prometheus/client_golang/prometheus/promhttp"
1415
"github.com/prometheus/common/version"
1516
)
@@ -39,7 +40,8 @@ func NewServer(logger log.Logger, opts Opts) *Server {
3940
mux := http.NewServeMux()
4041

4142
httpServer := &http.Server{
42-
Handler: mux,
43+
Handler: mux,
44+
ReadHeaderTimeout: 10 * time.Second,
4345
}
4446

4547
billingExporter := NewBillingMetricsExporter(logger, opts)

internal/server/server_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ package server_test
22

33
import (
44
"context"
5-
"io/ioutil"
5+
"io"
66
"net/http"
77
"os"
88
"testing"
99
"time"
1010

1111
"github.com/cpanato/github_actions_exporter/internal/server"
12-
"github.com/go-kit/kit/log"
12+
"github.com/go-kit/log"
1313
"github.com/google/go-github/v47/github"
1414
"github.com/stretchr/testify/assert"
1515
"github.com/stretchr/testify/require"
@@ -42,7 +42,7 @@ func Test_Server_MetricsRouteWithNoMetrics(t *testing.T) {
4242

4343
assert.Equal(t, 200, res.StatusCode)
4444

45-
payload, err := ioutil.ReadAll(res.Body)
45+
payload, err := io.ReadAll(res.Body)
4646
require.NoError(t, err)
4747
assert.NotNil(t, payload)
4848
}
@@ -105,7 +105,7 @@ func Test_Server_MetricsRouteAfterWorkflowJob(t *testing.T) {
105105

106106
assert.Equal(t, 200, metricsRes.StatusCode)
107107

108-
payload, err := ioutil.ReadAll(metricsRes.Body)
108+
payload, err := io.ReadAll(metricsRes.Body)
109109
require.NoError(t, err)
110110
assert.Contains(t, string(payload), `workflow_job_duration_seconds_bucket{org="someone",repo="some-repo",runner_group="runner-group",state="in_progress",le="10.541350399999995"} 1`)
111111
assert.Contains(t, string(payload), `workflow_job_duration_seconds_total{conclusion="success",org="someone",repo="some-repo",runner_group="runner-group",status="completed"} 10`)

internal/server/workflow_metrics_exporter.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ import (
77
"encoding/hex"
88
"errors"
99
"fmt"
10-
"io/ioutil"
10+
"io"
1111
"math"
1212
"net/http"
1313
"strings"
1414

1515
"github.com/cpanato/github_actions_exporter/model"
16-
"github.com/go-kit/kit/log"
17-
"github.com/go-kit/kit/log/level"
16+
"github.com/go-kit/log"
17+
"github.com/go-kit/log/level"
1818
"github.com/google/go-github/v47/github"
1919
)
2020

@@ -36,7 +36,7 @@ func NewWorkflowMetricsExporter(logger log.Logger, opts Opts) *WorkflowMetricsEx
3636

3737
// handleGHWebHook responds to POST /gh_event, when receive a event from GitHub.
3838
func (c *WorkflowMetricsExporter) HandleGHWebHook(w http.ResponseWriter, r *http.Request) {
39-
buf, err := ioutil.ReadAll(r.Body)
39+
buf, err := io.ReadAll(r.Body)
4040
if err != nil {
4141
_ = level.Error(c.Logger).Log("msg", "error reading body: %v", err)
4242
w.WriteHeader(http.StatusInternalServerError)
@@ -63,7 +63,7 @@ func (c *WorkflowMetricsExporter) HandleGHWebHook(w http.ResponseWriter, r *http
6363
eventType := r.Header.Get("X-GitHub-Event")
6464
switch eventType {
6565
case "ping":
66-
pingEvent := model.PingEventFromJSON(ioutil.NopCloser(bytes.NewBuffer(buf)))
66+
pingEvent := model.PingEventFromJSON(io.NopCloser(bytes.NewBuffer(buf)))
6767
if pingEvent == nil {
6868
_ = level.Info(c.Logger).Log("msg", "ping event", "hookID", pingEvent.GetHookID())
6969
w.WriteHeader(http.StatusBadRequest)
@@ -73,11 +73,11 @@ func (c *WorkflowMetricsExporter) HandleGHWebHook(w http.ResponseWriter, r *http
7373
_, _ = w.Write([]byte(`{"status": "honk"}`))
7474
return
7575
case "workflow_job":
76-
event := model.WorkflowJobEventFromJSON(ioutil.NopCloser(bytes.NewBuffer(buf)))
76+
event := model.WorkflowJobEventFromJSON(io.NopCloser(bytes.NewBuffer(buf)))
7777
_ = level.Info(c.Logger).Log("msg", "got workflow_job event", "org", event.GetRepo().GetOwner().GetLogin(), "repo", event.GetRepo().GetName(), "runId", event.GetWorkflowJob().GetRunID(), "action", event.GetAction())
7878
go c.CollectWorkflowJobEvent(event)
7979
case "workflow_run":
80-
event := model.WorkflowRunEventFromJSON(ioutil.NopCloser(bytes.NewBuffer(buf)))
80+
event := model.WorkflowRunEventFromJSON(io.NopCloser(bytes.NewBuffer(buf)))
8181
_ = level.Info(c.Logger).Log("msg", "got workflow_run event", "org", event.GetRepo().GetOwner().GetLogin(), "repo", event.GetRepo().GetName(), "workflow_name", event.GetWorkflow().GetName(), "runNumber", event.GetWorkflowRun().GetRunNumber(), "action", event.GetAction())
8282
go c.CollectWorkflowRunEvent(event)
8383
default:

internal/server/workflow_metrics_exporter_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"time"
1616

1717
"github.com/cpanato/github_actions_exporter/internal/server"
18-
"github.com/go-kit/kit/log"
18+
"github.com/go-kit/log"
1919
"github.com/google/go-github/v47/github"
2020
"github.com/stretchr/testify/assert"
2121
"github.com/stretchr/testify/require"
@@ -694,7 +694,7 @@ func (o *TestPrometheusObserver) assetWorkflowJobObservation(expected workflowJo
694694
}
695695
}
696696

697-
func (o *TestPrometheusObserver) assertWorkflowJobStatusCount(expected workflowJobStatusCount, timeout time.Duration) {
697+
func (o *TestPrometheusObserver) assertWorkflowJobStatusCount(expected workflowJobStatusCount, timeout time.Duration) { //nolint: unparam
698698
select {
699699
case <-time.After(timeout):
700700
o.t.Fatal("expected observation but none occurred")

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"syscall"
1010

1111
"github.com/cpanato/github_actions_exporter/internal/server"
12-
"github.com/go-kit/kit/log/level"
12+
"github.com/go-kit/log/level"
1313
"github.com/prometheus/client_golang/prometheus"
1414
"github.com/prometheus/common/promlog"
1515
"github.com/prometheus/common/promlog/flag"
@@ -81,7 +81,7 @@ func main() {
8181

8282
func validateFlags(token string) error {
8383
if token == "" {
84-
return errors.New("Please configure the GitHub Webhook Token")
84+
return errors.New("please configure the GitHub Webhook Token")
8585
}
8686
return nil
8787
}

0 commit comments

Comments
 (0)