Repository navigation
fix(metrics): reject non-finite metric values with warning - #8815
Closed
dhairyakhandelwal880-dotcom wants to merge 2 commits into
Closed
dhairyakhandelwal880-dotcom wants to merge 2 commits into
dhairyakhandelwal880-dotcom wants to merge 2 commits into
Conversation
…tools#8796) Signed-off-by: dhairyakhandelwal880-dotcom <dhairyakhandelwal880@gmail.com>
… assertions Signed-off-by: dhairyakhandelwal880-dotcom <dhairyakhandelwal880@gmail.com>
|
Contributor
|
Thanks for the PR @dhairyakhandelwal880-dotcom. This one is already fixed in #8797, which was linked on the issue and approved before yours came in, so I'm closing this as a duplicate. Your #8814 is reviewed and good, see there. Next time, a quick look at the issue for an existing PR saves you the work. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Issue number: closes #8796
Summary
Changes
math.isfinite(float(value))checks inMetricManager.add_metric(aws_lambda_powertools/metrics/base.py),AmazonCloudWatchEMFProvider.add_metric(aws_lambda_powertools/metrics/provider/cloudwatch_emf/cloudwatch.py), andDatadogProvider.add_metric(aws_lambda_powertools/metrics/provider/datadog/datadog.py).PowertoolsUserWarningand skip non-finite values (NaN,inf,-inf) per ADR 0006, preserving all other valid metrics in the flush.Metrics,AmazonCloudWatchEMFProvider,SingleMetric, andDatadogMetrics.User experience
Before this change, passing a
NaNor infinite value toadd_metric(e.g. from division by zero in an average calculation) passed theisinstance(value, numbers.Number)check. At flush time,json.dumpsemitted bareNaN/Infinity, corrupting the entire EMF line for all metrics in that flush into invalid JSON.After this change, non-finite values are caught with a clear
PowertoolsUserWarning, skipped, and all other valid metrics in the flush are serialized and published successfully without breaking the EMF line.Verification
tests/functional/metrics/required_dependencies/test_metrics_cloudwatch_emf.py: 102 passedtests/functional/metrics/datadog/test_metrics_datadog.py: 35 passedruff check --cache-dir /tmp/ruff_cache aws_lambda_powertools/metrics/ tests/functional/metrics/: 0 errorsruff format --check --cache-dir /tmp/ruff_cache aws_lambda_powertools/metrics/ tests/functional/metrics/: 0 modificationsBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.