Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore] Enable exhaustive linter for several modules #23329

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ issues:
- path: kubeletstatsreceiver
linters:
- exhaustive
- path: nsxtreceiver
linters:
- exhaustive
- path: podmanreceiver
linters:
- exhaustive
Expand All @@ -194,9 +191,6 @@ issues:
- path: receivercreator
linters:
- exhaustive
- path: snmpreceiver
linters:
- exhaustive
- path: statsdreceiver
linters:
- exhaustive
Expand Down Expand Up @@ -314,12 +308,6 @@ issues:
- path: k8sobserver
linters:
- exhaustive
- path: countconnector
linters:
- exhaustive
- path: storage
linters:
- exhaustive
- path: containerinsight
linters:
- exhaustive
Expand All @@ -338,9 +326,6 @@ issues:
- path: ottl
linters:
- exhaustive
- path: stanza
linters:
- exhaustive
- path: resourcetotelemetry
linters:
- exhaustive
Expand Down
3 changes: 3 additions & 0 deletions connector/countconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package countconnector // import "github.com/open-telemetry/opentelemetry-collec

import (
"context"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
Expand Down Expand Up @@ -134,6 +135,8 @@ func (c *count) ConsumeMetrics(ctx context.Context, md pmetric.Metrics) error {
dCtx := ottldatapoint.NewTransformContext(dps.At(i), metric, scopeMetrics.Metrics(), scopeMetrics.Scope(), resourceMetric.Resource())
errors = multierr.Append(errors, dataPointsCounter.update(ctx, dps.At(i).Attributes(), dCtx))
}
case pmetric.MetricTypeEmpty:
errors = multierr.Append(errors, fmt.Errorf("metric %q: invalid metric type: %v", metric.Name(), metric.Type()))
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions extension/storage/dbstorage/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func kindString(k component.Kind) string {
return "exporter"
case component.KindExtension:
return "extension"
case component.KindConnector:
return "connector"
default:
return "other" // not expected
}
Expand Down
2 changes: 2 additions & 0 deletions extension/storage/filestorage/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func kindString(k component.Kind) string {
return "exporter"
case component.KindExtension:
return "extension"
case component.KindConnector:
return "connector"
default:
return "other" // not expected
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/stanza/entry/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ func fromJSONDot(s string) ([]string, error) {
return nil, fmt.Errorf("found unclosed single quote")
case InUnbracketedToken:
fields = append(fields, s[tokenStart:])
case Begin, OutBracket:
// shouldn't be possible
}

if len(fields) == 0 {
Expand Down
8 changes: 7 additions & 1 deletion pkg/stanza/operator/input/windows/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func parseSecurity(message string) (string, map[string]interface{}) {
subject = l.v
case keyType:
subject = l.k
default:
case pairType, emptyType:
return message, nil
}

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

Expand All @@ -72,6 +74,8 @@ func (mp *messageProcessor) consumeSubsection(depth int) map[string]interface{}
continue
}
sub[l.k] = mp.consumeSublist(depth + 1)
case valueType:
continue
}
}
return sub
Expand All @@ -89,6 +93,8 @@ func (mp *messageProcessor) consumeSublist(depth int) []string {
sublist = append(sublist, l.v)
case keyType: // not expected, but handle
sublist = append(sublist, l.k)
case pairType, emptyType:
// not expected
}
}
return sublist
Expand Down
28 changes: 10 additions & 18 deletions receiver/nsxtreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,15 @@ func (c *nsxClient) NodeStatus(ctx context.Context, nodeID string, class nodeCla
return nil, fmt.Errorf("unable to get a node's status from the REST API: %w", err)
}

switch class {
case transportClass:
if class == transportClass {
var nodeStatus dm.TransportNodeStatus
err = json.Unmarshal(body, &nodeStatus)
return &nodeStatus.NodeStatus, err
default:
var nodeStatus dm.NodeStatus
err = json.Unmarshal(body, &nodeStatus)
return &nodeStatus, err
}

var nodeStatus dm.NodeStatus
err = json.Unmarshal(body, &nodeStatus)
return &nodeStatus, err
}

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

func (c *nsxClient) nodeStatusEndpoint(class nodeClass, nodeID string) string {
switch class {
case transportClass:
if class == transportClass {
return fmt.Sprintf("/api/v1/transport-nodes/%s/status", nodeID)
default:
return fmt.Sprintf("/api/v1/cluster/nodes/%s/status", nodeID)
}
return fmt.Sprintf("/api/v1/cluster/nodes/%s/status", nodeID)
}

func (c *nsxClient) interfacesEndpoint(class nodeClass, nodeID string) string {
switch class {
case transportClass:
if class == transportClass {
return fmt.Sprintf("/api/v1/transport-nodes/%s/network/interfaces", nodeID)
default:
return fmt.Sprintf("/api/v1/cluster/nodes/%s/network/interfaces", nodeID)
}
return fmt.Sprintf("/api/v1/cluster/nodes/%s/network/interfaces", nodeID)
}

func (c *nsxClient) interfaceStatusEndpoint(class nodeClass, nodeID, interfaceID string) string {
switch class {
case transportClass:
if class == transportClass {
return fmt.Sprintf("/api/v1/transport-nodes/%s/network/interfaces/%s/stats", nodeID, interfaceID)
default:
return fmt.Sprintf("/api/v1/cluster/nodes/%s/network/interfaces/%s/stats", nodeID, interfaceID)
}
return fmt.Sprintf("/api/v1/cluster/nodes/%s/network/interfaces/%s/stats", nodeID, interfaceID)
}
34 changes: 12 additions & 22 deletions receiver/nsxtreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,36 +146,29 @@ func TestScraperRecordNoStat(_ *testing.T) {
}

func loadTestNodeStatus(t *testing.T, nodeID string, class nodeClass) (*dm.NodeStatus, error) {
var classType string
switch class {
case transportClass:
classType := "cluster"
if class == transportClass {
classType = "transport"
default:
classType = "cluster"
}
testFile, err := os.ReadFile(filepath.Join("testdata", "metrics", "nodes", classType, nodeID, "status.json"))
require.NoError(t, err)
switch class {
case transportClass:
if class == transportClass {
var stats dm.TransportNodeStatus
err = json.Unmarshal(testFile, &stats)
require.NoError(t, err)
return &stats.NodeStatus, err
default:
var stats dm.NodeStatus
err = json.Unmarshal(testFile, &stats)
require.NoError(t, err)
return &stats, err
}

var stats dm.NodeStatus
err = json.Unmarshal(testFile, &stats)
require.NoError(t, err)
return &stats, err
}

func loadTestNodeInterfaces(t *testing.T, nodeID string, class nodeClass) ([]dm.NetworkInterface, error) {
var classType string
switch class {
case transportClass:
classType := "cluster"
if class == transportClass {
classType = "transport"
default:
classType = "cluster"
}
testFile, err := os.ReadFile(filepath.Join("testdata", "metrics", "nodes", classType, nodeID, "interfaces", "index.json"))
require.NoError(t, err)
Expand All @@ -186,12 +179,9 @@ func loadTestNodeInterfaces(t *testing.T, nodeID string, class nodeClass) ([]dm.
}

func loadInterfaceStats(t *testing.T, nodeID, interfaceID string, class nodeClass) (*dm.NetworkInterfaceStats, error) {
var classType string
switch class {
case transportClass:
classType := "cluster"
if class == transportClass {
classType = "transport"
default:
classType = "cluster"
}
testFile, err := os.ReadFile(filepath.Join("testdata", "metrics", "nodes", classType, nodeID, "interfaces", interfaceID, "stats.json"))
require.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion receiver/snmpreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ func (c *snmpClient) convertSnmpPDUToSnmpData(pdu gosnmp.SnmpPDU) SNMPData {
}

// Condense gosnmp data types to our client's simplified data types
switch pdu.Type {
switch pdu.Type { // nolint:exhaustive
// Integer types
case gosnmp.Counter32, gosnmp.Gauge32, gosnmp.Uinteger32, gosnmp.TimeTicks, gosnmp.Integer:
value, err := c.toInt64(pdu.Name, pdu.Value)
Expand Down
6 changes: 5 additions & 1 deletion receiver/snmpreceiver/otel_metric_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,17 @@ func (h *otelMetricHelper) addMetricDataPoint(resourceKey string, metricName str
} else {
dp.SetIntValue(int64(rawValue))
}
default:
case integerVal:
rawValue := data.value.(int64)
if valueType == "int" {
dp.SetIntValue(rawValue)
} else {
dp.SetDoubleValue(float64(rawValue))
}
case stringVal:
return nil, fmt.Errorf("cannot create data point for metric %q from string value", metricName)
case notSupportedVal:
return nil, fmt.Errorf("cannot create data point for metric %q from unsupported value type", metricName)
}

// Add attributes to dp
Expand Down