Skip to content

RFC: Metrics: Create a default dimension using the "service" name #61

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
to-mc opened this issue Jun 6, 2020 · 1 comment
Closed

RFC: Metrics: Create a default dimension using the "service" name #61

to-mc opened this issue Jun 6, 2020 · 1 comment
Labels

Comments

@to-mc
Copy link
Contributor

to-mc commented Jun 6, 2020

Key information

  • RFC PR:
  • Related issue(s), if known:
  • Area: Metrics
  • Meet tenets: Yes

Summary

Add a default dimension named "service" with a value of the provided service name if it exists (via Metrics constructor or env var).

Motivation

This would simplify what I think is the most common use case where users don't need multiple dimensions. It would enable creation of simple custom metrics without needing to think about the underlying CloudWatch dimension construct.

Proposal

With PR #60 the metrics interface was changed to behave more similarly to the other core utils, by accepting a service parameter or reading the POWERTOOLS_SERVICE_NAME env var. In the metrics util, this service is translated to the namespace used for metrics. We could also use this value to set a dimension by default: {"name": "service", "value": service_name}. This could be handled in the MetricManager constructor, by adding to the dimension_set dict if the service parameter is set.
This would remove the need to make a call to add_dimension, so the simplest implementation could look like:

metrics = Metrics(service="ServerlessAirline")

@metrics.log_metrics
def lambda_handler():
    # without this change we have to make a call to add dimensions here
    metrics.add_metric(name="Something", unit="Count", value=1)

Drawbacks

  1. We would potentially create additional billable custom metrics for users who want specify their own dimensions.
  2. The migration path is a bit awkward for anyone who is currently using the POWERTOOLS_SERVICE_NAME env var. Right now they are forced to use add_dimension, so they will start to see another dimension for all their metrics when they upgrade.

Rationale and alternatives

  • What other designs have been considered? Why not them?
  • What is the impact of not doing this?

Users of the library need to understand how CloudWatch metrics dimensions work. In my opinion this is quite hard to grasp from documentation. If we don't abstract this away by implementing this change, users who are not already familiar with CloudWatch can be faced with a time consuming trial/error cycle to discover how to properly use dimensions in their custom metrics. This is compounded by the fact that custom metrics can't be deleted - if mistakes are made here they will pollute the dashboard for 2 weeks until they expire.

Unresolved questions

Optional, stash area for topics that need further development e.g. TBD

@to-mc to-mc added RFC triage Pending triage from maintainers labels Jun 6, 2020
@ghost ghost removed the triage Pending triage from maintainers label Jun 6, 2020
@heitorlessa
Copy link
Contributor

heitorlessa commented Jun 6, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants