Skip to content

Add publicly accessible units #49

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

Merged
merged 4 commits into from
Aug 28, 2020
Merged

Add publicly accessible units #49

merged 4 commits into from
Aug 28, 2020

Conversation

jen-w
Copy link
Contributor

@jen-w jen-w commented Aug 20, 2020

Issue #, if available:
N/A

Description of changes:
Having .now() in utils is nice. As a developer using this package, it would be also great to have publicly accessible constants for metric units available. It not only reduces the chance of silly spelling mistakes, but benefits discoverability outside of the documentation.

https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html

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

@@ -14,3 +14,31 @@
DEFAULT_NAMESPACE = "aws-embedded-metrics"
MAX_DIMENSIONS = 9
MAX_METRICS_PER_EVENT = 100

# Units
SECONDS = "Seconds"
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the PR! Can we namespace (e.g. Units.SECONDS) these rather than dropping them in as constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The most pythonic way that comes to mind to namespace is moving these constants to a new file called units.py. Happy to implement this in the next revision or any alternative preferred. Please let me know, thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Another option would be use an Enum for the units. That'd have the advantage to play nicely with typing.

Copy link
Member

@jaredcnance jaredcnance Aug 26, 2020

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The thing I didn't really like with enum is that we'd access the string with something like Units.SECONDS.value, but I'm okay with that given the packages you linked use enum for units for consistency. One more question before I submit the next revision - should I create a new file, unit.py?

Copy link
Member

Choose a reason for hiding this comment

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

is that we'd access the string with something like Units.SECONDS.value

I think for this version that should be okay. In the next breaking version we may choose to replace the signature of put_metric with the new enum type. Any strong disagreements with that approach?

should I create a new file, unit.py

Yes, I think that's a good choice and then we can add it as a top-level import.

@jen-w jen-w changed the title Add publicly accessible units to constants.py Add publicly accessible units Aug 27, 2020
@jaredcnance jaredcnance merged commit a4d7bc0 into awslabs:master Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants