diff --git a/.golangci.yml b/.golangci.yml index 587940ff4988..0f6457b67cc2 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -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 @@ -314,12 +308,6 @@ issues: - path: k8sobserver linters: - exhaustive - - path: countconnector - linters: - - exhaustive - - path: storage - linters: - - exhaustive - path: containerinsight linters: - exhaustive @@ -338,9 +326,6 @@ issues: - path: ottl linters: - exhaustive - - path: stanza - linters: - - exhaustive - path: resourcetotelemetry linters: - exhaustive diff --git a/connector/countconnector/connector.go b/connector/countconnector/connector.go index b9f99deeab5b..694dcb799abf 100644 --- a/connector/countconnector/connector.go +++ b/connector/countconnector/connector.go @@ -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" @@ -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())) } } } diff --git a/extension/storage/dbstorage/extension.go b/extension/storage/dbstorage/extension.go index 3e3e30416893..a55aef153301 100644 --- a/extension/storage/dbstorage/extension.go +++ b/extension/storage/dbstorage/extension.go @@ -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 } diff --git a/extension/storage/filestorage/extension.go b/extension/storage/filestorage/extension.go index 0fcd16db8687..da23222d3c83 100644 --- a/extension/storage/filestorage/extension.go +++ b/extension/storage/filestorage/extension.go @@ -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 } diff --git a/pkg/stanza/entry/field.go b/pkg/stanza/entry/field.go index 8333a24d6409..170aea25ba9e 100644 --- a/pkg/stanza/entry/field.go +++ b/pkg/stanza/entry/field.go @@ -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 { diff --git a/pkg/stanza/operator/input/windows/security.go b/pkg/stanza/operator/input/windows/security.go index 4f73002b2afe..5a5bc8a98719 100644 --- a/pkg/stanza/operator/input/windows/security.go +++ b/pkg/stanza/operator/input/windows/security.go @@ -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 } @@ -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 } } @@ -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 @@ -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 diff --git a/receiver/nsxtreceiver/client.go b/receiver/nsxtreceiver/client.go index fff539c3dc73..fcc3ea0d38e6 100644 --- a/receiver/nsxtreceiver/client.go +++ b/receiver/nsxtreceiver/client.go @@ -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) } diff --git a/receiver/nsxtreceiver/scraper_test.go b/receiver/nsxtreceiver/scraper_test.go index bdb1953632a3..df9a53561896 100644 --- a/receiver/nsxtreceiver/scraper_test.go +++ b/receiver/nsxtreceiver/scraper_test.go @@ -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) diff --git a/receiver/snmpreceiver/client.go b/receiver/snmpreceiver/client.go index 2520f13123f5..6ab374686b29 100644 --- a/receiver/snmpreceiver/client.go +++ b/receiver/snmpreceiver/client.go @@ -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) diff --git a/receiver/snmpreceiver/otel_metric_helper.go b/receiver/snmpreceiver/otel_metric_helper.go index b68c423fc450..e2211b36c927 100644 --- a/receiver/snmpreceiver/otel_metric_helper.go +++ b/receiver/snmpreceiver/otel_metric_helper.go @@ -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