diff --git a/.golangci.yml b/.golangci.yml index 3329718..678c369 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -24,7 +24,7 @@ linters-settings: exclude: - append govet: - check-shadowing: true + enable-all: true settings: printf: funcs: @@ -154,3 +154,4 @@ issues: - funlen - gomnd - lll + - musttag diff --git a/go.mod b/go.mod index 08e7a47..7c9abaf 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,7 @@ require ( github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect github.com/prometheus/client_golang v1.19.0 // indirect github.com/prometheus/client_model v0.6.0 // indirect - github.com/prometheus/common v0.50.0 // indirect + github.com/prometheus/common v0.51.0 // indirect github.com/prometheus/procfs v0.13.0 // indirect github.com/sasha-s/go-deadlock v0.3.1 // indirect go4.org/unsafe/assume-no-moving-gc v0.0.0-20231121144256-b99613f794b6 // indirect diff --git a/go.sum b/go.sum index 2c48322..9f66dbd 100644 --- a/go.sum +++ b/go.sum @@ -47,8 +47,8 @@ github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7km github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= -github.com/prometheus/common v0.50.0 h1:YSZE6aa9+luNa2da6/Tik0q0A5AbR+U003TItK57CPQ= -github.com/prometheus/common v0.50.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ= +github.com/prometheus/common v0.51.0 h1:vT5R9NAlW4V6k8Wruk7ikrHaHRsrPbduM/cKTOdQM/k= +github.com/prometheus/common v0.51.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ= github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o= github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g= github.com/sasha-s/go-deadlock v0.3.1 h1:sqv7fDNShgjcaxkO0JNcOAlr8B9+cV5Ey/OB71efZx0= diff --git a/pkg/lmd/a_helper_test.go b/pkg/lmd/a_helper_test.go index 47bf154..c6e002c 100644 --- a/pkg/lmd/a_helper_test.go +++ b/pkg/lmd/a_helper_test.go @@ -218,7 +218,7 @@ func prepareTmpDataHostService(dataFolder, tempFolder string, table *Table, numH hostname string services []string }, numHosts) - for curNum := 0; curNum < numHosts; curNum++ { + for curNum := range numHosts { hosts[curNum].hostname = fmt.Sprintf("%s_%d", "testhost", curNum+1) hosts[curNum].services = make([]string, 0) if curNum == 2 { @@ -238,8 +238,7 @@ func prepareTmpDataHostService(dataFolder, tempFolder string, table *Table, numH newData := []map[string]interface{}{} if name == TableHosts { count := 0 - for x := range hosts { - host := hosts[x] + for _, host := range hosts { count++ src := last if count <= num { @@ -257,9 +256,8 @@ func prepareTmpDataHostService(dataFolder, tempFolder string, table *Table, numH } if name == TableServices { count := 0 - for numH := range hosts { - host := hosts[numH] - for numS := range host.services { + for _, host := range hosts { + for _, service := range host.services { count++ src := last if count <= num { @@ -270,7 +268,7 @@ func prepareTmpDataHostService(dataFolder, tempFolder string, table *Table, numH newObj[key] = src[key] } newObj["host_name"] = host.hostname - newObj["description"] = host.services[numS] + newObj["description"] = service newData = append(newData, newObj) } } @@ -342,7 +340,7 @@ func StartTestPeerExtra(numPeers, numHosts, numServices int, extraConfig string) InitLogging(&Config{LogLevel: testLogLevel, LogFile: testLogTarget}) mocklmd = createTestLMDInstance() sockets := []string{} - for i := 0; i < numPeers; i++ { + for i := range numPeers { sockets = append(sockets, StartMockLivestatusSource(mocklmd, i, numHosts, numServices)) } StartMockMainLoop(mocklmd, sockets, extraConfig) diff --git a/pkg/lmd/benchmark_test.go b/pkg/lmd/benchmark_test.go index 8cfae2e..baaf0e6 100644 --- a/pkg/lmd/benchmark_test.go +++ b/pkg/lmd/benchmark_test.go @@ -33,7 +33,7 @@ func BenchmarkParseResultJSON(b *testing.B) { require.NoError(b, err) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { res, _, err2 := req.parseResult(resBytes) if err2 != nil { panic(err2.Error()) @@ -73,7 +73,7 @@ func BenchmarkParseResultWrappedJSON(b *testing.B) { require.NoError(b, err) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { res, _, err2 := req.parseResult(resBytes) if err2 != nil { panic(err2.Error()) @@ -98,7 +98,7 @@ func BenchmarkPeerUpdate(b *testing.B) { ctx := context.TODO() b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { err := peer.data.UpdateFull(ctx, Objects.UpdateTables) if err != nil { panic("Update failed") @@ -129,7 +129,7 @@ func BenchmarkPeerUpdateServiceInsert(b *testing.B) { } b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { res := peer.data.insertDeltaDataResult(2, res, meta, table) if res != nil { panic("Update failed") @@ -147,7 +147,7 @@ func BenchmarkSingleFilter_1k_svc__1Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString("GET hosts\nColumns: name\nFilter: contact_groups >= demo\nSort: name asc") if err != nil { panic(err.Error()) @@ -165,7 +165,7 @@ func BenchmarkSingleFilter_1k_svc_10Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString("GET hosts\nColumns: name\nFilter: contact_groups >= demo\nSort: name asc") if err != nil { panic(err.Error()) @@ -183,7 +183,7 @@ func BenchmarkMultiFilter_1k_svc__1Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString("GET hosts\nColumns: name\nFilter: name != test\nFilter: state != 5\nFilter: latency != 2\nFilter: contact_groups !=\nFilter: custom_variables != TEST blah\n") if err != nil { panic(err.Error()) @@ -201,7 +201,7 @@ func BenchmarkSimpleStats_1k_svc__1Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString("GET hosts\nStats: name != \nStats: avg latency\nStats: sum latency") if err != nil { panic(err.Error()) @@ -219,7 +219,7 @@ func BenchmarkTacStats_1k_svc__1Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString(tacPageStatsQuery) if err != nil { panic(err.Error()) @@ -237,7 +237,7 @@ func BenchmarkTacStats_1k_svc_10Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString(tacPageStatsQuery) if err != nil { panic(err.Error()) @@ -257,7 +257,7 @@ func BenchmarkTacStats_1k_svc_100Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString(tacPageStatsQuery) if err != nil { panic(err.Error()) @@ -277,7 +277,7 @@ func BenchmarkTacStats_5k_svc_500Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString(tacPageStatsQuery) if err != nil { panic(err.Error()) @@ -295,7 +295,7 @@ func BenchmarkServicelistLimit_1k_svc__1Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString(servicesPageQuery) if err != nil { panic(err.Error()) @@ -313,7 +313,7 @@ func BenchmarkServicelistLimit_1k_svc_10Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString(servicesPageQuery) if err != nil { panic(err.Error()) @@ -327,7 +327,7 @@ func BenchmarkServicelistLimit_1k_svc_10Peer(b *testing.B) { func BenchmarkRequestParser1(b *testing.B) { lmd := createTestLMDInstance() - for n := 0; n < b.N; n++ { + for range b.N { buf := bufio.NewReader(bytes.NewBufferString(servicesPageQuery)) _, size, err := NewRequest(context.TODO(), lmd, buf, ParseOptimize) if err != nil { @@ -341,7 +341,7 @@ func BenchmarkRequestParser1(b *testing.B) { func BenchmarkRequestParser2(b *testing.B) { lmd := createTestLMDInstance() - for n := 0; n < b.N; n++ { + for range b.N { buf := bufio.NewReader(bytes.NewBufferString(tacPageStatsQuery)) _, size, err := NewRequest(context.TODO(), lmd, buf, ParseOptimize) if err != nil { @@ -359,7 +359,7 @@ func BenchmarkServicesearchLimit_1k_svc_10Peer(b *testing.B) { PauseTestPeers(peer) b.StartTimer() - for n := 0; n < b.N; n++ { + for range b.N { _, _, err := peer.QueryString(serviceSearchQuery) if err != nil { panic(err.Error()) diff --git a/pkg/lmd/go.mod b/pkg/lmd/go.mod index f3ba46b..b25332b 100644 --- a/pkg/lmd/go.mod +++ b/pkg/lmd/go.mod @@ -30,7 +30,7 @@ require ( github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.6.0 // indirect - github.com/prometheus/common v0.50.0 // indirect + github.com/prometheus/common v0.51.0 // indirect github.com/prometheus/procfs v0.13.0 // indirect go4.org/unsafe/assume-no-moving-gc v0.0.0-20231121144256-b99613f794b6 // indirect golang.org/x/sys v0.18.0 // indirect diff --git a/pkg/lmd/go.sum b/pkg/lmd/go.sum index ec7d0c5..23e96d9 100644 --- a/pkg/lmd/go.sum +++ b/pkg/lmd/go.sum @@ -52,8 +52,8 @@ github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7km github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= -github.com/prometheus/common v0.50.0 h1:YSZE6aa9+luNa2da6/Tik0q0A5AbR+U003TItK57CPQ= -github.com/prometheus/common v0.50.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ= +github.com/prometheus/common v0.51.0 h1:vT5R9NAlW4V6k8Wruk7ikrHaHRsrPbduM/cKTOdQM/k= +github.com/prometheus/common v0.51.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ= github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o= github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=