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

[exporter/awsemfexporter] Add config option to retain the initial value of delta metrics (#16218) #17988

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
36 changes: 26 additions & 10 deletions exporter/awsemfexporter/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,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 @@ -127,6 +128,13 @@ func (dps numberDataPointSlice) CalculateDeltaDatapoints(i int, instrumentationS
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 nil, retained
}
Expand Down Expand Up @@ -175,6 +183,13 @@ func (dps summaryDataPointSlice) CalculateDeltaDatapoints(i int, instrumentation
var delta interface{}
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 datapoints, retained
}
Expand Down Expand Up @@ -229,11 +244,12 @@ func createLabels(attributes pcommon.Map, instrLibName string) map[string]string
// getDataPoints retrieves data points from OT Metric.
func getDataPoints(pmd pmetric.Metric, metadata cWMetricMetadata, logger *zap.Logger) dataPoints {
metricMetadata := deltaMetricMetadata{
adjustToDelta: false,
metricName: pmd.Name(),
namespace: metadata.namespace,
logGroup: metadata.logGroup,
logStream: metadata.logStream,
adjustToDelta: false,
retainInitialValueForDelta: metadata.retainInitialValueForDelta,
metricName: pmd.Name(),
namespace: metadata.namespace,
logGroup: metadata.logGroup,
logStream: metadata.logStream,
}

var dps dataPoints
Expand Down
Loading