Skip to content

Commit

Permalink
[exporter/awsemfexporter] fix awsemfexporter Namespace dimension (#17024
Browse files Browse the repository at this point in the history
)

* see related issue
* Namespace of Cloudwatch was used as dimension
* this conflicted when the metric has namespace metadata (for e.g. k8s metrics)
* this is caused because AWs Embedded metric format depends on the
ordering of the keys in `CloudWatchMetrics`, if the Namespace of
cloudwatch comes first it is used in the dimensions too
  • Loading branch information
Claus Riegg committed Dec 21, 2022
1 parent bc29302 commit 9cf5e18
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 18 additions & 0 deletions .chloggen/17024_fix_cwmetrics_namespace_dimension.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: exporter/awsemfexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fixing inheritance of the value of cloudwatch `Namespace` to a dimension which is named `Namespace` too.

# One or more tracking issues related to the change
issues: [17024]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: |
When pushing metrics to cloudwatch which have a Dimension named `Namespace` (for e.g. k8s metrics) it was always
overriden by the value from `Namespace` of cloudwatch where the metrics get written to.
10 changes: 7 additions & 3 deletions exporter/awsemfexporter/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ type cWMetrics struct {
fields map[string]interface{}
}

// cWMeasurement represents the CloudWatch Embedded metric format
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format_Specification.html
// The namespace must be at the end of the struct to avoid overwriting a `Namespace`
// key given in a `Metrics` `Dimensions` which should use labels instead.
type cWMeasurement struct {
Namespace string
Dimensions [][]string
Metrics []map[string]string
Namespace string
}

type cWMetricStats struct {
Expand Down Expand Up @@ -227,9 +231,9 @@ func groupedMetricToCWMeasurement(groupedMetric *groupedMetric, config *Config)
}

return cWMeasurement{
Namespace: groupedMetric.metadata.namespace,
Dimensions: dimensions,
Metrics: metrics,
Namespace: groupedMetric.metadata.namespace,
}
}

Expand Down Expand Up @@ -326,9 +330,9 @@ func groupedMetricToCWMeasurementsWithFilters(groupedMetric *groupedMetric, conf
// Export metrics only with non-empty dimensions list
if len(dimensions) > 0 {
cwm := cWMeasurement{
Namespace: groupedMetric.metadata.namespace,
Dimensions: dimensions,
Metrics: group.metrics,
Namespace: groupedMetric.metadata.namespace,
}
cWMeasurements = append(cWMeasurements, cwm)
}
Expand Down

0 comments on commit 9cf5e18

Please sign in to comment.