Skip to content

feat(metrics): logMetrics middleware #338

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 32 commits into from
Dec 27, 2021
Merged

Conversation

saragerion
Copy link
Contributor

@saragerion saragerion commented Dec 17, 2021

Description of your changes

Business logic, tests, documentation and examples added for the logMetrics middy middleware.

How to verify this change

Docs:

  1. build the doc with npm run docs-runLocalDocker0
  2. go to http://localhost:8000/core/metrics/

Examples:
See added NPM scripts for examples in the package.json file.

Related issues, RFCs

#25

PR status

Is this ready for review?: YES
Is it a breaking change?: NO

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
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published in downstream module
  • The PR title follows the conventional commit semantics

Breaking change checklist

N/A


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

@saragerion saragerion changed the title Feat/metrics middleware feat(metrics): logMetrics middleware Dec 21, 2021
@saragerion saragerion marked this pull request as ready for review December 21, 2021 18:27
@dreamorosi dreamorosi added metrics This item relates to the Metrics Utility enhancement labels Dec 22, 2021
@dreamorosi dreamorosi added this to the beta-release milestone Dec 22, 2021
@saragerion saragerion linked an issue Dec 22, 2021 that may be closed by this pull request
8 tasks
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

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

Great job, really like the rewording & edits on the docs as well.

Left some minor notes/comments.

Copy link
Contributor

@ijemmy ijemmy left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning out the inconsistent case style!

const getRandomInt = (): number => Math.floor(Math.random() * 1000000000);

const awsRequestId = getRandomInt().toString();
const context = {
Copy link
Contributor

Choose a reason for hiding this comment

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

(minor) Can we extract context object out to reuse and avoid duplication?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

dreamorosi
dreamorosi previously approved these changes Dec 23, 2021
@@ -227,7 +229,7 @@ describe('Class: Metrics', () => {
test('Cold start metric should only be written out once and flushed automatically', async () => {
const metrics = new Metrics({ namespace: 'test' });

const handler = async (event: any, context: Context) => {
const handler = async (_event: unknown, _context: unknown): Promise<void> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why moving _context to Unknown type ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was getting a linting error, and because we should use unknown instead of any, whenever needed: https://www.typescriptlang.org/docs/handbook/declaration-files/do-s-and-don-ts.html#any

Copy link
Contributor

Choose a reason for hiding this comment

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

weird that we are getting linting error when (for once :) ) we know which type to expect :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed it with a more descriptive type

@@ -361,7 +363,7 @@ describe('Class: Metrics', () => {
expect.assertions(1);

const metrics = new Metrics({ namespace: 'test' });
const handler = async (event: any, context: Context) => {
const handler = async (_event: unknown, _context: unknown): Promise<void> => {
Copy link
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See here: #338 (comment)

dreamorosi
dreamorosi previously approved these changes Dec 27, 2021
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

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

LGTM, thanks a lot for taking this one!

flochaz
flochaz previously approved these changes Dec 27, 2021
@saragerion saragerion dismissed stale reviews from flochaz and dreamorosi via 29d1c05 December 27, 2021 15:07
dreamorosi
dreamorosi previously approved these changes Dec 27, 2021
flochaz
flochaz previously approved these changes Dec 27, 2021
ijemmy
ijemmy previously approved these changes Dec 27, 2021
@saragerion saragerion dismissed stale reviews from ijemmy, flochaz, and dreamorosi via fe6bad1 December 27, 2021 19:44
@saragerion saragerion merged commit f8cf705 into main Dec 27, 2021
@saragerion saragerion deleted the feat/metrics-middleware branch December 27, 2021 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
metrics This item relates to the Metrics Utility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Metrics utility
4 participants