Skip to content

Commit

Permalink
fix for inf value
Browse files Browse the repository at this point in the history
  • Loading branch information
jayasai470 committed Dec 8, 2023
1 parent d6dda62 commit 35e04e0
Show file tree
Hide file tree
Showing 7 changed files with 376 additions and 30 deletions.
27 changes: 27 additions & 0 deletions .chloggen/awsemf_dropinf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# 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: awsemfexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: AWS EMF Exporter will not drop any metrics that contain Inf values to avoid JSON marshal errors.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [29336]

# (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:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
2 changes: 1 addition & 1 deletion exporter/awsemfexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ and then sends them directly to CloudWatch Logs using the
## Data Conversion
Convert OpenTelemetry ```Int64DataPoints```, ```DoubleDataPoints```, ```SummaryDataPoints``` metrics datapoints into
CloudWatch ```EMF``` structured log formats and send it to CloudWatch. Logs and Metrics will be displayed in
CloudWatch console. NaN values are not supported by CloudWatch EMF and will be dropped by the exporter.
CloudWatch console. NaN,Inf values are not supported by CloudWatch EMF and will be dropped by the exporter.

## Exporter Configuration

Expand Down
27 changes: 15 additions & 12 deletions exporter/awsemfexporter/datapoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ type dataPoints interface {
// retained: indicates whether the data point is valid for further process
// NOTE: It is an expensive call as it calculates the metric value.
CalculateDeltaDatapoints(i int, instrumentationScopeName string, detailedMetrics bool, calculators *emfCalculators) (dataPoint []dataPoint, retained bool)
// IsStaleOrNaN returns true if metric value has NoRecordedValue flag set or if any metric value contains a NaN.
// When return value is true, IsStaleOrNaN also returns the attributes attached to the metric which can be used for
// IsStaleOrNaNOrInf returns true if metric value has NoRecordedValue flag set or if any metric value contains a NaN or Inf.
// When return value is true, IsStaleOrNaNOrInf also returns the attributes attached to the metric which can be used for
// logging purposes.
IsStaleOrNaN(i int) (bool, pcommon.Map)
IsStaleOrNaNOrInf(i int) (bool, pcommon.Map)
}

// deltaMetricMetadata contains the metadata required to perform rate/delta calculation
Expand Down Expand Up @@ -149,13 +149,13 @@ func (dps numberDataPointSlice) CalculateDeltaDatapoints(i int, instrumentationS
return []dataPoint{{name: dps.metricName, value: metricVal, labels: labels, timestampMs: timestampMs}}, retained
}

func (dps numberDataPointSlice) IsStaleOrNaN(i int) (bool, pcommon.Map) {
func (dps numberDataPointSlice) IsStaleOrNaNOrInf(i int) (bool, pcommon.Map) {
metric := dps.NumberDataPointSlice.At(i)
if metric.Flags().NoRecordedValue() {
return true, metric.Attributes()
}
if metric.ValueType() == pmetric.NumberDataPointValueTypeDouble {
return math.IsNaN(metric.DoubleValue()), metric.Attributes()
return math.IsNaN(metric.DoubleValue()) || math.IsInf(metric.DoubleValue(), 0), metric.Attributes()
}
return false, pcommon.Map{}
}
Expand All @@ -179,12 +179,12 @@ func (dps histogramDataPointSlice) CalculateDeltaDatapoints(i int, instrumentati
}}, true
}

func (dps histogramDataPointSlice) IsStaleOrNaN(i int) (bool, pcommon.Map) {
func (dps histogramDataPointSlice) IsStaleOrNaNOrInf(i int) (bool, pcommon.Map) {
metric := dps.HistogramDataPointSlice.At(i)
if metric.Flags().NoRecordedValue() {
return true, metric.Attributes()
}
if math.IsNaN(metric.Max()) || math.IsNaN(metric.Sum()) || math.IsNaN(metric.Min()) {
if math.IsNaN(metric.Max()) || math.IsNaN(metric.Sum()) || math.IsNaN(metric.Min()) || math.IsInf(metric.Max(), 0) || math.IsInf(metric.Sum(), 0) || math.IsInf(metric.Min(), 0) {
return true, metric.Attributes()
}
return false, pcommon.Map{}
Expand Down Expand Up @@ -272,14 +272,17 @@ func (dps exponentialHistogramDataPointSlice) CalculateDeltaDatapoints(idx int,
}}, true
}

func (dps exponentialHistogramDataPointSlice) IsStaleOrNaN(i int) (bool, pcommon.Map) {
func (dps exponentialHistogramDataPointSlice) IsStaleOrNaNOrInf(i int) (bool, pcommon.Map) {
metric := dps.ExponentialHistogramDataPointSlice.At(i)
if metric.Flags().NoRecordedValue() {
return true, metric.Attributes()
}
if math.IsNaN(metric.Max()) ||
math.IsNaN(metric.Min()) ||
math.IsNaN(metric.Sum()) {
math.IsNaN(metric.Sum()) ||
math.IsInf(metric.Max(), 0) ||
math.IsInf(metric.Min(), 0) ||
math.IsInf(metric.Sum(), 0) {
return true, metric.Attributes()
}

Expand Down Expand Up @@ -343,19 +346,19 @@ func (dps summaryDataPointSlice) CalculateDeltaDatapoints(i int, instrumentation
return datapoints, retained
}

func (dps summaryDataPointSlice) IsStaleOrNaN(i int) (bool, pcommon.Map) {
func (dps summaryDataPointSlice) IsStaleOrNaNOrInf(i int) (bool, pcommon.Map) {
metric := dps.SummaryDataPointSlice.At(i)
if metric.Flags().NoRecordedValue() {
return true, metric.Attributes()
}
if math.IsNaN(metric.Sum()) {
if math.IsNaN(metric.Sum()) || math.IsInf(metric.Sum(), 0) {
return true, metric.Attributes()
}

values := metric.QuantileValues()
for i := 0; i < values.Len(); i++ {
quantile := values.At(i)
if math.IsNaN(quantile.Value()) || math.IsNaN(quantile.Quantile()) {
if math.IsNaN(quantile.Value()) || math.IsNaN(quantile.Quantile()) || math.IsInf(quantile.Value(), 0) || math.IsInf(quantile.Quantile(), 0) {
return true, metric.Attributes()
}
}
Expand Down
Loading

0 comments on commit 35e04e0

Please sign in to comment.