Skip to content

Commit

Permalink
chore: update Go, CI, and linter
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Jan 24, 2024
1 parent 2fdca48 commit 842f413
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-cross.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
env:
GO_VERSION: stable
GOLANGCI_LINT_VERSION: v1.54.2
GOLANGCI_LINT_VERSION: v1.55.2

steps:

Expand All @@ -23,7 +23,7 @@ jobs:

# https://github.com/marketplace/actions/setup-go-environment
- name: Set up Go ${{ env.GO_VERSION }}
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}

Expand Down
9 changes: 8 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ linters:

issues:
exclude-use-default: false
max-per-linter: 0
max-issues-per-linter: 0
max-same-issues: 0
exclude:
- 'ST1000: at least one file in a package should have a package comment' # TODO(ldez) must be fixed
Expand All @@ -110,6 +110,7 @@ issues:
linters:
- funlen
- gosec
- goconst
- path: testutils/.+
linters:
- gosec
Expand All @@ -125,3 +126,9 @@ issues:
text: "Function 'serveWebSocket' has too many statements" # TODO(ldez) must be fixed
- path: utils/handler.go
text: "ifElseChain: rewrite if-else to switch statement" # TODO(ldez) must be fixed
- path: memmetrics/ratio_test.go
text: "float-compare: use assert\\.InEpsilon \\(or InDelta\\)" # TODO(ldez) must be fixed
- path: memmetrics/roundtrip_test.go
text: "float-compare: use assert\\.InEpsilon \\(or InDelta\\)" # TODO(ldez) must be fixed
- path: memmetrics/anomaly_test.go
text: "float-compare: use assert\\.InEpsilon \\(or InDelta\\)" # TODO(ldez) must be fixed
2 changes: 1 addition & 1 deletion forward/fwd_websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestWebSocketTCPClose(t *testing.T) {
serverErr := <-errChan

wsErr := &gorillawebsocket.CloseError{}
assert.ErrorAs(t, serverErr, &wsErr)
assert.ErrorAs(t, serverErr, &wsErr) //nolint:testifylint // The code is analyzed after this assertion.
assert.Equal(t, 1006, wsErr.Code)
}

Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ go 1.19

require (
github.com/HdrHistogram/hdrhistogram-go v1.1.2
github.com/gorilla/websocket v1.5.0
github.com/gorilla/websocket v1.5.1
github.com/mailgun/multibuf v0.1.2
github.com/segmentio/fasthash v1.0.3
github.com/stretchr/testify v1.8.4
github.com/vulcand/predicate v1.2.0
golang.org/x/net v0.17.0
golang.org/x/net v0.20.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gravitational/trace v1.1.16-0.20220114165159-14a9a7dd6aaf // indirect
github.com/jonboulle/clockwork v0.2.2 // indirect
github.com/jonboulle/clockwork v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
23 changes: 12 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.1 h1:gmztn0JnHVt9JZquRuzLw3g4wouNVzKL15iLr/zn/QY=
github.com/gorilla/websocket v1.5.1/go.mod h1:x3kM2JMyaluk02fnUJpQuwD2dCS5NDG2ZHL0uE0tcaY=
github.com/gravitational/trace v1.1.16-0.20220114165159-14a9a7dd6aaf h1:C1GPyPJrOlJlIrcaBBiBpDsqZena2Ks8spa5xZqr1XQ=
github.com/gravitational/trace v1.1.16-0.20220114165159-14a9a7dd6aaf/go.mod h1:zXqxTI6jXDdKnlf8s+nT+3c8LrwUEy3yNpO4XJL90lA=
github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ=
github.com/jonboulle/clockwork v0.2.2/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
Expand Down Expand Up @@ -58,8 +59,8 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand All @@ -82,8 +83,8 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -95,10 +96,10 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
22 changes: 11 additions & 11 deletions memmetrics/ratio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ func TestNotReady(t *testing.T) {
// No data
fr, err := NewRatioCounter(10, clock.Second)
require.NoError(t, err)
assert.Equal(t, false, fr.IsReady())
assert.False(t, fr.IsReady())
assert.Equal(t, 0.0, fr.Ratio())

// Not enough data
fr, err = NewRatioCounter(10, clock.Second)
require.NoError(t, err)
fr.CountA()
assert.Equal(t, false, fr.IsReady())
assert.False(t, fr.IsReady())
}

func TestNoB(t *testing.T) {
Expand All @@ -45,7 +45,7 @@ func TestNoB(t *testing.T) {
fr, err := NewRatioCounter(1, clock.Second)
require.NoError(t, err)
fr.IncA(1)
assert.Equal(t, true, fr.IsReady())
assert.True(t, fr.IsReady())
assert.Equal(t, 1.0, fr.Ratio())
}

Expand All @@ -56,7 +56,7 @@ func TestNoA(t *testing.T) {
fr, err := NewRatioCounter(1, clock.Second)
require.NoError(t, err)
fr.IncB(1)
assert.Equal(t, true, fr.IsReady())
assert.True(t, fr.IsReady())
assert.Equal(t, 0.0, fr.Ratio())
}

Expand All @@ -75,7 +75,7 @@ func TestMultipleBuckets(t *testing.T) {
clock.Advance(clock.Second)
fr.IncA(1)

assert.Equal(t, true, fr.IsReady())
assert.True(t, fr.IsReady())
assert.Equal(t, float64(2)/float64(3), fr.Ratio())
}

Expand All @@ -101,7 +101,7 @@ func TestOverwriteBuckets(t *testing.T) {
fr.IncA(1)
fr.IncB(2)

assert.Equal(t, true, fr.IsReady())
assert.True(t, fr.IsReady())
assert.Equal(t, float64(3)/float64(5), fr.Ratio())
}

Expand Down Expand Up @@ -131,7 +131,7 @@ func TestInactiveBuckets(t *testing.T) {
clock.Advance(clock.Second * 2)
fr.IncB(1)

assert.Equal(t, true, fr.IsReady())
assert.True(t, fr.IsReady())
assert.Equal(t, float64(1)/float64(4), fr.Ratio())
}

Expand All @@ -147,7 +147,7 @@ func TestLongPeriodsOfInactivity(t *testing.T) {
clock.Advance(clock.Second)
fr.IncA(1)

assert.Equal(t, true, fr.IsReady())
assert.True(t, fr.IsReady())
assert.Equal(t, 0.5, fr.Ratio())

// This time we should overwrite all data points
Expand All @@ -166,17 +166,17 @@ func TestNewRatioCounterReset(t *testing.T) {
fr.IncB(1)
fr.IncA(1)

assert.Equal(t, true, fr.IsReady())
assert.True(t, fr.IsReady())
assert.Equal(t, 0.5, fr.Ratio())

// Reset the counter
fr.Reset()
assert.Equal(t, false, fr.IsReady())
assert.False(t, fr.IsReady())

// Now add some stats
fr.IncA(2)

// We are game again!
assert.Equal(t, true, fr.IsReady())
assert.True(t, fr.IsReady())
assert.Equal(t, 1.0, fr.Ratio())
}
4 changes: 2 additions & 2 deletions ratelimit/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ func TestDivisionByZeroOnPeriod(t *testing.T) {
tb := newTokenBucket(&rate{period: time.Duration(emptyPeriod), average: 2, burst: 2})

_, err := tb.consume(1)
assert.NoError(t, err)
require.NoError(t, err)

err = tb.update(&rate{period: clock.Nanosecond, average: 1, burst: 1})
assert.NoError(t, err)
require.NoError(t, err)
}
2 changes: 1 addition & 1 deletion ratelimit/tokenlimiter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestRateSetAdd(t *testing.T) {

err = rs.Add(clock.Second, 1, 1)
require.NoError(t, err)
assert.Equal(t, rs.String(), "map[1s:rate(1/1s, burst=1)]")
assert.Equal(t, "map[1s:rate(1/1s, burst=1)]", rs.String())
}

// We've hit the limit and were able to proceed on the next time run.
Expand Down
2 changes: 1 addition & 1 deletion roundrobin/rebalancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type BalancerHandler interface {
// Meter measures server performance and returns its relative value via rating.
type Meter interface {
Rating() float64
Record(int, time.Duration)
Record(code int, latency time.Duration)
IsReady() bool
}

Expand Down
12 changes: 6 additions & 6 deletions roundrobin/rr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestRemoveBadServer(t *testing.T) {
lb, err := New(nil)
require.NoError(t, err)

assert.Error(t, lb.RemoveServer(testutils.ParseURI("http://google.com")))
require.Error(t, lb.RemoveServer(testutils.ParseURI("http://google.com")))
}

func TestCustomErrHandler(t *testing.T) {
Expand Down Expand Up @@ -154,7 +154,7 @@ func TestUpsertWeight(t *testing.T) {

assert.Equal(t, []string{"a", "b", "a"}, seq(t, proxy.URL, 3))

assert.NoError(t, lb.UpsertServer(testutils.ParseURI(b.URL), Weight(3)))
require.NoError(t, lb.UpsertServer(testutils.ParseURI(b.URL), Weight(3)))

assert.Equal(t, []string{"b", "b", "a", "b"}, seq(t, proxy.URL, 4))
}
Expand Down Expand Up @@ -188,19 +188,19 @@ func TestWeighted(t *testing.T) {

w, ok := lb.ServerWeight(testutils.ParseURI(a.URL))
assert.Equal(t, 3, w)
assert.Equal(t, true, ok)
assert.True(t, ok)

w, ok = lb.ServerWeight(testutils.ParseURI(b.URL))
assert.Equal(t, 2, w)
assert.Equal(t, true, ok)
assert.True(t, ok)

w, ok = lb.ServerWeight(testutils.ParseURI(z.URL))
assert.Equal(t, 0, w)
assert.Equal(t, true, ok)
assert.True(t, ok)

w, ok = lb.ServerWeight(testutils.ParseURI("http://caramba:4000"))
assert.Equal(t, -1, w)
assert.Equal(t, false, ok)
assert.False(t, ok)
}

func TestRequestRewriteListener(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions roundrobin/stickycookie/cookie_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import "net/url"
// It will be used by the load balancer to generate the sticky cookie value and to retrieve the matching url.
type CookieValue interface {
// Get converts raw value to an expected sticky format.
Get(*url.URL) string
Get(raw *url.URL) string

// FindURL gets url from array that match the value.
FindURL(string, []*url.URL) (*url.URL, error)
FindURL(raw string, urls []*url.URL) (*url.URL, error)
}

// areURLEqual compare a string to a url and check if the string is the same as the url value.
Expand Down
6 changes: 3 additions & 3 deletions roundrobin/stickycookie/fallback_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestFallbackValue_FindURL(t *testing.T) {

value, err := NewFallbackValue(from.CookieValue, to.CookieValue)
if from.CookieValue == nil && to.CookieValue == nil {
assert.Error(t, err)
require.Error(t, err)
return
}
require.NoError(t, err)
Expand Down Expand Up @@ -182,14 +182,14 @@ func TestFallbackValue_FindURL_error(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
value, err := NewFallbackValue(tt.From, tt.To)
if tt.expectErrorOnNew {
assert.Error(t, err)
require.Error(t, err)
return
}
require.NoError(t, err)

findURL, err := value.FindURL(tt.rawValue, servers)
if tt.expectError {
assert.Error(t, err)
require.Error(t, err)
return
}
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion utils/dumpreq_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ func TestHttpReqToString(t *testing.T) {
Body: &readCloserTestImpl{},
}

assert.True(t, len(DumpHTTPRequest(req)) > 0)
assert.NotEmpty(t, len(DumpHTTPRequest(req)))
}

0 comments on commit 842f413

Please sign in to comment.