Skip to content

Commit

Permalink
[exporter/awsemfexporter] Add config option to retain the initial val…
Browse files Browse the repository at this point in the history
…ue of delta metrics (#16218)
  • Loading branch information
mircohacker committed Feb 24, 2023
1 parent 7206d6d commit 4b71292
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 226 deletions.
16 changes: 16 additions & 0 deletions .chloggen/awsemfexporter_retein_intitial_delta_value.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The AWS EMF exporter now supports the additional configuration flag `retain_initial_value_of_delta_metric`. With this flag active the first value of a metric is not discarded but instead sent to AWS.

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

# (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:
37 changes: 19 additions & 18 deletions exporter/awsemfexporter/README.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions exporter/awsemfexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ type Config struct {
// Namespace is a container for CloudWatch metrics.
// Metrics in different namespaces are isolated from each other.
Namespace string `mapstructure:"namespace"`
// RetainInitialValueOfDeltaMetric is the flag to signal that the initial value of a metric is a valid datapoint.
// The default behavior is that the first value occurrence of a metric is set as the baseline for the calculation of
// the delta to the next occurrence. With this flag set to true the exporter will instead use this first value as the
// initial delta value. This is especially useful when handling low frequency metrics.
RetainInitialValueOfDeltaMetric bool `mapstructure:"retain_initial_value_of_delta_metric"`
// DimensionRollupOption is the option for metrics dimension rollup. Three options are available, default option is "ZeroAndSingleDimensionRollup".
// "ZeroAndSingleDimensionRollup" - Enable both zero dimension rollup and single dimension rollup
// "SingleDimensionRollupOnly" - Enable single dimension rollup
Expand Down
26 changes: 21 additions & 5 deletions exporter/awsemfexporter/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ type dataPoints interface {

// deltaMetricMetadata contains the metadata required to perform rate/delta calculation
type deltaMetricMetadata struct {
adjustToDelta bool
metricName string
namespace string
logGroup string
logStream string
adjustToDelta bool
retainInitialValueForDelta bool
metricName string
namespace string
logGroup string
logStream string
}

// numberDataPointSlice is a wrapper for pmetric.NumberDataPointSlice
Expand Down Expand Up @@ -114,6 +115,13 @@ func (dps numberDataPointSlice) At(i int) (dataPoint, bool) {
var deltaVal interface{}
mKey := aws.NewKey(dps.deltaMetricMetadata, labels)
deltaVal, retained = deltaMetricCalculator.Calculate(mKey, metricVal, metric.Timestamp().AsTime())

// If a delta to the previous data point could not be computed use the current metric value instead
if !retained && dps.retainInitialValueForDelta {
retained = true
deltaVal = metricVal
}

if !retained {
return dataPoint{}, retained
}
Expand Down Expand Up @@ -163,6 +171,13 @@ func (dps summaryDataPointSlice) At(i int) (dataPoint, bool) {
mKey := aws.NewKey(dps.deltaMetricMetadata, labels)

delta, retained = summaryMetricCalculator.Calculate(mKey, summaryMetricEntry{sum, count}, metric.Timestamp().AsTime())

// If a delta to the previous data point could not be computed use the current metric value instead
if !retained && dps.retainInitialValueForDelta {
retained = true
delta = summaryMetricEntry{sum, count}
}

if !retained {
return dataPoint{}, retained
}
Expand Down Expand Up @@ -208,6 +223,7 @@ func createLabels(attributes pcommon.Map, instrLibName string) map[string]string
func getDataPoints(pmd pmetric.Metric, metadata cWMetricMetadata, logger *zap.Logger) (dps dataPoints) {
adjusterMetadata := deltaMetricMetadata{
false,
metadata.retainInitialValueForDelta,
pmd.Name(),
metadata.namespace,
metadata.logGroup,
Expand Down
Loading

0 comments on commit 4b71292

Please sign in to comment.