Skip to content

Commit

Permalink
Merge pull request #16 from krakend/deepsource_suggested_improvements
Browse files Browse the repository at this point in the history
Deepsource suggested improvements
  • Loading branch information
kpacha authored Sep 18, 2024
2 parents 35a13bb + f9ffbf6 commit 5653ddd
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 149 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v3
with:
go-version: 1.17
go-version: 1.23

- name: Test
run: go test -v ./...
16 changes: 11 additions & 5 deletions gin/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"io/ioutil"
"io"
"math/rand"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -34,7 +34,9 @@ func TestDisabledRouterMetrics(t *testing.T) {
}

func TestNew(t *testing.T) {
rand.Seed(time.Now().Unix())
// we do not need a lot of entropy for the test, so we comment
// the line to skip the warning
rand.Seed(time.Now().Unix()) // skipcq: GO-S1033
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
buf := bytes.NewBuffer(make([]byte, 1024))
Expand All @@ -48,7 +50,8 @@ func TestNew(t *testing.T) {
max := 1000
min := 1
p := func(_ context.Context, _ *proxy.Request) (*proxy.Response, error) {
time.Sleep(time.Microsecond * time.Duration(rand.Intn(max-min)+min))
// we do not need crypto strong rand generator for this
time.Sleep(time.Microsecond * time.Duration(rand.Intn(max-min)+min)) // skipcq: GSC-G404
return &response, nil
}
hf := metric.NewHTTPHandlerFactory(krakendgin.EndpointHandler)
Expand Down Expand Up @@ -119,17 +122,20 @@ func TestStatsEndpoint(t *testing.T) {
t.Errorf("Problem with the stats endpoint: %s\n", err.Error())
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
t.Errorf("Cannot read body: %s\n", err.Error())
return
}
_ = resp.Body.Close()
var stats map[string]interface{}
err = json.Unmarshal(body, &stats)
if err != nil {
t.Errorf("Proble unmarshaling stats endpoint response: %s\n", err.Error())
return
}
if _, ok := stats["cmdline"]; !ok {
t.Error("Key cmdline should exists in the response.\n")
return
}
}
40 changes: 25 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,45 +1,55 @@
module github.com/krakendio/krakend-metrics/v2

go 1.17
go 1.19

require (
github.com/gin-gonic/gin v1.7.7
github.com/gin-gonic/gin v1.9.1
github.com/krakendio/krakend-viper/v2 v2.0.1
github.com/luraproject/lura/v2 v2.0.5
github.com/luraproject/lura/v2 v2.7.0
github.com/rcrowley/go-metrics v0.0.0-20180406234716-d932a24a8ccb
)

require (
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/fsnotify/fsnotify v1.4.7 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.9.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/krakendio/flatmap v1.1.1 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/magiconair/properties v1.8.1 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/spf13/afero v1.1.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/spf13/viper v1.7.1 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20211004093028-2c5d950f24ef // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/ini.v1 v1.51.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 5653ddd

Please sign in to comment.