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

[receiver/snmp] Add column and scalar OID metrics to resources that have scalar OID attributes #25174

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
9e728c3
added ScalarOID to config and began testing
kuiperda Aug 8, 2023
f127f24
test scalar ra on coid with no indexed identifier
kuiperda Aug 8, 2023
3f08443
expanded config tests
kuiperda Aug 8, 2023
c4af256
test that resource attribute doesn't have too many keys
kuiperda Aug 8, 2023
4b7532c
test that resource attribute (scalar/column oid) end in correct digit
kuiperda Aug 8, 2023
bfd36ee
add ScalarOID to readme
kuiperda Aug 8, 2023
b63e39b
feedback implemented
kuiperda Aug 16, 2023
0eb2856
updated comment
kuiperda Aug 16, 2023
470f251
more feedback
kuiperda Aug 16, 2023
f58d098
migrate to errors.Join
kuiperda Aug 16, 2023
1387841
column oid metrics can be created with scalar oid resource attributes
kuiperda Aug 17, 2023
b578006
fix naming to be accurate
kuiperda Aug 18, 2023
862a057
fix cases where the only resource attributes are scalar
kuiperda Aug 18, 2023
0f446e0
Add resource attributes to scalar oid metric config and only allow sc…
kuiperda Aug 18, 2023
0fb327a
add readme
kuiperda Aug 18, 2023
b177fa9
can add scalar resource attributes to scalar metrics successfully
kuiperda Aug 21, 2023
325f07d
Stefan 2nd feedback
kuiperda Aug 22, 2023
ff8ff25
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
kuiperda Aug 22, 2023
c83668c
Dan 2nd feeback
kuiperda Aug 22, 2023
2149c5c
Stefan 3rd feedback
kuiperda Aug 22, 2023
2e44b18
Add chloggen yaml, another test, gofmt
kuiperda Aug 22, 2023
0d171ad
make gotidy and actually add chloggen yaml
kuiperda Aug 22, 2023
499308d
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
kuiperda Aug 22, 2023
9441acc
Sort []string cfg values for deterministic test behavior
kuiperda Aug 23, 2023
501ea0d
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
kuiperda Aug 23, 2023
bc6a8cc
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
kuiperda Aug 28, 2023
39ae6de
fix lint error with make gofmt
kuiperda Aug 28, 2023
8f5e3ee
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
kuiperda Aug 28, 2023
ad77642
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
kuiperda Aug 29, 2023
726777b
Merge branch 'main' into feat/snmpreceiver-resource-attribute-updates
kuiperda Aug 29, 2023
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
2 changes: 1 addition & 1 deletion receiver/snmpreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ type SumMetric struct {
type ScalarOID struct {
// OID is required and is the scalar OID that is associated with a metric
OID string `mapstructure:"oid"`
// ResourceAttributes is optional and may contain values of Scalar OIDs to associate this metric with
// ResourceAttributes is optional and may contain values of (Scalar OIDs only) to associate this metric with
ResourceAttributes []string `mapstructure:"resource_attributes"`
// Attributes is optional and may contain names and values associated with enum
// AttributeConfigs to associate with the value of the scalar OID
Expand Down
42 changes: 17 additions & 25 deletions receiver/snmpreceiver/config_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,36 +80,28 @@ func newConfigHelper(cfg *Config) *configHelper {
ch.attributeColumnOIDs = append(ch.attributeColumnOIDs, attributeCfg.OID)
}

// Find all resource attribute scalar OIDs
// Find all resource attribute scalar and column OIDs
for name, resourceAttributeCfg := range cfg.ResourceAttributes {
if resourceAttributeCfg.ScalarOID == "" {
continue
}

// Data is returned by the client with '.' prefix on the OIDs.
// Making sure the prefix exists here in the configs so we can match it up with returned data later
if !strings.HasPrefix(resourceAttributeCfg.ScalarOID, ".") {
resourceAttributeCfg.ScalarOID = "." + resourceAttributeCfg.ScalarOID
cfg.ResourceAttributes[name] = resourceAttributeCfg
}
ch.resourceAttributeScalarOIDs = append(ch.resourceAttributeScalarOIDs, resourceAttributeCfg.ScalarOID)
}

// Find all resource attribute column OIDs
for name, resourceAttributeCfg := range cfg.ResourceAttributes {
if resourceAttributeCfg.OID == "" {
if resourceAttributeCfg.ScalarOID != "" {
// Data is returned by the client with '.' prefix on the OIDs.
// Making sure the prefix exists here in the configs so we can match it up with returned data later
if !strings.HasPrefix(resourceAttributeCfg.ScalarOID, ".") {
resourceAttributeCfg.ScalarOID = "." + resourceAttributeCfg.ScalarOID
cfg.ResourceAttributes[name] = resourceAttributeCfg
}
ch.resourceAttributeScalarOIDs = append(ch.resourceAttributeScalarOIDs, resourceAttributeCfg.ScalarOID)
continue
}

// Data is returned by the client with '.' prefix on the OIDs.
// Making sure the prefix exists here in the configs so we can match it up with returned data later
if !strings.HasPrefix(resourceAttributeCfg.OID, ".") {
resourceAttributeCfg.OID = "." + resourceAttributeCfg.OID
cfg.ResourceAttributes[name] = resourceAttributeCfg
if resourceAttributeCfg.OID != "" {
// Data is returned by the client with '.' prefix on the OIDs.
// Making sure the prefix exists here in the configs so we can match it up with returned data later
if !strings.HasPrefix(resourceAttributeCfg.OID, ".") {
resourceAttributeCfg.OID = "." + resourceAttributeCfg.OID
cfg.ResourceAttributes[name] = resourceAttributeCfg
}
ch.resourceAttributeColumnOIDs = append(ch.resourceAttributeColumnOIDs, resourceAttributeCfg.OID)
}
ch.resourceAttributeColumnOIDs = append(ch.resourceAttributeColumnOIDs, resourceAttributeCfg.OID)
}

return &ch
}

Expand Down
35 changes: 15 additions & 20 deletions receiver/snmpreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ func (s *snmpScraper) scrapeScalarMetrics(
return
}
// Retrieve scalar OID SNMP data for resource attributes
scalarOIDScalarResourceAttributeValues := s.scrapeScalarResourceAttributes(configHelper.getResourceAttributeScalarOIDs(), scraperErrors)
scalarResourceAttributes := s.scrapeScalarResourceAttributes(configHelper.getResourceAttributeScalarOIDs(), scraperErrors)

// For each piece of SNMP data, attempt to create the necessary OTEL structures (resources/metrics/datapoints)
for _, data := range scalarData {
if err := s.scalarDataToMetric(data, metricHelper, configHelper, scalarOIDScalarResourceAttributeValues); err != nil {
if err := s.scalarDataToMetric(data, metricHelper, configHelper, scalarResourceAttributes); err != nil {
scraperErrors.AddPartial(1, fmt.Errorf(errMsgScalarOIDProcessing, data.oid, err))
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ func (s *snmpScraper) scalarDataToMetric(
data SNMPData,
metricHelper *otelMetricHelper,
configHelper *configHelper,
scalarOIDScalarResourceAttributeValues map[string]string,
scalarResourceAttributes map[string]string,
) error {
// Get the related metric name for this SNMP indexed data
metricName := configHelper.getMetricName(data.oid)
Expand All @@ -164,34 +164,29 @@ func (s *snmpScraper) scalarDataToMetric(
dataPointAttributes := getScalarDataPointAttributes(configHelper, data.oid)

// Get resource attributes
resourceAttributes, err := getResourceAttributes(configHelper, data.oid, "0", map[string]indexedAttributeValues{}, scalarOIDScalarResourceAttributeValues)
resourceAttributes, err := getResourceAttributes(configHelper, data.oid, "0", map[string]indexedAttributeValues{}, scalarResourceAttributes)
if err != nil {
return fmt.Errorf(errMsgOIDResourceAttributeEmptyValue, metricName, err)
}

// Create a resource key using all of the relevant resource attribute names
resourceAttributeNames := configHelper.getResourceAttributeNames(data.oid)

var resourceKey string
if len(resourceAttributeNames) > 0 {
resourceKey := getResourceKey(resourceAttributeNames, "0")

// Create a new resource if needed
resource := metricHelper.getResource(resourceKey)
if resource == nil {
metricHelper.createResource(resourceKey, resourceAttributes)
}

return addMetricDataPointToResource(data, metricHelper, configHelper, metricName, resourceKey, dataPointAttributes)
resourceKey = getResourceKey(resourceAttributeNames, "")
} else {
// Create general resource if we don't have any resource attributes
resource := metricHelper.getResource(generalResourceKey)
if resource == nil {
metricHelper.createResource(generalResourceKey, map[string]string{})
}
resourceKey = generalResourceKey
}

return addMetricDataPointToResource(data, metricHelper, configHelper, metricName, generalResourceKey, dataPointAttributes)
// Create a new resource if needed
resource := metricHelper.getResource(resourceKey)
if resource == nil {
metricHelper.createResource(resourceKey, resourceAttributes)
}

return addMetricDataPointToResource(data, metricHelper, configHelper, metricName, resourceKey, dataPointAttributes)
}

// indexedDataToMetric will take one piece of column OID SNMP indexed metric data and turn it
Expand Down Expand Up @@ -229,7 +224,7 @@ func (s *snmpScraper) indexedDataToMetric(
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")
resourceKey = getResourceKey(resourceAttributeNames, "")
} else {
resourceKey = getResourceKey(resourceAttributeNames, indexString)
}
Expand Down Expand Up @@ -380,7 +375,7 @@ func (s *snmpScraper) scrapeScalarResourceAttributes(
scalarOIDs []string,
scraperErrors *scrapererror.ScrapeErrors,
) map[string]string {
scalarOIDAttributeValues := map[string]string{}
scalarOIDAttributeValues := make(map[string]string, len(scalarOIDs))

// If no scalar OID resource attribute configs, nothing else to do
if len (scalarOIDs) == 0 {
Expand Down