Skip to content

feat(metrics): logMetrics middleware - #338

Merged
saragerion merged 32 commits into
mainfrom
feat/metrics-middleware
Dec 27, 2021
Merged

feat(metrics): logMetrics middleware#338
saragerion merged 32 commits into
mainfrom
feat/metrics-middleware

Conversation

@saragerion

@saragerion saragerion commented Dec 17, 2021

Copy link
Copy Markdown
Contributor

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

@dreamorosi dreamorosi left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread packages/metrics/examples/empty-metrics.ts
Comment thread packages/metrics/examples/empty-metrics.ts
Comment thread packages/metrics/examples/programmatic-access.ts
Comment thread packages/metrics/package.json Outdated
Comment thread packages/metrics/src/middleware/middy.ts
Comment thread docs/core/metrics.md Outdated
Comment thread docs/core/metrics.md Outdated
Comment thread docs/core/metrics.md Outdated
Comment thread docs/core/metrics.md Outdated
Co-authored-by: Andrea Amorosi <dreamorosi@gmail.com>

@ijemmy ijemmy left a comment

Copy link
Copy Markdown
Contributor

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!

Comment thread docs/core/metrics.md Outdated
Comment thread docs/core/metrics.md Outdated
Comment thread docs/core/metrics.md Outdated
Comment thread docs/core/metrics.md Outdated
Comment thread docs/core/metrics.md Outdated
Comment thread packages/metrics/examples/decorator/single-metric.ts Outdated
Comment thread packages/metrics/examples/programmatic-access.ts
Comment thread packages/metrics/examples/single-metric.ts Outdated
Comment thread packages/metrics/package.json Outdated
const getRandomInt = (): number => Math.floor(Math.random() * 1000000000);

const awsRequestId = getRandomInt().toString();
const context = {

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

saragerion and others added 4 commits December 22, 2021 15:05
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
dreamorosi
dreamorosi previously approved these changes Dec 23, 2021
Comment thread packages/metrics/examples/cold-start.ts
Comment thread packages/metrics/src/middleware/middy.ts
const metrics = new Metrics({ namespace: 'test' });

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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


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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same

Copy link
Copy Markdown
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)

saragerion and others added 2 commits December 27, 2021 13:51
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
Co-authored-by: ijemmy <ijemmy@users.noreply.github.com>
dreamorosi
dreamorosi previously approved these changes Dec 27, 2021

@dreamorosi dreamorosi left a comment

Copy link
Copy Markdown
Contributor

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