Skip to content

Commit 8729c16

Browse files
authored
[chore] Enable exhaustive linter for several modules (open-telemetry#23329)
Updates open-telemetry#23266 - receiver/nsxt - receiver/snmp - connector/count - extension/storage - pkg/stanza
1 parent 52d87f8 commit 8729c16

File tree

10 files changed

+44
-58
lines changed

10 files changed

+44
-58
lines changed

.golangci.yml

-15
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,6 @@ issues:
182182
- path: kubeletstatsreceiver
183183
linters:
184184
- exhaustive
185-
- path: nsxtreceiver
186-
linters:
187-
- exhaustive
188185
- path: podmanreceiver
189186
linters:
190187
- exhaustive
@@ -194,9 +191,6 @@ issues:
194191
- path: receivercreator
195192
linters:
196193
- exhaustive
197-
- path: snmpreceiver
198-
linters:
199-
- exhaustive
200194
- path: statsdreceiver
201195
linters:
202196
- exhaustive
@@ -314,12 +308,6 @@ issues:
314308
- path: k8sobserver
315309
linters:
316310
- exhaustive
317-
- path: countconnector
318-
linters:
319-
- exhaustive
320-
- path: storage
321-
linters:
322-
- exhaustive
323311
- path: containerinsight
324312
linters:
325313
- exhaustive
@@ -338,9 +326,6 @@ issues:
338326
- path: ottl
339327
linters:
340328
- exhaustive
341-
- path: stanza
342-
linters:
343-
- exhaustive
344329
- path: resourcetotelemetry
345330
linters:
346331
- exhaustive

connector/countconnector/connector.go

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package countconnector // import "github.com/open-telemetry/opentelemetry-collec
55

66
import (
77
"context"
8+
"fmt"
89

910
"go.opentelemetry.io/collector/component"
1011
"go.opentelemetry.io/collector/consumer"
@@ -134,6 +135,8 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error {
134135
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource())
135136
errors = multierr.Append(errors, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
136137
}
138+
case pmetric.MetricTypeEmpty:
139+
errors = multierr.Append(errors, fmt.Errorf("metric %q: invalid metric type: %v", metric.Name(), metric.Type()))
137140
}
138141
}
139142
}

extension/storage/dbstorage/extension.go

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func kindString(k component.Kind) string {
7777
return "exporter"
7878
case component.KindExtension:
7979
return "extension"
80+
case component.KindConnector:
81+
return "connector"
8082
default:
8183
return "other" // not expected
8284
}

extension/storage/filestorage/extension.go

+2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ func kindString(k component.Kind) string {
7878
return "exporter"
7979
case component.KindExtension:
8080
return "extension"
81+
case component.KindConnector:
82+
return "connector"
8183
default:
8284
return "other" // not expected
8385
}

pkg/stanza/entry/field.go

+2
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ func fromJSONDot(s string) ([]string, error) {
204204
return nil, fmt.Errorf("found unclosed single quote")
205205
case InUnbracketedToken:
206206
fields = append(fields, s[tokenStart:])
207+
case Begin, OutBracket:
208+
// shouldn't be possible
207209
}
208210

209211
if len(fields) == 0 {

pkg/stanza/operator/input/windows/security.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func parseSecurity(message string) (string, map[string]interface{}) {
2020
subject = l.v
2121
case keyType:
2222
subject = l.k
23-
default:
23+
case pairType, emptyType:
2424
return message, nil
2525
}
2626

@@ -46,6 +46,8 @@ func parseSecurity(message string) (string, map[string]interface{}) {
4646
}
4747
// value was first in a list
4848
details[l.k] = append([]string{l.v}, mp.consumeSublist(l.i+1)...)
49+
case emptyType:
50+
continue
4951
}
5052
}
5153

@@ -72,6 +74,8 @@ func (mp *messageProcessor) consumeSubsection(depth int) map[string]interface{}
7274
continue
7375
}
7476
sub[l.k] = mp.consumeSublist(depth + 1)
77+
case valueType:
78+
continue
7579
}
7680
}
7781
return sub
@@ -89,6 +93,8 @@ func (mp *messageProcessor) consumeSublist(depth int) []string {
8993
sublist = append(sublist, l.v)
9094
case keyType: // not expected, but handle
9195
sublist = append(sublist, l.k)
96+
case pairType, emptyType:
97+
// not expected
9298
}
9399
}
94100
return sublist

receiver/nsxtreceiver/client.go

+10-18
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,15 @@ func (c *nsxClient) NodeStatus(ctx context.Context, nodeID string, class nodeCla
9595
return nil, fmt.Errorf("unable to get a node's status from the REST API: %w", err)
9696
}
9797

98-
switch class {
99-
case transportClass:
98+
if class == transportClass {
10099
var nodeStatus dm.TransportNodeStatus
101100
err = json.Unmarshal(body, &nodeStatus)
102101
return &nodeStatus.NodeStatus, err
103-
default:
104-
var nodeStatus dm.NodeStatus
105-
err = json.Unmarshal(body, &nodeStatus)
106-
return &nodeStatus, err
107102
}
108103

104+
var nodeStatus dm.NodeStatus
105+
err = json.Unmarshal(body, &nodeStatus)
106+
return &nodeStatus, err
109107
}
110108

111109
func (c *nsxClient) Interfaces(
@@ -181,28 +179,22 @@ func (c *nsxClient) doRequest(ctx context.Context, path string) ([]byte, error)
181179
}
182180

183181
func (c *nsxClient) nodeStatusEndpoint(class nodeClass, nodeID string) string {
184-
switch class {
185-
case transportClass:
182+
if class == transportClass {
186183
return fmt.Sprintf("/api/v1/transport-nodes/%s/status", nodeID)
187-
default:
188-
return fmt.Sprintf("/api/v1/cluster/nodes/%s/status", nodeID)
189184
}
185+
return fmt.Sprintf("/api/v1/cluster/nodes/%s/status", nodeID)
190186
}
191187

192188
func (c *nsxClient) interfacesEndpoint(class nodeClass, nodeID string) string {
193-
switch class {
194-
case transportClass:
189+
if class == transportClass {
195190
return fmt.Sprintf("/api/v1/transport-nodes/%s/network/interfaces", nodeID)
196-
default:
197-
return fmt.Sprintf("/api/v1/cluster/nodes/%s/network/interfaces", nodeID)
198191
}
192+
return fmt.Sprintf("/api/v1/cluster/nodes/%s/network/interfaces", nodeID)
199193
}
200194

201195
func (c *nsxClient) interfaceStatusEndpoint(class nodeClass, nodeID, interfaceID string) string {
202-
switch class {
203-
case transportClass:
196+
if class == transportClass {
204197
return fmt.Sprintf("/api/v1/transport-nodes/%s/network/interfaces/%s/stats", nodeID, interfaceID)
205-
default:
206-
return fmt.Sprintf("/api/v1/cluster/nodes/%s/network/interfaces/%s/stats", nodeID, interfaceID)
207198
}
199+
return fmt.Sprintf("/api/v1/cluster/nodes/%s/network/interfaces/%s/stats", nodeID, interfaceID)
208200
}

receiver/nsxtreceiver/scraper_test.go

+12-22
Original file line numberDiff line numberDiff line change
@@ -146,36 +146,29 @@ func TestScraperRecordNoStat(_ *testing.T) {
146146
}
147147

148148
func loadTestNodeStatus(t *testing.T, nodeID string, class nodeClass) (*dm.NodeStatus, error) {
149-
var classType string
150-
switch class {
151-
case transportClass:
149+
classType := "cluster"
150+
if class == transportClass {
152151
classType = "transport"
153-
default:
154-
classType = "cluster"
155152
}
156153
testFile, err := os.ReadFile(filepath.Join("testdata", "metrics", "nodes", classType, nodeID, "status.json"))
157154
require.NoError(t, err)
158-
switch class {
159-
case transportClass:
155+
if class == transportClass {
160156
var stats dm.TransportNodeStatus
161157
err = json.Unmarshal(testFile, &stats)
162158
require.NoError(t, err)
163159
return &stats.NodeStatus, err
164-
default:
165-
var stats dm.NodeStatus
166-
err = json.Unmarshal(testFile, &stats)
167-
require.NoError(t, err)
168-
return &stats, err
169160
}
161+
162+
var stats dm.NodeStatus
163+
err = json.Unmarshal(testFile, &stats)
164+
require.NoError(t, err)
165+
return &stats, err
170166
}
171167

172168
func loadTestNodeInterfaces(t *testing.T, nodeID string, class nodeClass) ([]dm.NetworkInterface, error) {
173-
var classType string
174-
switch class {
175-
case transportClass:
169+
classType := "cluster"
170+
if class == transportClass {
176171
classType = "transport"
177-
default:
178-
classType = "cluster"
179172
}
180173
testFile, err := os.ReadFile(filepath.Join("testdata", "metrics", "nodes", classType, nodeID, "interfaces", "index.json"))
181174
require.NoError(t, err)
@@ -186,12 +179,9 @@ func loadTestNodeInterfaces(t *testing.T, nodeID string, class nodeClass) ([]dm.
186179
}
187180

188181
func loadInterfaceStats(t *testing.T, nodeID, interfaceID string, class nodeClass) (*dm.NetworkInterfaceStats, error) {
189-
var classType string
190-
switch class {
191-
case transportClass:
182+
classType := "cluster"
183+
if class == transportClass {
192184
classType = "transport"
193-
default:
194-
classType = "cluster"
195185
}
196186
testFile, err := os.ReadFile(filepath.Join("testdata", "metrics", "nodes", classType, nodeID, "interfaces", interfaceID, "stats.json"))
197187
require.NoError(t, err)

receiver/snmpreceiver/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (c *snmpClient) convertSnmpPDUToSnmpData(pdu gosnmp.SnmpPDU) SNMPData {
325325
}
326326

327327
// Condense gosnmp data types to our client's simplified data types
328-
switch pdu.Type {
328+
switch pdu.Type { // nolint:exhaustive
329329
// Integer types
330330
case gosnmp.Counter32, gosnmp.Gauge32, gosnmp.Uinteger32, gosnmp.TimeTicks, gosnmp.Integer:
331331
value, err := c.toInt64(pdu.Name, pdu.Value)

receiver/snmpreceiver/otel_metric_helper.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,17 @@ func (h *otelMetricHelper) addMetricDataPoint(resourceKey string, metricName str
189189
} else {
190190
dp.SetIntValue(int64(rawValue))
191191
}
192-
default:
192+
case integerVal:
193193
rawValue := data.value.(int64)
194194
if valueType == "int" {
195195
dp.SetIntValue(rawValue)
196196
} else {
197197
dp.SetDoubleValue(float64(rawValue))
198198
}
199+
case stringVal:
200+
return nil, fmt.Errorf("cannot create data point for metric %q from string value", metricName)
201+
case notSupportedVal:
202+
return nil, fmt.Errorf("cannot create data point for metric %q from unsupported value type", metricName)
199203
}
200204

201205
// Add attributes to dp

0 commit comments

Comments
 (0)