Skip to content

Commit

Permalink
fix cases where the only resource attributes are scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
kuiperda committed Aug 21, 2023
1 parent b578006 commit 862a057
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 33 deletions.
13 changes: 10 additions & 3 deletions receiver/snmpreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ var (
// Error messages
errMsgBadValueType = `returned metric SNMP data type for OID '%s' is not supported`
errMsgIndexedAttributesBadValueType = `returned attribute SNMP data type for OID '%s' from column OID '%s' is not supported`
errMsgScalarAttributesBadValueType = `returned attribute SNMP data type for OID '%s' is not supported`
errMsgScalarAttributesBadValueType = `returned attribute SNMP data type for OID '%s' is not supported`
errMsgOIDAttributeEmptyValue = `not creating indexed metric '%s' datapoint: %w`
errMsgAttributeEmptyValue = `metric OID attribute value is blank`
errMsgResourceAttributeEmptyValue = `related resource attribute value is blank`
errMsgOIDResourceAttributeEmptyValue = `not creating indexed metric '%s' or resource: %w`
errMsgScalarOIDProcessing = `problem processing scalar metric data for OID '%s': %w`
errMsgIndexedMetricOIDProcessing = `problem processing indexed metric data for OID '%s' from column OID '%s': %w`
errMsgScalarAttributeOIDProcessing = `problem processing scalar attribute data from scalar OID '%s': %w`
errMsgScalarAttributeOIDProcessing = `problem processing scalar attribute data from scalar OID '%s': %w`
errMsgIndexedAttributeOIDProcessing = `problem processing indexed attribute data for OID '%s' from column OID '%s': %w`
)

Expand Down Expand Up @@ -200,7 +200,14 @@ func (s *snmpScraper) indexedDataToMetric(
// Create a resource key using all of the relevant resource attribute names along
// with the row index of the SNMP data
resourceAttributeNames := configHelper.getResourceAttributeNames(data.columnOID)
resourceKey := getResourceKey(resourceAttributeNames, indexString)

var resourceKey string
// If we only have scalar resource attributes, we don't need multiple resources
if len(resourceAttributes) == len(columnOIDScalarResourceAttributeValues) {
resourceKey = getResourceKey(resourceAttributeNames, "0")
} else {
resourceKey = getResourceKey(resourceAttributeNames, indexString)
}

// Create a new resource if needed
resource := metricHelper.getResource(resourceKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ resourceMetrics:
value:
stringValue: string1
timeUnixNano: "1651783494931319000"
name: metric1
unit: By
scope:
name: otelcol/snmpreceiver
version: latest
- resource:
attributes:
- key: rattr1
value:
stringValue: scalar
scopeMetrics:
- metrics:
- description: test description
gauge:
dataPoints:
- asInt: "4"
attributes:
- key: attr1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@ resourceMetrics:
value:
stringValue: prefix.1
timeUnixNano: "1651783494931319000"
name: metric1
unit: By
scope:
name: otelcol/snmpreceiver
version: latest
- resource:
attributes:
- key: rattr1
value:
stringValue: scalar
scopeMetrics:
- metrics:
- description: test description
gauge:
dataPoints:
- asInt: "4"
attributes:
- key: attr1
Expand Down

0 comments on commit 862a057

Please sign in to comment.