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/awsemf] Drop metrics with NaN values #26344

Merged
merged 31 commits into from
Sep 19, 2023

Conversation

bryan-aguilar
Copy link
Contributor

Description: Metrics with NaN values for float types would cause the EMF Exporter to error out during JSON Marshaling. This PR introduces a change to drop metric values that contain NaN.

Link to tracking Issue: Fixes #26267

Testing: Added unit tests at several different points with varying levels of specificity. Unit tests are quite verbose in this example but I have followed the format of existing tests while doing very little refactoring.

Documentation: Update README

@bryan-aguilar bryan-aguilar requested a review from a team August 31, 2023 01:21
@github-actions github-actions bot added the exporter/awsemf awsemf exporter label Aug 31, 2023
func TestCalculateDeltaDatapoints_SummaryDataPointSlice(t *testing.T) {
emfCalcs := setupEmfCalculators()
defer require.NoError(t, shutdownEmfCalculators(emfCalcs))
for _, retainInitialValueOfDeltaMetric := range []bool{true, false} {
deltaMetricMetadata := generateDeltaMetricMetadata(true, "foo", retainInitialValueOfDeltaMetric)
dmd := generateDeltaMetricMetadata(true, "foo", retainInitialValueOfDeltaMetric)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed many of these variables to avoid shadowing which caused linting fails.

Comment on lines -27 to -31
func init() {
os.Setenv("AWS_ACCESS_KEY_ID", "test")
os.Setenv("AWS_SECRET_ACCESS_KEY", "test")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These weren't required anymore and were causing warnings for unchecked error. Opted to remove dead code.

// Drop stale or NaN metric values
if dps.IsStaleOrNaN(i) {
if config != nil && config.logger != nil {
config.logger.Debug("dropped metric with nan value", zap.String("metric.name", pmd.Name()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this include the metric attributes? The name alone is not identifying.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a consistent way to log this without being too verbose? Or should we just log all metric attributes along with the name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the IsStaleOrNaN function signature to also return the attributes for each data point. I don't love this but it seemed like the cleanest way to ensure only one log line had to be added. I chose this over adding the logger as an function parameter to IsStaleOrNaN.

if metric.Flags().NoRecordedValue() {
return true, metric.Attributes()
}
if math.IsNaN(metric.Max()) || math.IsNaN(metric.Sum()) || math.IsNaN(metric.Min()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q: do we also need to check on count as well?

Copy link
Contributor Author

@bryan-aguilar bryan-aguilar Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mx-psi mx-psi merged commit 6d00884 into open-telemetry:main Sep 19, 2023
@github-actions github-actions bot added this to the next release milestone Sep 19, 2023
@bryan-aguilar bryan-aguilar deleted the awsemf/dropnan branch September 19, 2023 14:12
jmsnll pushed a commit to jmsnll/opentelemetry-collector-contrib that referenced this pull request Nov 12, 2023
**Description:** Metrics with NaN values for float types would cause the
EMF Exporter to error out during JSON Marshaling. This PR introduces a
change to drop metric values that contain NaN.

**Link to tracking Issue:** Fixes open-telemetry#26267 

**Testing:** Added unit tests at several different points with varying
levels of specificity. Unit tests are quite verbose in this example but
I have followed the format of existing tests while doing very little
refactoring.

**Documentation:** Update README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exporter/awsemf awsemf exporter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[exporter/awsemf] NaN values are not handled properly
4 participants