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

feat(metrics): publish metrics when other middlewares return early #1546

Conversation

dreamorosi
Copy link
Contributor

Description of your changes

This PR introduces new logic to the logMetrics() Middy middleware offered by Metrics to allow it to close and publish any stored metric whenever another middleware down in the stack returns early.

This is made possible by the cleanupMiddlewares function shipped in commons in the previous release. The new logic sets a reference to a cleanup function in the Middy internal storage using a scoped key. This way, Middy middlewares that want to return early can call the cleanupMiddlewares function which will execute all the cleanup functions available. This is useful for those middlewares like Idempotency, that want to return a result bypassing the Lambda handler and the normal Middy request lifecycle.

I have also added a unit test case to verify that the cleanup logic is executed.

Related issues, RFCs

Issue number: #1535

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my change is effective and works
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary 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.

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

@dreamorosi dreamorosi requested a review from a team as a code owner June 22, 2023 14:35
@dreamorosi dreamorosi self-assigned this Jun 22, 2023
@boring-cyborg boring-cyborg bot added metrics This item relates to the Metrics Utility tests PRs that add or change tests labels Jun 22, 2023
@pull-request-size pull-request-size bot added the size/M PR between 30-99 LOC label Jun 22, 2023
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Jun 22, 2023
@dreamorosi
Copy link
Contributor Author

@dreamorosi
Copy link
Contributor Author

@am29d since the implementation is the same as the previous two PR that you have reviewed & we have passing tests I'm going to merge the PR.

@dreamorosi dreamorosi merged commit 58b0877 into main Jun 22, 2023
@dreamorosi dreamorosi deleted the 1535-feature-request-populate-middys-requestinternal-with-cleanup-function-for-metrics branch June 22, 2023 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs that introduce new features or minor changes metrics This item relates to the Metrics Utility size/M PR between 30-99 LOC tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: populate middy's request.internal with cleanup function for Metrics
1 participant