go.d fix some JB code inspection issues (#17702)
Ilya Mashchenko committed
May 19, 2024 at 21:43 UTC
011d15a626fdbe817f826b6f2916b5310de16c2b
23 files changed
+68
-58
src/collectors/perf.plugin/metadata.yaml
+1
-1
@@ -30,7 +30,7 @@ modules:
30
exclude: []
31
multi_instance: true
32
additional_permissions:
33
- description: "It needs setuid to use the necessary syscall to collect perf events. Netdada sets the permission during installation time."
33
+ description: "It needs setuid to use the necessary syscall to collect perf events. Netdata sets the permission during installation time."
34
default_behavior:
35
auto_detection:
36
description: ""
src/go/collectors/go.d.plugin/agent/confgroup/cache.go
+1
-1
@@ -85,7 +85,7 @@ func (c *Cache) addNotEmpty(group *Group) (added, removed []Config) {
85
}
86
}
87
88
- if ok && len(set) == 0 {
88
+ if len(set) == 0 {
89
delete(c.sources, group.Source)
90
}
91
src/go/collectors/go.d.plugin/examples/simple/main.go
+8
-6
@@ -21,15 +21,17 @@ import (
21
22
var version = "v0.0.1-example"
23
24
-type example struct{ module.Base }
24
+type example struct {
25
+ module.Base
26
+}
27
26
-func (example) Cleanup() {}
28
+func (e *example) Cleanup() {}
29
28
-func (example) Init() error { return nil }
30
+func (e *example) Init() error { return nil }
31
30
-func (example) Check() error { return nil }
32
+func (e *example) Check() error { return nil }
33
32
-func (example) Charts() *module.Charts {
34
+func (e *example) Charts() *module.Charts {
35
return &module.Charts{
36
{
37
ID: "random",
@@ -41,7 +43,7 @@ func (example) Charts() *module.Charts {
43
},
44
}
45
}
44
-func (example) Configuration() any { return nil }
46
+func (e *example) Configuration() any { return nil }
47
48
func (e *example) Collect() map[string]int64 {
49
return map[string]int64{
src/go/collectors/go.d.plugin/modules/dnsquery/init.go
+1
-1
@@ -50,7 +50,7 @@ func (d *DNSQuery) initRecordTypes() (map[string]uint16, error) {
50
}
51
52
func (d *DNSQuery) initCharts() (*module.Charts, error) {
53
- var charts module.Charts
53
+ charts := module.Charts{}
54
55
for _, srv := range d.Servers {
56
for _, rtype := range d.RecordTypes {
src/go/collectors/go.d.plugin/modules/haproxy/init.go
+2
-2
@@ -10,7 +10,7 @@ import (
10
"github.com/netdata/netdata/go/go.d.plugin/pkg/web"
11
)
12
13
-func (h Haproxy) validateConfig() error {
13
+func (h *Haproxy) validateConfig() error {
14
if h.URL == "" {
15
return errors.New("'url' is not set")
16
}
@@ -20,7 +20,7 @@ func (h Haproxy) validateConfig() error {
20
return nil
21
}
22
23
-func (h Haproxy) initPrometheusClient() (prometheus.Prometheus, error) {
23
+func (h *Haproxy) initPrometheusClient() (prometheus.Prometheus, error) {
24
httpClient, err := web.NewHTTPClient(h.Client)
25
if err != nil {
26
return nil, err
src/go/collectors/go.d.plugin/modules/k8s_state/init.go
+1
-1
@@ -6,7 +6,7 @@ import (
6
"k8s.io/client-go/kubernetes"
7
)
8
9
-func (ks KubeState) initClient() (kubernetes.Interface, error) {
9
+func (ks *KubeState) initClient() (kubernetes.Interface, error) {
10
return ks.newKubeClient()
11
}
12
src/go/collectors/go.d.plugin/modules/k8s_state/state.go
+1
-1
@@ -101,7 +101,7 @@ type (
101
}
102
)
103
104
-func (ns nodeState) id() string { return ns.name }
104
+func (ns *nodeState) id() string { return ns.name }
105
func (ns *nodeState) resetStats() { ns.stats = nodeStateStats{} }
106
107
type (
src/go/collectors/go.d.plugin/modules/openvpn/client/client_test.go
+5
@@ -75,6 +75,7 @@ func (m *mockSocketClient) Disconnect() error { return nil }
75
76
func (m *mockSocketClient) Command(command string, process socket.Processor) error {
77
var s *bufio.Scanner
78
+
79
switch command {
80
default:
81
return fmt.Errorf("unknown command : %s", command)
@@ -91,6 +92,10 @@ func (m *mockSocketClient) Command(command string, process socket.Processor) err
92
s = bufio.NewScanner(bytes.NewReader(testLoadStatsData))
93
}
94
95
+ if s == nil {
96
+ return nil
97
+ }
98
+
99
for s.Scan() {
100
process(s.Bytes())
101
}
src/go/collectors/go.d.plugin/modules/phpdaemon/client.go
+1
-1
@@ -56,7 +56,7 @@ func (c *client) doWithDecode(dst interface{}, decode decodeFunc, request web.Re
56
return nil
57
}
58
59
-func (c client) doOK(req *http.Request) (*http.Response, error) {
59
+func (c *client) doOK(req *http.Request) (*http.Response, error) {
60
resp, err := c.httpClient.Do(req)
61
if err != nil {
62
return resp, fmt.Errorf("error on request : %v", err)
src/go/collectors/go.d.plugin/modules/pika/pika_test.go
+1
-1
@@ -284,7 +284,7 @@ type mockRedisClient struct {
284
calledClose bool
285
}
286
287
-func (m mockRedisClient) Info(_ context.Context, _ ...string) (cmd *redis.StringCmd) {
287
+func (m *mockRedisClient) Info(_ context.Context, _ ...string) (cmd *redis.StringCmd) {
288
if m.errOnInfo {
289
cmd = redis.NewStringResult("", errors.New("error on Info"))
290
} else {
src/go/collectors/go.d.plugin/modules/portcheck/init.go
+1
-1
@@ -30,7 +30,7 @@ func (pc *PortCheck) validateConfig() error {
30
}
31
32
func (pc *PortCheck) initCharts() (*module.Charts, error) {
33
- var charts module.Charts
33
+ charts := module.Charts{}
34
35
for _, port := range pc.Ports {
36
if err := charts.Add(*newPortCharts(pc.Host, port)...); err != nil {
src/go/collectors/go.d.plugin/modules/scaleio/client/client.go
+6
-6
@@ -94,7 +94,7 @@ type Client struct {
94
}
95
96
// LoggedIn reports whether the client is logged in.
97
-func (c Client) LoggedIn() bool {
97
+func (c *Client) LoggedIn() bool {
98
return c.token.isSet()
99
}
100
@@ -160,7 +160,7 @@ func (c *Client) Instances() (Instances, error) {
160
return instances, err
161
}
162
163
-func (c Client) createLoginRequest() web.Request {
163
+func (c *Client) createLoginRequest() web.Request {
164
req := c.Request.Copy()
165
u, _ := url.Parse(req.URL)
166
u.Path = path.Join(u.Path, "/api/login")
@@ -168,7 +168,7 @@ func (c Client) createLoginRequest() web.Request {
168
return req
169
}
170
171
-func (c Client) createLogoutRequest() web.Request {
171
+func (c *Client) createLogoutRequest() web.Request {
172
req := c.Request.Copy()
173
u, _ := url.Parse(req.URL)
174
u.Path = path.Join(u.Path, "/api/logout")
@@ -177,7 +177,7 @@ func (c Client) createLogoutRequest() web.Request {
177
return req
178
}
179
180
-func (c Client) createAPIVersionRequest() web.Request {
180
+func (c *Client) createAPIVersionRequest() web.Request {
181
req := c.Request.Copy()
182
u, _ := url.Parse(req.URL)
183
u.Path = path.Join(u.Path, "/api/version")
@@ -186,7 +186,7 @@ func (c Client) createAPIVersionRequest() web.Request {
186
return req
187
}
188
189
-func (c Client) createSelectedStatisticsRequest(query []byte) web.Request {
189
+func (c *Client) createSelectedStatisticsRequest(query []byte) web.Request {
190
req := c.Request.Copy()
191
u, _ := url.Parse(req.URL)
192
u.Path = path.Join(u.Path, "/api/instances/querySelectedStatistics")
@@ -200,7 +200,7 @@ func (c Client) createSelectedStatisticsRequest(query []byte) web.Request {
200
return req
201
}
202
203
-func (c Client) createInstancesRequest() web.Request {
203
+func (c *Client) createInstancesRequest() web.Request {
204
req := c.Request.Copy()
205
u, _ := url.Parse(req.URL)
206
u.Path = path.Join(u.Path, "/api/instances")
src/go/collectors/go.d.plugin/modules/supervisord/supervisord_test.go
+1
-1
@@ -230,7 +230,7 @@ type mockSupervisorClient struct {
230
calledCloseIdleConnections bool
231
}
232
233
-func (m mockSupervisorClient) getAllProcessInfo() ([]processStatus, error) {
233
+func (m *mockSupervisorClient) getAllProcessInfo() ([]processStatus, error) {
234
if m.errOnGetAllProcessInfo {
235
return nil, errors.New("mock errOnGetAllProcessInfo")
236
}
src/go/collectors/go.d.plugin/modules/traefik/collect.go
+1
-1
@@ -173,7 +173,7 @@ func (t *Traefik) collectEntrypointOpenConnections(mx map[string]int64, pms prom
173
174
var httpRespCodeClasses = []string{"1xx", "2xx", "3xx", "4xx", "5xx"}
175
176
-func (t Traefik) updateCodeClassMetrics(mx map[string]int64) {
176
+func (t *Traefik) updateCodeClassMetrics(mx map[string]int64) {
177
for id, ce := range t.cache.entrypoints {
178
if ce.requests != nil {
179
for _, c := range httpRespCodeClasses {
src/go/collectors/go.d.plugin/modules/traefik/init.go
+2
-2
@@ -10,14 +10,14 @@ import (
10
"github.com/netdata/netdata/go/go.d.plugin/pkg/web"
11
)
12
13
-func (t Traefik) validateConfig() error {
13
+func (t *Traefik) validateConfig() error {
14
if t.URL == "" {
15
return errors.New("'url' is not set")
16
}
17
return nil
18
}
19
20
-func (t Traefik) initPrometheusClient() (prometheus.Prometheus, error) {
20
+func (t *Traefik) initPrometheusClient() (prometheus.Prometheus, error) {
21
httpClient, err := web.NewHTTPClient(t.Client)
22
if err != nil {
23
return nil, err
src/go/collectors/go.d.plugin/modules/traefik/traefik.go
+1
-1
@@ -127,4 +127,4 @@ func (t *Traefik) Collect() map[string]int64 {
127
return mx
128
}
129
130
-func (Traefik) Cleanup() {}
130
+func (t *Traefik) Cleanup() {}
src/go/collectors/go.d.plugin/modules/vsphere/match/match.go
+1
@@ -167,6 +167,7 @@ func parseHostInclude(include string) (HostMatcher, error) {
167
ms = append(ms, hostClusterMatcher{m})
168
case hostIdx:
169
ms = append(ms, hostHostMatcher{m})
170
+ default:
171
}
172
}
173
src/go/collectors/go.d.plugin/modules/vsphere/resources/resources.go
+1
-1
@@ -108,7 +108,7 @@ type (
108
}
109
)
110
111
-func (v HierarchyValue) IsSet() bool { return v.ID != "" && v.Name != "" }
111
+func (v *HierarchyValue) IsSet() bool { return v.ID != "" && v.Name != "" }
112
func (v *HierarchyValue) Set(id, name string) { v.ID = id; v.Name = name }
113
114
func (h ClusterHierarchy) IsSet() bool { return h.DC.IsSet() }
src/go/collectors/go.d.plugin/modules/vsphere/scrape/scrape.go
+16
-16
@@ -34,20 +34,20 @@ type Scraper struct {
34
}
35
36
// Default settings for vCenter 6.5 and above is 256, prior versions of vCenter have this set to 64.
37
-func (c *Scraper) calcMaxQuery() {
38
- major, minor, err := parseVersion(c.Version())
37
+func (s *Scraper) calcMaxQuery() {
38
+ major, minor, err := parseVersion(s.Version())
39
if err != nil || major < 6 || minor == 0 {
40
- c.maxQuery = 64
40
+ s.maxQuery = 64
41
return
42
}
43
- c.maxQuery = 256
43
+ s.maxQuery = 256
44
}
45
46
-func (c Scraper) ScrapeHosts(hosts rs.Hosts) []performance.EntityMetric {
46
+func (s *Scraper) ScrapeHosts(hosts rs.Hosts) []performance.EntityMetric {
47
t := time.Now()
48
pqs := newHostsPerfQuerySpecs(hosts)
49
- ms := c.scrapeMetrics(pqs)
50
- c.Debugf("scraping : scraped metrics for %d/%d hosts, process took %s",
49
+ ms := s.scrapeMetrics(pqs)
50
+ s.Debugf("scraping : scraped metrics for %d/%d hosts, process took %s",
51
len(ms),
52
len(hosts),
53
time.Since(t),
@@ -55,11 +55,11 @@ func (c Scraper) ScrapeHosts(hosts rs.Hosts) []performance.EntityMetric {
55
return ms
56
}
57
58
-func (c Scraper) ScrapeVMs(vms rs.VMs) []performance.EntityMetric {
58
+func (s *Scraper) ScrapeVMs(vms rs.VMs) []performance.EntityMetric {
59
t := time.Now()
60
pqs := newVMsPerfQuerySpecs(vms)
61
- ms := c.scrapeMetrics(pqs)
62
- c.Debugf("scraping : scraped metrics for %d/%d vms, process took %s",
61
+ ms := s.scrapeMetrics(pqs)
62
+ s.Debugf("scraping : scraped metrics for %d/%d vms, process took %s",
63
len(ms),
64
len(vms),
65
time.Since(t),
@@ -67,16 +67,16 @@ func (c Scraper) ScrapeVMs(vms rs.VMs) []performance.EntityMetric {
67
return ms
68
}
69
70
-func (c Scraper) scrapeMetrics(pqs []types.PerfQuerySpec) []performance.EntityMetric {
70
+func (s *Scraper) scrapeMetrics(pqs []types.PerfQuerySpec) []performance.EntityMetric {
71
tc := newThrottledCaller(5)
72
var ms []performance.EntityMetric
73
lock := &sync.Mutex{}
74
75
- chunks := chunkify(pqs, c.maxQuery)
75
+ chunks := chunkify(pqs, s.maxQuery)
76
for _, chunk := range chunks {
77
pqs := chunk
78
job := func() {
79
- c.scrape(&ms, lock, pqs)
79
+ s.scrape(&ms, lock, pqs)
80
}
81
tc.call(job)
82
}
@@ -85,10 +85,10 @@ func (c Scraper) scrapeMetrics(pqs []types.PerfQuerySpec) []performance.EntityMe
85
return ms
86
}
87
88
-func (c Scraper) scrape(metrics *[]performance.EntityMetric, lock *sync.Mutex, pqs []types.PerfQuerySpec) {
89
- m, err := c.PerformanceMetrics(pqs)
88
+func (s *Scraper) scrape(metrics *[]performance.EntityMetric, lock *sync.Mutex, pqs []types.PerfQuerySpec) {
89
+ m, err := s.PerformanceMetrics(pqs)
90
if err != nil {
91
- c.Error(err)
91
+ s.Error(err)
92
return
93
}
94
src/go/collectors/go.d.plugin/modules/x509check/collect.go
+5
-3
@@ -43,10 +43,12 @@ func (x *X509Check) collectRevocation(mx map[string]int64, certs []*x509.Certifi
43
if err != nil {
44
x.Debug(err)
45
}
46
- switch {
47
- case ok && rev:
46
+ if !ok {
47
+ return
48
+ }
49
+ if rev {
50
mx["revoked"] = 1
49
- case ok && !rev:
51
+ } else {
52
mx["revoked"] = 0
53
}
54
}
src/go/collectors/go.d.plugin/pkg/logs/reader.go
+3
-3
@@ -89,10 +89,10 @@ func (r *Reader) open() error {
89
func (r *Reader) Read(p []byte) (n int, err error) {
90
n, err = r.file.Read(p)
91
if err != nil {
92
- switch err {
93
- case io.EOF:
92
+ switch {
93
+ case err == io.EOF:
94
err = r.handleEOFErr()
95
- case os.ErrInvalid: // r.file is nil after Close
95
+ case errors.Is(err, os.ErrInvalid): // r.file is nil after Close
96
err = r.handleInvalidArgErr()
97
}
98
return
src/go/collectors/go.d.plugin/pkg/matcher/simple_patterns.go
+1
-1
@@ -18,7 +18,7 @@ type (
18
19
// NewSimplePatternsMatcher creates new simple patterns. It returns error in case one of patterns has bad syntax.
20
func NewSimplePatternsMatcher(expr string) (Matcher, error) {
21
- var ps simplePatternsMatcher
21
+ ps := simplePatternsMatcher{}
22
23
for _, pattern := range strings.Fields(expr) {
24
if err := ps.add(pattern); err != nil {
src/go/collectors/go.d.plugin/pkg/matcher/string.go
+7
-7
@@ -23,16 +23,16 @@ type (
23
24
// NewStringMatcher create a new matcher with string format
25
func NewStringMatcher(s string, startWith, endWith bool) (Matcher, error) {
26
- switch {
27
- case startWith && endWith:
28
- return stringFullMatcher(s), nil
29
- case startWith && !endWith:
26
+ if startWith {
27
+ if endWith {
28
+ return stringFullMatcher(s), nil
29
+ }
30
return stringPrefixMatcher(s), nil
31
- case !startWith && endWith:
31
+ }
32
+ if endWith {
33
return stringSuffixMatcher(s), nil
33
- default:
34
- return stringPartialMatcher(s), nil
34
}
35
+ return stringPartialMatcher(s), nil
36
}
37
38
func (m stringFullMatcher) Match(b []byte) bool { return string(m) == string(b) }