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 17 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
6 changes: 4 additions & 2 deletions receiver/snmpreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ Resource attribute configurations are used to define what resource attributes wi

| Field Name | Description | Value |
| -- | -- | -- |
| `oid` | Required if no `indexed_value_prefix`. This is the column OID in a SNMP table which will use the returned indexed SNMP data to create resource attribute values for unique resources. Metric configurations will reference these resource attribute configurations in order to assign metrics data to resources | string |
| `indexed_value_prefix` | Required if no `oid`. This is a string prefix which will be added to the indices of returned metric indexed SNMP data to create resource attribute values for unique resources. Metric configurations will reference these resource attribute configurations in order to assign metrics data to resources | string |
| `oid` | Required if no `scalar_oid` or `indexed_value_prefix`. This is the column OID in a SNMP table which will use the returned indexed SNMP data to create resource attribute values for unique resources. Metric configurations will reference these resource attribute configurations in order to assign metrics data to resources | string |
kuiperda marked this conversation as resolved.
Show resolved Hide resolved
| `scalar_oid` | Required if no `oid` or `indexed_value_prefix`. This is the scalar OID which will return non-indexed SNMP data to create resource attribute values for unique resources. Metric configurations will reference these resource attribute configurations in order to assign metrics data to resources | string |
| `indexed_value_prefix` | Required if no `scalar_oid` or `oid`. This is a string prefix which will be added to the indices of returned metric indexed SNMP data to create resource attribute values for unique resources. Metric configurations will reference these resource attribute configurations in order to assign metrics data to resources | string |
| `description` | Definition of what the resource attribute represents | string |

#### Attribute Configuration
Expand Down Expand Up @@ -124,6 +125,7 @@ Attribute configurations are used to define what resource attributes will be use
| Field Name | Description | Value | Default |
| -- | -- | -- | -- |
| `oid` | The SNMP scalar OID value to grab data from (must end in .0). | string | |
| `resource_attributes` | The names of the related resource attribute configurations, allowing scalar oid metrics to be added to resources that have one or more scalar oid resource attributes. Cannot have indexed resource attributes as values. | string[] | |
| `attributes` | The names of the related attribute enum configurations as well as the values to attach to this returned SNMP scalar data. This can be used to have a metric config with multiple ScalarOIDs as different datapoints with different attributue values within the same metric | Attribute | |

#### ColumnOID Configuration
Expand Down
169 changes: 111 additions & 58 deletions receiver/snmpreceiver/config.go

Large diffs are not rendered by default.

45 changes: 35 additions & 10 deletions receiver/snmpreceiver/config_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type configHelper struct {
metricScalarOIDs []string
metricColumnOIDs []string
attributeColumnOIDs []string
resourceAttributeScalarOIDs []string
resourceAttributeColumnOIDs []string
metricNamesByOID map[string]string
metricAttributesByOID map[string][]Attribute
Expand All @@ -26,6 +27,7 @@ func newConfigHelper(cfg *Config) *configHelper {
metricScalarOIDs: []string{},
metricColumnOIDs: []string{},
attributeColumnOIDs: []string{},
resourceAttributeScalarOIDs: []string{},
resourceAttributeColumnOIDs: []string{},
metricNamesByOID: map[string]string{},
metricAttributesByOID: map[string][]Attribute{},
Expand All @@ -46,6 +48,7 @@ func newConfigHelper(cfg *Config) *configHelper {
ch.metricScalarOIDs = append(ch.metricScalarOIDs, oid.OID)
ch.metricNamesByOID[oid.OID] = name
ch.metricAttributesByOID[oid.OID] = oid.Attributes
ch.resourceAttributesByOID[oid.OID] = oid.ResourceAttributes
}

for i, oid := range metricCfg.ColumnOIDs {
Expand Down Expand Up @@ -77,21 +80,28 @@ func newConfigHelper(cfg *Config) *configHelper {
ch.attributeColumnOIDs = append(ch.attributeColumnOIDs, attributeCfg.OID)
}

// Find all resource attribute column OIDs
// Find all resource attribute scalar and 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 All @@ -110,6 +120,11 @@ func (h configHelper) getAttributeColumnOIDs() []string {
return h.attributeColumnOIDs
}

// getResourceAttributeScalarOIDs returns all of the resource attribute scalar OIDs in the resource attribute configs
func (h configHelper) getResourceAttributeScalarOIDs() []string {
return h.resourceAttributeScalarOIDs
}

// getResourceAttributeColumnOIDs returns all of the resource attribute column OIDs in the resource attribute configs
func (h configHelper) getResourceAttributeColumnOIDs() []string {
return h.resourceAttributeColumnOIDs
Expand Down Expand Up @@ -175,6 +190,16 @@ func (h configHelper) getResourceAttributeConfigOID(name string) string {
return attrConfig.OID
}

// getResourceAttributeConfigScalarOID returns the scalar OID of a resource attribute config
func (h configHelper) getResourceAttributeConfigScalarOID(name string) string {
attrConfig := h.cfg.ResourceAttributes[name]
if attrConfig == nil {
return ""
}

return attrConfig.ScalarOID
}

// getMetricConfigAttributes returns the metric config attributes for a given OID
func (h configHelper) getMetricConfigAttributes(oid string) []Attribute {
return h.metricAttributesByOID[oid]
Expand Down
Loading