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
Changes from 1 commit
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
Next Next commit
[chore] Enable exhaustive linter for nsxt and snmp receivers
  • Loading branch information
djaglowski committed Jun 12, 2023
commit c1ee57fe2e9b93eed103c5d5763dab5d047b904e
6 changes: 0 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -182,9 +182,6 @@ issues:
- path: kubeletstatsreceiver
linters:
- exhaustive
- path: nsxtreceiver
linters:
- exhaustive
- path: podmanreceiver
linters:
- exhaustive
@@ -194,9 +191,6 @@ issues:
- path: receivercreator
linters:
- exhaustive
- path: snmpreceiver
linters:
- exhaustive
- path: statsdreceiver
linters:
- exhaustive
28 changes: 10 additions & 18 deletions receiver/nsxtreceiver/client.go
Original file line number Diff line number Diff line change
@@ -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(
@@ -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
@@ -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)
@@ -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)
2 changes: 1 addition & 1 deletion receiver/snmpreceiver/client.go
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 5 additions & 1 deletion receiver/snmpreceiver/otel_metric_helper.go
Original file line number Diff line number Diff line change
@@ -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