Skip to content

Feature request: support high resolution metrics #1908

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

Closed
2 tasks done
dreamorosi opened this issue Feb 8, 2023 · 2 comments · Fixed by #1915
Closed
2 tasks done

Feature request: support high resolution metrics #1908

dreamorosi opened this issue Feb 8, 2023 · 2 comments · Fixed by #1915
Assignees
Labels

Comments

@dreamorosi
Copy link
Contributor

Use case

Amazon CloudWatch announced support for high resolution metric extraction from structured logs (EMF). Customers can now provide an optional StorageResolution parameter within the EMF specification with a value of 1 or 60 (default) to indicate the desired resolution (in seconds) of the metric.

We should consider adding support for this new optional parameter to Metrics.

The EMF log should have this format:

{
  "_aws": {
    "CloudWatchMetrics": [
      {
        "Metrics": [
          {
            "Name": "Time",
            "Unit": "Milliseconds",
            "StorageResolution": 60 // <- new key
          }
        ],
        ...
      }
    ]
  },
  "Time": 1
}

As part of this issue we should also update the API docs, documentation, and unit/integration tests.

Solution/User Experience

from aws_lambda_powertools import Metrics
from aws_lambda_powertools.metrics import MetricUnit, MetricResolution
from aws_lambda_powertools.utilities.typing import LambdaContext

metrics = Metrics()


@metrics.log_metrics  # ensures metrics are flushed upon request completion/failure
def lambda_handler(event: dict, context: LambdaContext):
    # Publish a metric with standard resolution i.e. StorageResolution = 60
    metrics.add_metric(name="SuccessfulBooking", unit=MetricUnit.Count, value=1, resolution=MetricResolution.Standard)

    # Publish a metric with high resolution i.e. StorageResolution = 1
    metrics.add_metric(name="FailedBooking", unit=MetricUnit.Count, value=1, resolution=MetricResolution.High)

    # The last parameter (storage resolution) is optional
    metrics.add_metric(name="SuccessfulUpgrade", unit=MetricUnit.Count, value=1)

To support the proposal, a new MetricResolution enum should be added:

class MetricResolution(Enum):
    Standard = 60
    High = 1

and changes should be made to the Metrics.add_metric method to allow for a new optional parameter.

Note
The EMF specification states that if a value is not provided, then a default value of 60 is assumed (aka standard resolution). For this reason, if the resolution parameter is not specified we won't add the resolution.

Alternative solutions

No response

Acknowledgment

@dreamorosi dreamorosi added feature-request feature request triage Pending triage from maintainers labels Feb 8, 2023
@leandrodamascena leandrodamascena self-assigned this Feb 8, 2023
@heitorlessa heitorlessa added metrics and removed triage Pending triage from maintainers labels Feb 9, 2023
@heitorlessa heitorlessa linked a pull request Feb 9, 2023 that will close this issue
7 tasks
@github-actions
Copy link
Contributor

⚠️COMMENT VISIBILITY WARNING⚠️

This issue is now closed. Please be mindful that future comments are hard for our team to see.

If you need more assistance, please either tag a team member or open a new issue that references this one.

If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Feb 10, 2023
@github-actions
Copy link
Contributor

This is now released under 2.8.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants