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

fix(metrics): add warning for invalid dimension values; prevent their addition to EMF blobs #5542

Merged
merged 4 commits into from
Nov 12, 2024

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #5526

Summary

Changes

Before this PR, if a customer added a dimension with an empty value, it caused EMF to skip all dimensions and create a metric without dimensions. For example:

{
    "_aws": {
        "Timestamp": 1731078543804,
        "CloudWatchMetrics": [
            {
                "Namespace": "kindle-scribe-llm-lambda",
                "Dimensions": [
                    [
                        "environment",
                        "stage"
                    ]
                ],
                "Metrics": [
                    {
                        "Name": "TEST_METRIC",
                        "Unit": "Count"
                    }
                ]
            }
        ]
    },
    "environment": "",
    "stage": "1",
    "TEST_METRIC": [
        1
    ]
}

This pull request enhances the metrics dimension handling by adding a warning for invalid dimension values and preventing these invalid dimensions from being added to the EMF (Enhanced Metric Format) blobs emitted by the utility.

Changes

  • Implement a validation check for dimension values when adding a dimension to metrics
  • Add a UserWarning warning to alert when an invalid dimension value is encountered
  • Prevent dimensions with invalid values (empty strings or None) from being added to EMF blobs

User experience

Customer will get the following warning:

aws_lambda_powertools/metrics/metrics.py:117: UserWarning: The dimension **some_dimension** doesn't meet the requirements and won't be added. Ensure the dimension name and value are non empty strings
    self.provider.add_dimension(name=name, value=value)

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@leandrodamascena leandrodamascena requested a review from a team as a code owner November 12, 2024 10:07
@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 12, 2024
@github-actions github-actions bot added the bug Something isn't working label Nov 12, 2024
Copy link

codecov bot commented Nov 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.16%. Comparing base (3b2148e) to head (846d1f2).
Report is 3 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #5542   +/-   ##
========================================
  Coverage    96.16%   96.16%           
========================================
  Files          229      229           
  Lines        10812    10815    +3     
  Branches      2008     2009    +1     
========================================
+ Hits         10397    10400    +3     
  Misses         327      327           
  Partials        88       88           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Nov 12, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Nov 12, 2024
dreamorosi
dreamorosi previously approved these changes Nov 12, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Nov 12, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Nov 12, 2024
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Nov 12, 2024
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Nov 12, 2024
Copy link

sonarcloud bot commented Nov 12, 2024

@leandrodamascena leandrodamascena merged commit f8fe2a3 into develop Nov 12, 2024
13 checks passed
@leandrodamascena leandrodamascena deleted the metrics/empty-dimension branch November 12, 2024 12:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working metrics size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: dimension value not being validated for empty strings or None
2 participants