Skip to content

feat(v2): upgrade embedded-metrics to v4 #1405

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
wants to merge 7 commits into from
Closed

Conversation

jeromevdl
Copy link
Contributor

Issue #, if available: #1041

Description of changes:

Upgrade to latest version of embedded-metrics

Checklist

Breaking change checklist

Checked exception instead of unchecked exception. I feel the new dev experience is shitty with these exceptions. Is there anything we can do?

RFC issue #:

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

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

@jeromevdl jeromevdl changed the title !feat: upgrade embedded-metrics to v4 feat!: upgrade embedded-metrics to v4 Aug 29, 2023
@jeromevdl jeromevdl changed the title feat!: upgrade embedded-metrics to v4 feat: upgrade embedded-metrics to v4 Aug 29, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@jeromevdl
Copy link
Contributor Author

@scottgerring I'm not happy with this, have a look at the examples, the experience is really bad now with these checked exceptions. We encapsulate some of them, should we go further? Review the module completely?

@scottgerring scottgerring linked an issue Aug 30, 2023 that may be closed by this pull request
@scottgerring
Copy link
Contributor

@jeromevdl I linked this to #1041 - do we cover off the whole thing here (high-res metrics), or just the upgrade?

@jeromevdl
Copy link
Contributor Author

I didn't check high-res, it's just an upgrade (don't know if high res is handled directly or if we need to do something).

@scottgerring
Copy link
Contributor

I didn't check high-res, it's just an upgrade (don't know if high res is handled directly or if we need to do something).

Should we look at high-res as part of this, or unlink it from the underlying issue and deal with that separately? It's one of the things on the V2 roadmap.

@jeromevdl
Copy link
Contributor Author

I didn't check high-res, it's just an upgrade (don't know if high res is handled directly or if we need to do something).

Should we look at high-res as part of this, or unlink it from the underlying issue and deal with that separately? It's one of the things on the V2 roadmap.

high res is provided with the new version, we have nothing to do on our side.

@jeromevdl jeromevdl added the v2 Version 2 label Sep 27, 2023
@scottgerring scottgerring self-requested a review September 28, 2023 06:12
@@ -44,7 +44,7 @@
* Handler for requests to Lambda function.
*/
public class App implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
private final static Logger log = LogManager.getLogger(App.class);
private static final Logger log = LogManager.getLogger(App.class);
Copy link
Contributor

Choose a reason for hiding this comment

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

What's up with all the whitespace changes?

Copy link
Contributor

@scottgerring scottgerring left a comment

Choose a reason for hiding this comment

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

Looks good and straightforward. Still not sure about the exception thing though ... I feel like this is the best of the bad options, but perhaps it is worth checking with the library why they've done it this way


package software.amazon.lambda.powertools.metrics.exception;

public class InvalidMetricDimensionException extends RuntimeException {
Copy link
Contributor

Choose a reason for hiding this comment

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

I gather we are using these to wrap the checked exceptions with RuntimeExceptions while retaining something catchable.

Worth explaining that and why we're doing it on the javadoc ?

} catch (InvalidNamespaceException e) {
throw new InvalidMetricNamespaceException(e);
} catch (InvalidMetricException e) {
throw new software.amazon.lambda.powertools.metrics.exception.InvalidMetricException(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit confusing that sometimes the wrapping RuntimeException has the same name and only a different NS and sometimes not

public class InvalidMetricNamespaceException extends RuntimeException {
private static final long serialVersionUID = -8758457068851174063L;
public static final String POWERTOOLS_METRICS_NAMESPACE_REQUIRED =
"A valid namespace is required, either pass it to the @Metrics annotation or set the environment variable POWERTOOLS_METRICS_NAMESPACE";
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear to me why we have custom messages inline in this one but not in e.g. InvalidMetricException


context.setDimensions(defaultDimensions);

f.set(metricsLogger(), context);
} catch (NoSuchFieldException | IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvalidDimensionException e) {
throw new InvalidMetricNamespaceException(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

InvalidDimensionException -> InvalidMetricNamespaceException?

try {
metricsLogger.putMetric("ColdStart", 1, Unit.COUNT);
} catch (InvalidMetricException e) {
// should not occur
Copy link
Contributor

Choose a reason for hiding this comment

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

Throw or error or something then? Empty catch blocks should at least set off a linter!

@@ -222,8 +222,12 @@ You can create metrics using `putMetric`, and manually create dimensions for all
@Override
@Metrics(namespace = "ExampleApplication", service = "booking")
public Object handleRequest(Object input, Context context) {
metricsLogger.putDimensions(DimensionSet.of("environment", "prod"));
metricsLogger.putMetric("SuccessfulBooking", 1, Unit.COUNT);
try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Worth documenting the exception transformation here, probably? I'm also wondering if we should reach out to the SDK team to understand their thinking for the checked exceptions here; maybe we are missing something.

@jeromevdl jeromevdl changed the title feat: upgrade embedded-metrics to v4 feat(v2): upgrade embedded-metrics to v4 Oct 24, 2023
@jeromevdl jeromevdl removed their assignment Nov 23, 2023
@scottgerring
Copy link
Contributor

@scottgerring scottgerring marked this pull request as draft December 7, 2023 09:20
@scottgerring
Copy link
Contributor

We need to redo this from the released version of the library without the checked exceptions we have extensively worked around here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/L v2 Version 2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: support high resolution metrics
2 participants