From d246b97558b92f30404c67d69cfc38bceed209ad Mon Sep 17 00:00:00 2001 From: Chris Grindstaff Date: Sun, 13 Aug 2023 08:19:05 -0400 Subject: [PATCH] chore: bump go chore: replace utils with builtins --- .github/workflows/go.yml | 2 +- .github/workflows/golangci-lint.yml | 2 +- Makefile | 2 +- cmd/collectors/ems/ems_test.go | 16 ++++---- cmd/tools/doctor/restZapiDiff.go | 6 +-- cmd/tools/grafana/dashboard_test.go | 6 +-- go.mod | 2 +- go.sum | 1 + integration/Jenkinsfile | 2 +- integration/go.mod | 18 ++++----- integration/go.sum | 29 ++++++------- jenkins/artifacts/jenkinsfile | 2 +- pkg/tree/node/node.go | 7 ++-- pkg/util/util.go | 63 ++++++++--------------------- 14 files changed, 66 insertions(+), 92 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 999df8661..454c5b15a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,7 +1,7 @@ name: Build, Test, Lint License env: - GO_VERSION: "1.20.7" + GO_VERSION: "1.21.0" on: push: diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index e1079e065..09861e044 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -19,7 +19,7 @@ jobs: steps: - uses: actions/setup-go@v4 with: - go-version: '1.20.7' + go-version: '1.21.0' - uses: actions/checkout@v3 - name: golangci-lint uses: golangci/golangci-lint-action@v3 diff --git a/Makefile b/Makefile index 6dc30d128..bc9e3ce8c 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ ############################################################################### SHELL := /bin/bash GCC_EXISTS := $(shell which gcc) -REQUIRED_GO_VERSION := 1.20 +REQUIRED_GO_VERSION := 1.21 ifneq (, $(shell which go)) FOUND_GO_VERSION := $(shell go version | cut -d" " -f3 | cut -d"o" -f 2) CORRECT_GO_VERSION := $(shell expr `go version | cut -d" " -f3 | cut -d"o" -f 2` \>= ${REQUIRED_GO_VERSION}) diff --git a/cmd/collectors/ems/ems_test.go b/cmd/collectors/ems/ems_test.go index 379b2126f..d75f65b0e 100644 --- a/cmd/collectors/ems/ems_test.go +++ b/cmd/collectors/ems/ems_test.go @@ -7,9 +7,9 @@ import ( "github.com/netapp/harvest/v2/pkg/conf" "github.com/netapp/harvest/v2/pkg/tree" "github.com/netapp/harvest/v2/pkg/tree/node" - "github.com/netapp/harvest/v2/pkg/util" "github.com/rs/zerolog/log" "os" + "slices" "testing" "time" ) @@ -90,7 +90,7 @@ func (e *Ems) testBookendIssuingEms(t *testing.T, path string) { // Check and evaluate ems events var notGeneratedEmsNames []string for generatedEmsName, mx := range e.Matrix { - if util.Contains(issuingEmsNames, generatedEmsName) { + if slices.Contains(issuingEmsNames, generatedEmsName) { metr, ok := mx.GetMetrics()["events"] if !ok { t.Fatalf("Failed to get netric for Ems %s", generatedEmsName) @@ -129,7 +129,7 @@ func (e *Ems) testBookendResolvingEms(t *testing.T, path string) { // Check and evaluate ems events var notResolvedEmsNames []string for generatedEmsName, mx := range e.Matrix { - if util.Contains(issuingEmsNames, generatedEmsName) { + if slices.Contains(issuingEmsNames, generatedEmsName) { metr, ok := mx.GetMetrics()["events"] if !ok { t.Fatalf("Failed to get netric for Ems %s", generatedEmsName) @@ -169,7 +169,7 @@ func (e *Ems) testAutoResolvingEms(t *testing.T, path string) { // Check and evaluate ems events for generatedEmsName, mx := range e.Matrix { - if util.Contains(autoresolveEmsNames, generatedEmsName) { + if slices.Contains(autoresolveEmsNames, generatedEmsName) { if metr, ok := mx.GetMetrics()["events"]; ok { for _, instance := range mx.GetInstances() { // If value not exist for that instance or metric value 0 indicate ems hasn't been raised. @@ -191,7 +191,7 @@ func (e *Ems) testAutoResolvingEms(t *testing.T, path string) { e.updateMatrix(time.Now().Add(1 * time.Second)) // Check and evaluate bookend ems events got auto resolved successfully. for generatedEmsName, mx := range e.Matrix { - if util.Contains(autoresolveEmsNames, generatedEmsName) { + if slices.Contains(autoresolveEmsNames, generatedEmsName) { if metr, ok := mx.GetMetrics()["events"]; ok { for _, instance := range mx.GetInstances() { // If value not exist for that instance or metric value 0 indicate ems hasn't been raised. @@ -204,7 +204,7 @@ func (e *Ems) testAutoResolvingEms(t *testing.T, path string) { } } } - if util.Contains(notAutoResolvedEmsNames, "LUN.offline") { + if slices.Contains(notAutoResolvedEmsNames, "LUN.offline") { t.Fatalf("These Bookend Ems haven't been auto resolved: %s", notAutoResolvedEmsNames) } @@ -217,7 +217,7 @@ func (e *Ems) testAutoResolvingEms(t *testing.T, path string) { t.Fatalf("These Bookend Ems haven't been removed from cache: %s", "LUN.offline") } for generatedEmsName, mx := range e.Matrix { - if util.Contains(autoresolveEmsNames, generatedEmsName) { + if slices.Contains(autoresolveEmsNames, generatedEmsName) { if metr, ok := mx.GetMetrics()["events"]; ok { for _, instance := range mx.GetInstances() { // If value not exist for that instance or metric value 0 indicate ems hasn't been raised. @@ -230,7 +230,7 @@ func (e *Ems) testAutoResolvingEms(t *testing.T, path string) { } } } - if util.Contains(notAutoResolvedEmsNames, "monitor.fan.critical") { + if slices.Contains(notAutoResolvedEmsNames, "monitor.fan.critical") { t.Fatalf("These Bookend Ems haven't been auto resolved: %s", notAutoResolvedEmsNames) } } diff --git a/cmd/tools/doctor/restZapiDiff.go b/cmd/tools/doctor/restZapiDiff.go index 248787b18..3e949fb8d 100644 --- a/cmd/tools/doctor/restZapiDiff.go +++ b/cmd/tools/doctor/restZapiDiff.go @@ -2,7 +2,6 @@ package doctor import ( "fmt" - "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" "io" "log" @@ -11,6 +10,7 @@ import ( "os" "path/filepath" "regexp" + "slices" "strconv" "strings" "time" @@ -520,7 +520,7 @@ func labelValueDiff(label string, labelNames []string) { results = gjson.GetMany(data, prefixLabelsName...) } - if util.Contains([]string{"shelf_voltage_labels", "shelf_temperature_labels", "shelf_sensor_labels"}, label) { + if slices.Contains([]string{"shelf_voltage_labels", "shelf_temperature_labels", "shelf_sensor_labels"}, label) { keyIndexes = append(keyIndexes, IndexOf(finalLabelNames, "shelf")) keyIndexes = append(keyIndexes, IndexOf(finalLabelNames, "sensor_id")) dataCenterIndex = IndexOf(finalLabelNames, "datacenter") @@ -533,7 +533,7 @@ func labelValueDiff(label string, labelNames []string) { results = gjson.GetMany(data, prefixLabelsName...) } - if util.Contains([]string{"svm_labels", "security_login_labels"}, label) { + if slices.Contains([]string{"svm_labels", "security_login_labels"}, label) { keyIndexes = append(keyIndexes, IndexOf(finalLabelNames, "svm")) dataCenterIndex = IndexOf(finalLabelNames, "datacenter") results = gjson.GetMany(data, prefixLabelsName...) diff --git a/cmd/tools/grafana/dashboard_test.go b/cmd/tools/grafana/dashboard_test.go index b1ede5cf6..6b7fbd87d 100644 --- a/cmd/tools/grafana/dashboard_test.go +++ b/cmd/tools/grafana/dashboard_test.go @@ -2,12 +2,12 @@ package grafana import ( "fmt" - "github.com/netapp/harvest/v2/pkg/util" "github.com/tidwall/gjson" "github.com/tidwall/pretty" "os" "path/filepath" "regexp" + "slices" "sort" "strconv" "strings" @@ -83,7 +83,7 @@ func checkThreshold(t *testing.T, path string, data []byte) { isThresholdSet = color.String() == th[0] && v.String() == th[1] } else if id == "custom.displayMode" && kind == "table" { v := propertiesN.Get("value") - if !util.Contains(expectedColorBackground[kind], v.String()) { + if !slices.Contains(expectedColorBackground[kind], v.String()) { t.Errorf("dashboard=%s panel=%s kind=%s expr=%s don't have correct displaymode expected %s found %s", path, panelTitle, kind, expr, expectedColorBackground[kind], v.String()) } else { isColorBackgroundSet = true @@ -94,7 +94,7 @@ func checkThreshold(t *testing.T, path string, data []byte) { if kind == "stat" { colorMode := value.Get("options.colorMode") - if !util.Contains(expectedColorBackground[kind], colorMode.String()) { + if !slices.Contains(expectedColorBackground[kind], colorMode.String()) { t.Errorf("dashboard=%s panel=%s kind=%s expr=%s don't have correct colorMode expected %s found %s", path, panelTitle, kind, expr, expectedColorBackground[kind], colorMode.String()) } else { isColorBackgroundSet = true diff --git a/go.mod b/go.mod index cbae6e2b1..dcd4f8e33 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/netapp/harvest/v2 -go 1.20 +go 1.21 require ( dario.cat/mergo v1.0.0 diff --git a/go.sum b/go.sum index 38d118fb8..729dc7423 100644 --- a/go.sum +++ b/go.sum @@ -38,6 +38,7 @@ github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFF github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 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= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= diff --git a/integration/Jenkinsfile b/integration/Jenkinsfile index 560020f23..2ff39f0a3 100644 --- a/integration/Jenkinsfile +++ b/integration/Jenkinsfile @@ -18,7 +18,7 @@ pipeline { environment { BUILD_ID="dontKillMe" JENKINS_NODE_COOKIE="dontKillMe" - GO_VERSION = "1.20.7" + GO_VERSION = "1.21.0" } stages { diff --git a/integration/go.mod b/integration/go.mod index e8321114e..a231c398c 100644 --- a/integration/go.mod +++ b/integration/go.mod @@ -1,15 +1,15 @@ module github.com/Netapp/harvest-automation -go 1.20 +go 1.21 replace github.com/netapp/harvest/v2 => ../ require ( github.com/carlmjohnson/requests v0.23.4 - github.com/netapp/harvest/v2 v2.0.0-20230404163343-f21b0c1a08ac - github.com/rs/zerolog v1.29.1 - github.com/tidwall/gjson v1.14.4 - golang.org/x/text v0.11.0 + github.com/netapp/harvest/v2 v2.0.0-20230811164902-1b91e21d6950 + github.com/rs/zerolog v1.30.0 + github.com/tidwall/gjson v1.16.0 + golang.org/x/text v0.12.0 ) require ( @@ -21,16 +21,16 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b // indirect - github.com/shirou/gopsutil/v3 v3.23.6 // indirect + github.com/shirou/gopsutil/v3 v3.23.7 // indirect github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/spf13/cobra v1.7.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.1 // indirect - github.com/tklauser/go-sysconf v0.3.11 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect github.com/tklauser/numcpus v0.6.1 // indirect github.com/yusufpapurcu/wmi v1.2.3 // indirect - golang.org/x/net v0.7.0 // indirect - golang.org/x/sys v0.10.0 // indirect + golang.org/x/net v0.14.0 // indirect + golang.org/x/sys v0.11.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/integration/go.sum b/integration/go.sum index 1b4dc8607..44ae3d0d1 100644 --- a/integration/go.sum +++ b/integration/go.sum @@ -33,12 +33,12 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b h1:0LFwY6Q3gMACTjAbMZBjXAqTOzOwFaj2Ld6cjeQ7Rig= github.com/power-devops/perfstat v0.0.0-20221212215047-62379fc7944b/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= -github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc= -github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= +github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shirou/gopsutil/v3 v3.23.6 h1:5y46WPI9QBKBbK7EEccUPNXpJpNrvPuTD0O2zHEHT08= -github.com/shirou/gopsutil/v3 v3.23.6/go.mod h1:j7QX50DrXYggrpN30W0Mo+I4/8U2UUIQrnrhqUeWrAU= +github.com/shirou/gopsutil/v3 v3.23.7 h1:C+fHO8hfIppoJ1WdsVm1RoI0RwXoNdfTK7yWXV0wVj4= +github.com/shirou/gopsutil/v3 v3.23.7/go.mod h1:c4gnmoRC0hQuaLqvxnx1//VXQ0Ms/X9UnJF8pddY5z4= github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= @@ -54,22 +54,23 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM= -github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= +github.com/tidwall/gjson v1.16.0 h1:SyXa+dsSPpUlcwEDuKuEBJEz5vzTvOea+9rjyYodQFg= +github.com/tidwall/gjson v1.16.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4= github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= -github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= -golang.org/x/net v0.7.0 h1:rJrUqqhjsgNp7KqAIc25s9pZnjU7TUcSY7HcVZjdn1g= -golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -78,11 +79,11 @@ golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= -golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/jenkins/artifacts/jenkinsfile b/jenkins/artifacts/jenkinsfile index d64b89bfd..86430d77f 100644 --- a/jenkins/artifacts/jenkinsfile +++ b/jenkins/artifacts/jenkinsfile @@ -37,7 +37,7 @@ pipeline { jfrogImagePrefix = "netappdownloads.jfrog.io/oss-docker-harvest-production/harvest" jfrogRepo = "netappdownloads.jfrog.io" COMMIT_ID = sh(returnStdout: true, script: 'git rev-parse HEAD') - GO_VERSION = "1.20.7" + GO_VERSION = "1.21.0" } stages { diff --git a/pkg/tree/node/node.go b/pkg/tree/node/node.go index f9f1c14c0..16ac91ebb 100644 --- a/pkg/tree/node/node.go +++ b/pkg/tree/node/node.go @@ -10,6 +10,7 @@ import ( "fmt" "github.com/netapp/harvest/v2/pkg/util" "regexp" + "slices" "strings" ) @@ -326,7 +327,7 @@ func (n *Node) Merge(subtemplate *Node, skipOverwrite []string) { } else if mine == nil { n.AddChild(child) } else { - if mine.GetParent() != nil && util.Contains(skipOverwrite, mine.GetParent().GetNameS()) { + if mine.GetParent() != nil && slices.Contains(skipOverwrite, mine.GetParent().GetNameS()) { mine.SetContentS(mine.GetContentS() + "," + child.GetContentS()) } else { mine.SetContentS(child.GetContentS()) @@ -418,7 +419,7 @@ func (n *Node) SearchContent(prefix []string, paths [][]string) ([]string, bool) } //fmt.Printf(" -> current_path=%v \t new_path=%v\n", currentPath, newPath) for _, path := range paths { - if util.EqualStringSlice(newPath, path) { + if slices.Equal(newPath, path) { matches = append(matches, node.GetContentS()) //fmt.Println(" MATCH!") break @@ -451,7 +452,7 @@ func (n *Node) SearchChildren(path []string) []*Node { newPath = make([]string, len(currentPath)) copy(newPath, currentPath) } - if util.EqualStringSlice(newPath, path) { + if slices.Equal(newPath, path) { matches = append(matches, node) } else if len(newPath) < len(path) { for _, child := range node.GetChildren() { diff --git a/pkg/util/util.go b/pkg/util/util.go index 002936ccb..8c63b2fcb 100644 --- a/pkg/util/util.go +++ b/pkg/util/util.go @@ -15,6 +15,7 @@ import ( "net/url" "os" "regexp" + "slices" "sort" "strconv" "strings" @@ -40,25 +41,25 @@ func GetCollectorSlice() []string { } func MinLen(elements [][]string) int { - var min, i int - min = len(elements[0]) + var smallest, i int + smallest = len(elements[0]) for i = 1; i < len(elements); i++ { - if len(elements[i]) < min { - min = len(elements[i]) + if len(elements[i]) < smallest { + smallest = len(elements[i]) } } - return min + return smallest } func MaxLen(elements [][]string) int { - var max, i int - max = len(elements[0]) + var largest, i int + largest = len(elements[0]) for i = 1; i < len(elements); i++ { - if len(elements[i]) > max { - max = len(elements[i]) + if len(elements[i]) > largest { + largest = len(elements[i]) } } - return max + return largest } func AllSame(elements [][]string, k int) bool { @@ -71,19 +72,6 @@ func AllSame(elements [][]string, k int) bool { return true } -func EqualStringSlice(a, b []string) bool { - var i int - if len(a) != len(b) { - return false - } - for i = 0; i < len(a); i++ { - if a[i] != b[i] { - return false - } - } - return true -} - var pollerRegex = regexp.MustCompile(`poller\s+--poller\s+(.*?)\s`) var profRegex = regexp.MustCompile(`--profiling (\d+)`) var promRegex = regexp.MustCompile(`--promPort (\d+)`) @@ -127,15 +115,6 @@ func GetPollerStatuses() ([]PollerStatus, error) { return result, nil } -func Contains(s []string, e string) bool { - for _, a := range s { - if a == e { - return true - } - } - return false -} - func FindLocalIP() (string, error) { conn, err := net.Dial("udp", "1.1.1.1:80") if err != nil { @@ -310,28 +289,20 @@ func SumNumbers(s []float64) float64 { return total } +// Max returns 0 when passed an empty slice, slices.Max panics if input is empty +// This function can be removed once all callers are checked for empty slices func Max(input []float64) float64 { if len(input) > 0 { - max := input[0] - for _, v := range input { - if v > max { - max = v - } - } - return max + return slices.Max(input) } return 0 } +// Min returns 0 when passed an empty slice, slices.Min panics if input is empty +// This function can be removed once all callers are checked for empty slices func Min(input []float64) float64 { if len(input) > 0 { - min := input[0] - for _, v := range input { - if v < min { - min = v - } - } - return min + return slices.Min(input) } return 0 }