Skip to content

Commit

Permalink
use 1.22 syntax for intranges
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Mar 23, 2024
1 parent 1a8a51f commit b924a27
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ linters-settings:
exclude:
- append
govet:
check-shadowing: true
enable-all: true
settings:
printf:
funcs:
Expand Down Expand Up @@ -154,3 +154,4 @@ issues:
- funlen
- gomnd
- lll
- musttag
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
14 changes: 6 additions & 8 deletions pkg/lmd/a_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 17 additions & 17 deletions pkg/lmd/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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())
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/lmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/lmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit b924a27

Please sign in to comment.