go.d fix Goland code inspection warnings (#18552)
Ilya Mashchenko committed
Sep 14, 2024 at 22:25 UTC
a7c8b989c320a1522cde5dfcc89817d5ae04f7f5
65 files changed
+128
-110
src/go/plugin/go.d/agent/confgroup/config_test.go
+6
-6
@@ -13,7 +13,7 @@ import (
13
func TestConfig_Name(t *testing.T) {
14
tests := map[string]struct {
15
cfg Config
16
- expected interface{}
16
+ expected any
17
}{
18
"string": {cfg: Config{"name": "name"}, expected: "name"},
19
"empty string": {cfg: Config{"name": ""}, expected: ""},
@@ -32,7 +32,7 @@ func TestConfig_Name(t *testing.T) {
32
func TestConfig_Module(t *testing.T) {
33
tests := map[string]struct {
34
cfg Config
35
- expected interface{}
35
+ expected any
36
}{
37
"string": {cfg: Config{"module": "module"}, expected: "module"},
38
"empty string": {cfg: Config{"module": ""}, expected: ""},
@@ -51,7 +51,7 @@ func TestConfig_Module(t *testing.T) {
51
func TestConfig_FullName(t *testing.T) {
52
tests := map[string]struct {
53
cfg Config
54
- expected interface{}
54
+ expected any
55
}{
56
"name == module": {cfg: Config{"name": "name", "module": "name"}, expected: "name"},
57
"name != module": {cfg: Config{"name": "name", "module": "module"}, expected: "module_name"},
@@ -68,7 +68,7 @@ func TestConfig_FullName(t *testing.T) {
68
func TestConfig_UpdateEvery(t *testing.T) {
69
tests := map[string]struct {
70
cfg Config
71
- expected interface{}
71
+ expected any
72
}{
73
"int": {cfg: Config{"update_every": 1}, expected: 1},
74
"not int": {cfg: Config{"update_every": "1"}, expected: 0},
@@ -86,7 +86,7 @@ func TestConfig_UpdateEvery(t *testing.T) {
86
func TestConfig_AutoDetectionRetry(t *testing.T) {
87
tests := map[string]struct {
88
cfg Config
89
- expected interface{}
89
+ expected any
90
}{
91
"int": {cfg: Config{"autodetection_retry": 1}, expected: 1},
92
"not int": {cfg: Config{"autodetection_retry": "1"}, expected: 0},
@@ -104,7 +104,7 @@ func TestConfig_AutoDetectionRetry(t *testing.T) {
104
func TestConfig_Priority(t *testing.T) {
105
tests := map[string]struct {
106
cfg Config
107
- expected interface{}
107
+ expected any
108
}{
109
"int": {cfg: Config{"priority": 1}, expected: 1},
110
"not int": {cfg: Config{"priority": "1"}, expected: 0},
src/go/plugin/go.d/agent/config.go
+2
-2
@@ -47,13 +47,13 @@ func (c *config) isEnabled(moduleName string, explicit bool) bool {
47
return c.DefaultRun
48
}
49
50
-func (c *config) UnmarshalYAML(unmarshal func(interface{}) error) error {
50
+func (c *config) UnmarshalYAML(unmarshal func(any) error) error {
51
type plain config
52
if err := unmarshal((*plain)(c)); err != nil {
53
return err
54
}
55
56
- var m map[string]interface{}
56
+ var m map[string]any
57
if err := unmarshal(&m); err != nil {
58
return err
59
}
src/go/plugin/go.d/agent/discovery/file/parse.go
+1
-1
@@ -97,7 +97,7 @@ func parseSDFormat(reg confgroup.Registry, path string, bs []byte) (*confgroup.G
97
}
98
99
func cfgFormat(bs []byte) format {
100
- var data interface{}
100
+ var data any
101
if err := yaml.Unmarshal(bs, &data); err != nil {
102
return unknownFormat
103
}
src/go/plugin/go.d/agent/discovery/file/sim_test.go
+1
-1
@@ -110,7 +110,7 @@ func (d *tmpDir) renameFile(origFilename, newFilename string) {
110
require.NoError(d.t, err)
111
}
112
113
-func (d *tmpDir) writeYAML(filename string, in interface{}) {
113
+func (d *tmpDir) writeYAML(filename string, in any) {
114
bs, err := yaml.Marshal(in)
115
require.NoError(d.t, err)
116
err = os.WriteFile(filename, bs, 0644)
src/go/plugin/go.d/agent/discovery/sd/discoverer/kubernetes/kubernetes.go
+1
-1
@@ -234,7 +234,7 @@ func (d *KubeDiscoverer) setupServiceDiscoverer(ctx context.Context, namespace s
234
return td
235
}
236
237
-func enqueue(queue *workqueue.Type, obj any) {
237
+func enqueue(queue *workqueue.Typed[any], obj any) {
238
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
239
if err != nil {
240
return
src/go/plugin/go.d/agent/discovery/sd/discoverer/kubernetes/kubernetes_test.go
+1
-1
@@ -134,7 +134,7 @@ func TestKubeDiscoverer_Discover(t *testing.T) {
134
}
135
136
func prepareDiscoverer(role role, namespaces []string, objects ...runtime.Object) (*KubeDiscoverer, kubernetes.Interface) {
137
- client := fake.NewSimpleClientset(objects...)
137
+ client := fake.NewClientset(objects...)
138
tags, _ := model.ParseTags("k8s")
139
disc := &KubeDiscoverer{
140
tags: tags,
src/go/plugin/go.d/agent/discovery/sd/discoverer/kubernetes/pod.go
+2
-2
@@ -58,7 +58,7 @@ func newPodDiscoverer(pod, cmap, secret cache.SharedInformer) *podDiscoverer {
58
panic("nil pod or cmap or secret informer")
59
}
60
61
- queue := workqueue.NewWithConfig(workqueue.QueueConfig{Name: "pod"})
61
+ queue := workqueue.NewTypedWithConfig(workqueue.TypedQueueConfig[any]{Name: "pod"})
62
63
_, _ = pod.AddEventHandler(cache.ResourceEventHandlerFuncs{
64
AddFunc: func(obj any) { enqueue(queue, obj) },
@@ -82,7 +82,7 @@ type podDiscoverer struct {
82
podInformer cache.SharedInformer
83
cmapInformer cache.SharedInformer
84
secretInformer cache.SharedInformer
85
- queue *workqueue.Type
85
+ queue *workqueue.Typed[any]
86
}
87
88
func (p *podDiscoverer) String() string {
src/go/plugin/go.d/agent/discovery/sd/discoverer/kubernetes/service.go
+3
-2
@@ -53,7 +53,7 @@ type serviceDiscoverer struct {
53
model.Base
54
55
informer cache.SharedInformer
56
- queue *workqueue.Type
56
+ queue *workqueue.Typed[any]
57
}
58
59
func newServiceDiscoverer(inf cache.SharedInformer) *serviceDiscoverer {
@@ -61,7 +61,8 @@ func newServiceDiscoverer(inf cache.SharedInformer) *serviceDiscoverer {
61
panic("nil service informer")
62
}
63
64
- queue := workqueue.NewWithConfig(workqueue.QueueConfig{Name: "service"})
64
+ queue := workqueue.NewTypedWithConfig(workqueue.TypedQueueConfig[any]{Name: "service"})
65
+
66
_, _ = inf.AddEventHandler(cache.ResourceEventHandlerFuncs{
67
AddFunc: func(obj any) { enqueue(queue, obj) },
68
UpdateFunc: func(_, obj any) { enqueue(queue, obj) },
src/go/plugin/go.d/agent/discovery/sd/pipeline/funcmap.go
+1
-1
@@ -14,7 +14,7 @@ import (
14
)
15
16
func newFuncMap() template.FuncMap {
17
- custom := map[string]interface{}{
17
+ custom := map[string]any{
18
"match": funcMatchAny,
19
"glob": func(value, pattern string, patterns ...string) bool {
20
return funcMatchAny("glob", value, pattern, patterns...)
src/go/plugin/go.d/agent/discovery/sim_test.go
+1
@@ -9,6 +9,7 @@ import (
9
"time"
10
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/confgroup"
12
+
13
"github.com/stretchr/testify/assert"
14
"github.com/stretchr/testify/require"
15
)
src/go/plugin/go.d/agent/jobmgr/sim_test.go
+1
@@ -14,6 +14,7 @@ import (
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
15
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/netdataapi"
16
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/safewriter"
17
+
18
"github.com/stretchr/testify/assert"
19
"github.com/stretchr/testify/require"
20
)
src/go/plugin/go.d/agent/module/module.go
+2
-2
@@ -53,8 +53,8 @@ func TestConfigurationSerialize(t *testing.T, mod Module, cfgJSON, cfgYAML []byt
53
t.Helper()
54
tests := map[string]struct {
55
config []byte
56
- unmarshal func(in []byte, out interface{}) (err error)
57
- marshal func(in interface{}) (out []byte, err error)
56
+ unmarshal func(in []byte, out any) (err error)
57
+ marshal func(in any) (out []byte, err error)
58
}{
59
"json": {config: cfgJSON, marshal: json.Marshal, unmarshal: json.Unmarshal},
60
"yaml": {config: cfgYAML, marshal: yaml.Marshal, unmarshal: yaml.Unmarshal},
src/go/plugin/go.d/agent/vnodes/vnodes.go
+1
-1
@@ -130,7 +130,7 @@ func isConfigFile(path string) bool {
130
}
131
}
132
133
-func loadConfigFile(conf interface{}, path string) error {
133
+func loadConfigFile(conf any, path string) error {
134
f, err := os.Open(path)
135
if err != nil {
136
return err
src/go/plugin/go.d/modules/activemq/init.go
+1
@@ -4,6 +4,7 @@ package activemq
4
5
import (
6
"errors"
7
+
8
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
9
)
10
src/go/plugin/go.d/modules/cassandra/collect.go
+2
-1
@@ -4,8 +4,9 @@ package cassandra
4
5
import (
6
"errors"
7
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
7
"strings"
8
+
9
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
10
)
11
12
const (
src/go/plugin/go.d/modules/cockroachdb/init.go
+1
-1
@@ -4,9 +4,9 @@ package cockroachdb
4
5
import (
6
"errors"
7
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
7
8
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
9
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
10
)
11
12
func (c *CockroachDB) validateConfig() error {
src/go/plugin/go.d/modules/coredns/collect.go
+2
-1
@@ -7,9 +7,10 @@ import (
7
"fmt"
8
"strings"
9
10
- "github.com/blang/semver/v4"
10
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
12
+
13
+ "github.com/blang/semver/v4"
14
)
15
16
const (
src/go/plugin/go.d/modules/couchdb/collect.go
+2
-2
@@ -185,13 +185,13 @@ func (cdb *CouchDB) scrapeDBStats(ms *cdbMetrics) {
185
ms.DBStats = stats
186
}
187
188
-func findMaxMQSize(MessageQueues map[string]interface{}) int64 {
188
+func findMaxMQSize(MessageQueues map[string]any) int64 {
189
var maxSize float64
190
for _, mq := range MessageQueues {
191
switch mqSize := mq.(type) {
192
case float64:
193
maxSize = math.Max(maxSize, mqSize)
194
- case map[string]interface{}:
194
+ case map[string]any:
195
if v, ok := mqSize["count"].(float64); ok {
196
maxSize = math.Max(maxSize, v)
197
}
src/go/plugin/go.d/modules/couchdb/metrics.go
+1
-1
@@ -182,7 +182,7 @@ type cdbNodeSystem struct {
182
ProcessCount float64 `stm:"process_count" json:"process_count"`
183
InternalReplicationJobs float64 `stm:"internal_replication_jobs" json:"internal_replication_jobs"`
184
185
- MessageQueues map[string]interface{} `json:"message_queues"`
185
+ MessageQueues map[string]any `json:"message_queues"`
186
}
187
188
type cdbDBStats struct {
src/go/plugin/go.d/modules/dnsdist/dnsdist_test.go
+1
-1
@@ -3,12 +3,12 @@
3
package dnsdist
4
5
import (
6
- "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
6
"net/http"
7
"net/http/httptest"
8
"os"
9
"testing"
10
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
src/go/plugin/go.d/modules/dnsquery/init.go
+1
@@ -5,6 +5,7 @@ package dnsquery
5
import (
6
"errors"
7
"fmt"
8
+
9
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
10
11
"github.com/miekg/dns"
src/go/plugin/go.d/modules/docker_engine/init.go
+1
-1
@@ -4,9 +4,9 @@ package docker_engine
4
5
import (
6
"errors"
7
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
7
8
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/prometheus"
9
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
10
)
11
12
func (de *DockerEngine) validateConfig() error {
src/go/plugin/go.d/modules/dockerhub/init.go
+1
@@ -4,6 +4,7 @@ package dockerhub
4
5
import (
6
"errors"
7
+
8
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
9
)
10
src/go/plugin/go.d/modules/elasticsearch/elasticsearch_test.go
+1
-1
@@ -3,12 +3,12 @@
3
package elasticsearch
4
5
import (
6
- "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
6
"net/http"
7
"net/http/httptest"
8
"os"
9
"testing"
10
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/tlscfg"
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
14
src/go/plugin/go.d/modules/envoy/envoy_test.go
+1
-1
@@ -3,12 +3,12 @@
3
package envoy
4
5
import (
6
- "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
6
"net/http"
7
"net/http/httptest"
8
"os"
9
"testing"
10
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
14
"github.com/stretchr/testify/assert"
src/go/plugin/go.d/modules/example/charts.go
+1
@@ -4,6 +4,7 @@ package example
4
5
import (
6
"fmt"
7
+
8
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
9
)
10
src/go/plugin/go.d/modules/example/init.go
+1
@@ -4,6 +4,7 @@ package example
4
5
import (
6
"errors"
7
+
8
"github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
9
)
10
src/go/plugin/go.d/modules/hdfs/collect.go
+1
-1
@@ -194,7 +194,7 @@ func (h *HDFS) collectDataNodeActivity(mx *metrics, raw rawJMX) error {
194
return nil
195
}
196
197
-func writeJSONTo(dst interface{}, src interface{}) error {
197
+func writeJSONTo(dst, src any) error {
198
b, err := json.Marshal(src)
199
if err != nil {
200
return err
src/go/plugin/go.d/modules/httpcheck/httpcheck_test.go
+2
-2
@@ -3,14 +3,14 @@
3
package httpcheck
4
5
import (
6
- "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
7
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
6
"net/http"
7
"net/http/httptest"
8
"os"
9
"testing"
10
"time"
11
12
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
13
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
14
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
15
16
"github.com/stretchr/testify/assert"
src/go/plugin/go.d/modules/k8s_state/discover_kubernetes.go
+1
-1
@@ -132,7 +132,7 @@ func (d *kubeDiscovery) setupDiscoverers(ctx context.Context) []discoverer {
132
}
133
}
134
135
-func enqueue(queue *workqueue.Type, obj interface{}) {
135
+func enqueue(queue *workqueue.Typed[any], obj any) {
136
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(obj)
137
if err != nil {
138
return
src/go/plugin/go.d/modules/k8s_state/discover_node.go
+8
-7
@@ -16,11 +16,12 @@ func newNodeDiscoverer(si cache.SharedInformer, l *logger.Logger) *nodeDiscovere
16
panic("nil node shared informer")
17
}
18
19
- queue := workqueue.NewWithConfig(workqueue.QueueConfig{Name: "node"})
19
+ queue := workqueue.NewTypedWithConfig(workqueue.TypedQueueConfig[any]{Name: "node"})
20
+
21
_, _ = si.AddEventHandler(cache.ResourceEventHandlerFuncs{
21
- AddFunc: func(obj interface{}) { enqueue(queue, obj) },
22
- UpdateFunc: func(_, obj interface{}) { enqueue(queue, obj) },
23
- DeleteFunc: func(obj interface{}) { enqueue(queue, obj) },
22
+ AddFunc: func(obj any) { enqueue(queue, obj) },
23
+ UpdateFunc: func(_, obj any) { enqueue(queue, obj) },
24
+ DeleteFunc: func(obj any) { enqueue(queue, obj) },
25
})
26
27
return &nodeDiscoverer{
@@ -34,17 +35,17 @@ func newNodeDiscoverer(si cache.SharedInformer, l *logger.Logger) *nodeDiscovere
35
36
type nodeResource struct {
37
src string
37
- val interface{}
38
+ val any
39
}
40
41
func (r nodeResource) source() string { return r.src }
42
func (r nodeResource) kind() kubeResourceKind { return kubeResourceNode }
42
-func (r nodeResource) value() interface{} { return r.val }
43
+func (r nodeResource) value() any { return r.val }
44
45
type nodeDiscoverer struct {
46
*logger.Logger
47
informer cache.SharedInformer
47
- queue *workqueue.Type
48
+ queue *workqueue.Typed[any]
49
readyCh chan struct{}
50
stopCh chan struct{}
51
}
src/go/plugin/go.d/modules/k8s_state/discover_pod.go
+8
-7
@@ -16,11 +16,12 @@ func newPodDiscoverer(si cache.SharedInformer, l *logger.Logger) *podDiscoverer
16
panic("nil pod shared informer")
17
}
18
19
- queue := workqueue.NewWithConfig(workqueue.QueueConfig{Name: "pod"})
19
+ queue := workqueue.NewTypedWithConfig(workqueue.TypedQueueConfig[any]{Name: "pod"})
20
+
21
_, _ = si.AddEventHandler(cache.ResourceEventHandlerFuncs{
21
- AddFunc: func(obj interface{}) { enqueue(queue, obj) },
22
- UpdateFunc: func(_, obj interface{}) { enqueue(queue, obj) },
23
- DeleteFunc: func(obj interface{}) { enqueue(queue, obj) },
22
+ AddFunc: func(obj any) { enqueue(queue, obj) },
23
+ UpdateFunc: func(_, obj any) { enqueue(queue, obj) },
24
+ DeleteFunc: func(obj any) { enqueue(queue, obj) },
25
})
26
27
return &podDiscoverer{
@@ -34,17 +35,17 @@ func newPodDiscoverer(si cache.SharedInformer, l *logger.Logger) *podDiscoverer
35
36
type podResource struct {
37
src string
37
- val interface{}
38
+ val any
39
}
40
41
func (r podResource) source() string { return r.src }
42
func (r podResource) kind() kubeResourceKind { return kubeResourcePod }
42
-func (r podResource) value() interface{} { return r.val }
43
+func (r podResource) value() any { return r.val }
44
45
type podDiscoverer struct {
46
*logger.Logger
47
informer cache.SharedInformer
47
- queue *workqueue.Type
48
+ queue *workqueue.Typed[any]
49
readyCh chan struct{}
50
stopCh chan struct{}
51
}
src/go/plugin/go.d/modules/k8s_state/kube_state_test.go
+12
-12
@@ -51,7 +51,7 @@ func TestKubeState_Init(t *testing.T) {
51
wantFail: false,
52
prepare: func() *KubeState {
53
ks := New()
54
- ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewSimpleClientset(), nil }
54
+ ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewClientset(), nil }
55
return ks
56
},
57
},
@@ -87,7 +87,7 @@ func TestKubeState_Check(t *testing.T) {
87
wantFail: false,
88
prepare: func() *KubeState {
89
ks := New()
90
- ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewSimpleClientset(), nil }
90
+ ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewClientset(), nil }
91
return ks
92
},
93
},
@@ -95,7 +95,7 @@ func TestKubeState_Check(t *testing.T) {
95
wantFail: true,
96
prepare: func() *KubeState {
97
ks := New()
98
- client := &brokenInfoKubeClient{fake.NewSimpleClientset()}
98
+ client := &brokenInfoKubeClient{fake.NewClientset()}
99
ks.newKubeClient = func() (kubernetes.Interface, error) { return client, nil }
100
return ks
101
},
@@ -133,7 +133,7 @@ func TestKubeState_Cleanup(t *testing.T) {
133
doCollect: false,
134
prepare: func() *KubeState {
135
ks := New()
136
- ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewSimpleClientset(), nil }
136
+ ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewClientset(), nil }
137
return ks
138
},
139
},
@@ -142,7 +142,7 @@ func TestKubeState_Cleanup(t *testing.T) {
142
doCollect: false,
143
prepare: func() *KubeState {
144
ks := New()
145
- ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewSimpleClientset(), nil }
145
+ ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewClientset(), nil }
146
return ks
147
},
148
},
@@ -151,7 +151,7 @@ func TestKubeState_Cleanup(t *testing.T) {
151
doCollect: true,
152
prepare: func() *KubeState {
153
ks := New()
154
- ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewSimpleClientset(), nil }
154
+ ks.newKubeClient = func() (kubernetes.Interface, error) { return fake.NewClientset(), nil }
155
return ks
156
},
157
},
@@ -192,7 +192,7 @@ func TestKubeState_Collect(t *testing.T) {
192
}{
193
"Node only": {
194
create: func(t *testing.T) testCase {
195
- client := fake.NewSimpleClientset(
195
+ client := fake.NewClientset(
196
newNode("node01"),
197
)
198
@@ -257,7 +257,7 @@ func TestKubeState_Collect(t *testing.T) {
257
"Pod only": {
258
create: func(t *testing.T) testCase {
259
pod := newPod("node01", "pod01")
260
- client := fake.NewSimpleClientset(
260
+ client := fake.NewClientset(
261
pod,
262
)
263
@@ -317,7 +317,7 @@ func TestKubeState_Collect(t *testing.T) {
317
create: func(t *testing.T) testCase {
318
node := newNode("node01")
319
pod := newPod(node.Name, "pod01")
320
- client := fake.NewSimpleClientset(
320
+ client := fake.NewClientset(
321
node,
322
pod,
323
)
@@ -417,7 +417,7 @@ func TestKubeState_Collect(t *testing.T) {
417
ctx := context.Background()
418
node := newNode("node01")
419
pod := newPod(node.Name, "pod01")
420
- client := fake.NewSimpleClientset(
420
+ client := fake.NewClientset(
421
node,
422
pod,
423
)
@@ -495,7 +495,7 @@ func TestKubeState_Collect(t *testing.T) {
495
node := newNode("node01")
496
podOrig := newPod(node.Name, "pod01")
497
podOrig.Spec.NodeName = ""
498
- client := fake.NewSimpleClientset(
498
+ client := fake.NewClientset(
499
node,
500
podOrig,
501
)
@@ -535,7 +535,7 @@ func TestKubeState_Collect(t *testing.T) {
535
node := newNode("node01")
536
pod1 := newPod(node.Name, "pod01")
537
pod2 := newPod(node.Name, "pod02")
538
- client := fake.NewSimpleClientset(
538
+ client := fake.NewClientset(
539
node,
540
pod1,
541
)
src/go/plugin/go.d/modules/k8s_state/resource.go
+3
-3
@@ -11,7 +11,7 @@ import (
11
type resource interface {
12
source() string
13
kind() kubeResourceKind
14
- value() interface{}
14
+ value() any
15
}
16
17
type kubeResourceKind uint8
@@ -21,7 +21,7 @@ const (
21
kubeResourcePod
22
)
23
24
-func toNode(i interface{}) (*corev1.Node, error) {
24
+func toNode(i any) (*corev1.Node, error) {
25
switch v := i.(type) {
26
case *corev1.Node:
27
return v, nil
@@ -32,7 +32,7 @@ func toNode(i interface{}) (*corev1.Node, error) {
32
}
33
}
34
35
-func toPod(i interface{}) (*corev1.Pod, error) {
35
+func toPod(i any) (*corev1.Pod, error) {
36
switch v := i.(type) {
37
case *corev1.Pod:
38
return v, nil
src/go/plugin/go.d/modules/logstash/logstash_test.go
+1
-1
@@ -3,12 +3,12 @@
3
package logstash
4
5
import (
6
- "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
6
"net/http"
7
"net/http/httptest"
8
"os"
9
"testing"
10
11
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/web"
13
14
"github.com/stretchr/testify/assert"
src/go/plugin/go.d/modules/mongodb/documents.go
+1
-1
@@ -20,7 +20,7 @@ type documentServerStatus struct {
20
Tcmalloc *documentTCMallocStatus `bson:"tcmalloc" stm:"tcmalloc"`
21
Locks *documentLocks `bson:"locks" stm:"locks"`
22
WiredTiger *documentWiredTiger `bson:"wiredTiger" stm:"wiredtiger"`
23
- Repl interface{} `bson:"repl"`
23
+ Repl any `bson:"repl"`
24
}
25
26
type (
src/go/plugin/go.d/modules/nginxvts/collect.go
+4
-4
@@ -13,7 +13,7 @@ func (vts *NginxVTS) collect() (map[string]int64, error) {
13
return nil, nil
14
}
15
16
- collected := make(map[string]interface{})
16
+ collected := make(map[string]any)
17
vts.collectMain(collected, ms)
18
vts.collectSharedZones(collected, ms)
19
vts.collectServerZones(collected, ms)
@@ -21,16 +21,16 @@ func (vts *NginxVTS) collect() (map[string]int64, error) {
21
return stm.ToMap(collected), nil
22
}
23
24
-func (vts *NginxVTS) collectMain(collected map[string]interface{}, ms *vtsMetrics) {
24
+func (vts *NginxVTS) collectMain(collected map[string]any, ms *vtsMetrics) {
25
collected["uptime"] = (ms.NowMsec - ms.LoadMsec) / 1000
26
collected["connections"] = ms.Connections
27
}
28
29
-func (vts *NginxVTS) collectSharedZones(collected map[string]interface{}, ms *vtsMetrics) {
29
+func (vts *NginxVTS) collectSharedZones(collected map[string]any, ms *vtsMetrics) {
30
collected["sharedzones"] = ms.SharedZones
31
}
32
33
-func (vts *NginxVTS) collectServerZones(collected map[string]interface{}, ms *vtsMetrics) {
33
+func (vts *NginxVTS) collectServerZones(collected map[string]any, ms *vtsMetrics) {
34
if !ms.hasServerZones() {
35
return
36
}
src/go/plugin/go.d/modules/openvpn/client/client_test.go
+1
@@ -11,6 +11,7 @@ import (
11
"testing"
12
13
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/socket"
14
+
15
"github.com/stretchr/testify/assert"
16
)
17
src/go/plugin/go.d/modules/openvpn_status_log/init.go
+1
@@ -4,6 +4,7 @@ package openvpn_status_log
4
5
import (
6
"errors"
7
+
8
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
9
)
10
src/go/plugin/go.d/modules/phpfpm/collect.go
+6
-6
@@ -49,7 +49,7 @@ func hasIdleProcesses(processes []proc) bool {
49
type accessor func(p proc) int64
50
51
func statProcesses(m map[string]int64, processes []proc, met string, acc accessor) {
52
- var sum, count, min, max int64
52
+ var sum, count, minv, maxv int64
53
for _, proc := range processes {
54
if proc.State != "Idle" {
55
continue
@@ -59,14 +59,14 @@ func statProcesses(m map[string]int64, processes []proc, met string, acc accesso
59
sum += val
60
count += 1
61
if count == 1 {
62
- min, max = val, val
62
+ minv, maxv = val, val
63
continue
64
}
65
- min = int64(math.Min(float64(min), float64(val)))
66
- max = int64(math.Max(float64(max), float64(val)))
65
+ minv = int64(math.Min(float64(minv), float64(val)))
66
+ maxv = int64(math.Max(float64(maxv), float64(val)))
67
}
68
69
- m["min"+met] = min
70
- m["max"+met] = max
69
+ m["min"+met] = minv
70
+ m["max"+met] = maxv
71
m["avg"+met] = sum / count
72
}
src/go/plugin/go.d/modules/powerdns/metrics.go
+1
-1
@@ -8,6 +8,6 @@ type (
8
statisticMetric struct {
9
Name string
10
Type string
11
- Value interface{}
11
+ Value any
12
}
13
)
src/go/plugin/go.d/modules/powerdns_recursor/metrics.go
+1
-1
@@ -13,6 +13,6 @@ type (
13
statisticMetric struct {
14
Name string
15
Type string
16
- Value interface{}
16
+ Value any
17
}
18
)
src/go/plugin/go.d/modules/rabbitmq/collect.go
+1
-1
@@ -80,7 +80,7 @@ func (r *RabbitMQ) collectNodeStats(mx map[string]int64) error {
80
for k, v := range stm.ToMap(stats) {
81
mx[k] = v
82
}
83
- mx["proc_available"] = int64(stats.ProcTotal - stats.ProcUsed)
83
+ mx["proc_available"] = stats.ProcTotal - stats.ProcUsed
84
85
return nil
86
}
src/go/plugin/go.d/modules/redis/collect.go
+2
-1
@@ -7,9 +7,10 @@ import (
7
"context"
8
"errors"
9
"fmt"
10
- "github.com/blang/semver/v4"
10
"regexp"
11
"strings"
12
+
13
+ "github.com/blang/semver/v4"
14
)
15
16
const precision = 1000 // float values multiplier and dimensions divisor
src/go/plugin/go.d/modules/scaleio/client/client.go
+1
-1
@@ -246,7 +246,7 @@ func (c *Client) doOKWithRetry(req web.RequestConfig) (*http.Response, error) {
246
return resp, err
247
}
248
249
-func (c *Client) doJSONWithRetry(dst interface{}, req web.RequestConfig) error {
249
+func (c *Client) doJSONWithRetry(dst any, req web.RequestConfig) error {
250
resp, err := c.doOKWithRetry(req)
251
defer web.CloseBody(resp)
252
if err != nil {
src/go/plugin/go.d/modules/sensors/lmsensors/scanner_test.go
+1
-1
@@ -804,7 +804,7 @@ func (fi *memoryDirEntry) Name() string { return fi.name }
804
func (fi *memoryDirEntry) Type() os.FileMode { return fi.mode }
805
func (fi *memoryDirEntry) IsDir() bool { return fi.isDir }
806
func (fi *memoryDirEntry) Info() (fs.FileInfo, error) { return fi, nil }
807
-func (fi *memoryDirEntry) Sys() interface{} { return nil }
807
+func (fi *memoryDirEntry) Sys() any { return nil }
808
func (fi *memoryDirEntry) Size() int64 { return 0 }
809
func (fi *memoryDirEntry) Mode() os.FileMode { return fi.Type() }
810
func (fi *memoryDirEntry) ModTime() time.Time { return time.Now() }
src/go/plugin/go.d/modules/snmp/init.go
+1
-1
@@ -8,9 +8,9 @@ import (
8
"strings"
9
"time"
10
11
- "github.com/google/uuid"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/matcher"
12
13
+ "github.com/google/uuid"
14
"github.com/gosnmp/gosnmp"
15
)
16
src/go/plugin/go.d/modules/squid/squid_test.go
+2
-2
@@ -187,7 +187,7 @@ Fusce et felis pulvinar, posuere sem non, porttitor eros.`)
187
188
srv := httptest.NewServer(http.HandlerFunc(
189
func(w http.ResponseWriter, r *http.Request) {
190
- _, _ = w.Write([]byte(resp))
190
+ _, _ = w.Write(resp)
191
}))
192
193
squid := New()
@@ -203,7 +203,7 @@ func prepareCaseEmptyResponse(t *testing.T) (*Squid, func()) {
203
204
srv := httptest.NewServer(http.HandlerFunc(
205
func(w http.ResponseWriter, r *http.Request) {
206
- _, _ = w.Write([]byte(resp))
206
+ _, _ = w.Write(resp)
207
}))
208
209
squid := New()
src/go/plugin/go.d/modules/squidlog/squidlog_test.go
+1
-1
@@ -7,10 +7,10 @@ import (
7
"os"
8
"testing"
9
10
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/logs"
12
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/metrics"
13
13
- "github.com/netdata/netdata/go/plugins/plugin/go.d/agent/module"
14
"github.com/stretchr/testify/assert"
15
"github.com/stretchr/testify/require"
16
)
src/go/plugin/go.d/modules/supervisord/client.go
+1
-1
@@ -66,7 +66,7 @@ func (c *supervisorRPCClient) closeIdleConnections() {
66
c.client.HttpClient.CloseIdleConnections()
67
}
68
69
-func parseGetAllProcessInfo(resp interface{}) ([]processStatus, error) {
69
+func parseGetAllProcessInfo(resp any) ([]processStatus, error) {
70
arr, ok := resp.(xmlrpc.Array)
71
if !ok {
72
return nil, fmt.Errorf("unexpected response type, want=xmlrpc.Array, got=%T", resp)
src/go/plugin/go.d/modules/vcsa/client/client.go
+1
-1
@@ -190,7 +190,7 @@ func (c *Client) doOK(req web.RequestConfig) (*http.Response, error) {
190
return resp, nil
191
}
192
193
-func (c *Client) doOKWithDecode(req web.RequestConfig, dst interface{}) error {
193
+func (c *Client) doOKWithDecode(req web.RequestConfig, dst any) error {
194
resp, err := c.doOK(req)
195
defer web.CloseBody(resp)
196
if err != nil {
src/go/plugin/go.d/modules/vsphere/discover/discover.go
+1
-1
@@ -7,10 +7,10 @@ import (
7
"strings"
8
"time"
9
10
+ "github.com/netdata/netdata/go/plugins/logger"
11
"github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/match"
12
rs "github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/resources"
13
13
- "github.com/netdata/netdata/go/plugins/logger"
14
"github.com/vmware/govmomi/vim25/mo"
15
"github.com/vmware/govmomi/vim25/types"
16
)
src/go/plugin/go.d/modules/vsphere/scrape/scrape.go
+1
-1
@@ -9,9 +9,9 @@ import (
9
"sync"
10
"time"
11
12
+ "github.com/netdata/netdata/go/plugins/logger"
13
rs "github.com/netdata/netdata/go/plugins/plugin/go.d/modules/vsphere/resources"
14
14
- "github.com/netdata/netdata/go/plugins/logger"
15
"github.com/vmware/govmomi/performance"
16
"github.com/vmware/govmomi/vim25/types"
17
)
src/go/plugin/go.d/modules/vsphere/scrape/throttled_caller_test.go
+4
-4
@@ -13,7 +13,7 @@ import (
13
14
func Test_throttledCaller(t *testing.T) {
15
var current int64
16
- var max int64
16
+ var maxv int64
17
var total int64
18
var mux sync.Mutex
19
limit := 5
@@ -28,8 +28,8 @@ func Test_throttledCaller(t *testing.T) {
28
29
mux.Lock()
30
defer mux.Unlock()
31
- if atomic.LoadInt64(¤t) > max {
32
- max = atomic.LoadInt64(¤t)
31
+ if atomic.LoadInt64(¤t) > maxv {
32
+ maxv = atomic.LoadInt64(¤t)
33
}
34
atomic.AddInt64(¤t, -1)
35
}
@@ -38,5 +38,5 @@ func Test_throttledCaller(t *testing.T) {
38
tc.wait()
39
40
assert.Equal(t, int64(n), total)
41
- assert.Equal(t, max, int64(limit))
41
+ assert.Equal(t, maxv, int64(limit))
42
}
src/go/plugin/go.d/modules/w1sensor/collect.go
+1
-1
@@ -72,7 +72,7 @@ func readW1sensorTemperature(filename string) (int64, error) {
72
if err != nil {
73
return 0, err
74
}
75
- defer file.Close()
75
+ defer func() { _ = file.Close() }()
76
77
sc := bufio.NewScanner(file)
78
sc.Scan()
src/go/plugin/go.d/modules/zookeeper/fetcher_test.go
+1
@@ -6,6 +6,7 @@ import (
6
"testing"
7
8
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/socket"
9
+
10
"github.com/stretchr/testify/assert"
11
)
12
src/go/plugin/go.d/pkg/confopt/duration.go
+1
-1
@@ -19,7 +19,7 @@ func (d Duration) String() string {
19
return d.Duration().String()
20
}
21
22
-func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error {
22
+func (d *Duration) UnmarshalYAML(unmarshal func(any) error) error {
23
var s string
24
25
if err := unmarshal(&s); err != nil {
src/go/plugin/go.d/pkg/dockerhost/dockerhost.go
+1
-1
@@ -41,7 +41,7 @@ func Exec(ctx context.Context, container string, cmd string, args ...string) ([]
41
return nil, fmt.Errorf("failed to create docker client: %v", err)
42
}
43
44
- defer cli.Close()
44
+ defer func() { _ = cli.Close() }()
45
46
cli.NegotiateAPIVersion(ctx)
47
src/go/plugin/go.d/pkg/k8sclient/k8sclient.go
+1
-1
@@ -27,7 +27,7 @@ func New(userAgent string) (kubernetes.Interface, error) {
27
28
switch {
29
case os.Getenv(EnvFakeClient) != "":
30
- return fake.NewSimpleClientset(), nil
30
+ return fake.NewClientset(), nil
31
case os.Getenv("KUBERNETES_SERVICE_HOST") != "" && os.Getenv("KUBERNETES_SERVICE_PORT") != "":
32
return newInCluster(userAgent)
33
default:
src/go/plugin/go.d/pkg/metrics/unique_counter.go
+2
-1
@@ -3,8 +3,9 @@
3
package metrics
4
5
import (
6
- "github.com/axiomhq/hyperloglog"
6
"github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/stm"
7
+
8
+ "github.com/axiomhq/hyperloglog"
9
)
10
11
type (
src/go/plugin/go.d/pkg/prometheus/client.go
+1
-1
@@ -103,7 +103,7 @@ func (p *prometheus) fetch(w io.Writer) error {
103
if err != nil {
104
return err
105
}
106
- defer f.Close()
106
+ defer func() { _ = f.Close() }()
107
108
_, err = io.Copy(w, f)
109
src/go/plugin/go.d/pkg/prometheus/metric_series.go
+4
-4
@@ -100,11 +100,11 @@ func (s Series) Max() float64 {
100
case 1:
101
return s[0].Value
102
}
103
- max := s[0].Value
103
+ maxv := s[0].Value
104
for _, kv := range s[1:] {
105
- if max < kv.Value {
106
- max = kv.Value
105
+ if maxv < kv.Value {
106
+ maxv = kv.Value
107
}
108
}
109
- return max
109
+ return maxv
110
}
src/go/plugin/go.d/pkg/stm/stm.go
+1
-1
@@ -22,7 +22,7 @@ type (
22
)
23
24
// ToMap converts struct to a map[string]int64 based on 'stm' tags
25
-func ToMap(s ...interface{}) map[string]int64 {
25
+func ToMap(s ...any) map[string]int64 {
26
rv := map[string]int64{}
27
for _, v := range s {
28
value := reflect.Indirect(reflect.ValueOf(v))
src/go/plugin/go.d/pkg/stm/stm_test.go
+5
-5
@@ -171,14 +171,14 @@ func TestToMap_map(t *testing.T) {
171
172
func TestToMap_nestMap(t *testing.T) {
173
s := struct {
174
- I int `stm:"int"`
175
- M map[string]interface{} `stm:""`
174
+ I int `stm:"int"`
175
+ M map[string]any `stm:""`
176
}{
177
I: 1,
178
- M: map[string]interface{}{
178
+ M: map[string]any{
179
"a": 2,
180
"b": 3,
181
- "m": map[string]interface{}{
181
+ "m": map[string]any{
182
"c": 4,
183
},
184
},
@@ -352,7 +352,7 @@ func TestToMap_bool(t *testing.T) {
352
}
353
354
func TestToMap_ArraySlice(t *testing.T) {
355
- s := [4]interface{}{
355
+ s := [4]any{
356
map[string]int{
357
"B": 1,
358
"C": 2,
src/go/plugin/go.d/pkg/web/client_config_test.go
+2
-1
@@ -3,11 +3,12 @@
3
package web
4
5
import (
6
- "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
6
"net/http"
7
"testing"
8
"time"
9
10
+ "github.com/netdata/netdata/go/plugins/plugin/go.d/pkg/confopt"
11
+
12
"github.com/stretchr/testify/assert"
13
)
14