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: add metrics #102

Merged
merged 28 commits into from
Aug 11, 2021
Merged

feat: add metrics #102

merged 28 commits into from
Aug 11, 2021

Conversation

alan-churley
Copy link
Contributor

@alan-churley alan-churley commented Jul 7, 2021

Description of your changes

Initial draft of the Metrics module,

It's rough, so feedback is very welcome

How to verify this change

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

  • 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.

@alan-churley alan-churley changed the title Feature/metrics feat: add metrics Jul 7, 2021
@saragerion saragerion added this to In progress in Issues via automation Jul 16, 2021
@saragerion saragerion added this to the beta-release milestone Jul 16, 2021
@saragerion saragerion linked an issue Jul 16, 2021 that may be closed by this pull request
@saragerion saragerion added this to Pull Requests - Work in progress in Pull Requests Jul 20, 2021
@saragerion saragerion removed this from Issues - In progress (triaged) in Issues Jul 20, 2021
@github-actions
Copy link
Contributor

Coverage after merging feature/metrics into main

100.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
./packages/logger/src
   Logger.ts100%100%100%100%
   helpers.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/formatter
   LogFormatter.ts100%100%100%100%
   PowertoolLogFormatter.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/log
   LogItem.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src
   Metrics.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%

Copy link
Contributor

@bahrmichael bahrmichael left a comment

Choose a reason for hiding this comment

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

Left a couple comments, most of them are non-blocking.

packages/metrics/package.json Outdated Show resolved Hide resolved
packages/metrics/src/Metrics.ts Outdated Show resolved Hide resolved
packages/metrics/src/Metrics.ts Outdated Show resolved Hide resolved
private serviceVariable = 'POWERTOOLS_SERVICE_NAME';

public get(name: string): string {
return process.env[name]?.trim() || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

I may not have caught usages of this, but why return an empty string instead of undefined? Personally I find undefined clearer than an empty string, but I'm aware that this would lead to a string | undefined in a lot of signatures.

Noticed if (targetService.length > 0) { in Metrics.ts which could be reduced to if (targetService).

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this logic was taken from the Logger. I do not have a strong opinion on this, my reasoning was that an environment variable is always a string.
Happy to revisit this!

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 did take this from the logger, But slightly agree with @saragerion that ENV vars should always be strings,

Whatever we decide here I think we should apply it consistently across the pacakges

Copy link
Contributor

Choose a reason for hiding this comment

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

@bahrmichael what's your take on this? One of these:

  1. Keep it as it is;
  2. Change it as you suggested, for the beta;
  3. Create a ticket to explore the issue after the beta;

I am in favour of 1 or 3.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm in favor of 3.

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've raised a placeholder issue #165 for visibility of this across all modules

packages/metrics/tests/unit/Metrics.test.ts Outdated Show resolved Hide resolved
packages/metrics/tests/unit/Metrics.test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@saragerion saragerion 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 your PR @alan-churley! 🎉
I left few comments, nothing major but curious to get yours and everyone's perspective on the points raised.
Let me know if you have any question.

packages/metrics/README.md Outdated Show resolved Hide resolved
packages/metrics/README.md Show resolved Hide resolved
packages/metrics/examples/empty-metrics.ts Show resolved Hide resolved
packages/metrics/src/Metrics.ts Show resolved Hide resolved
packages/metrics/README.md Show resolved Hide resolved
packages/metrics/src/Metrics.ts Outdated Show resolved Hide resolved
packages/metrics/src/Metrics.ts Show resolved Hide resolved
packages/metrics/tests/unit/Metrics.test.ts Outdated Show resolved Hide resolved
Pull Requests automation moved this from Pull Requests - Work in progress to Pull Requests - Review needed Jul 29, 2021
@github-actions
Copy link
Contributor

Coverage after merging feature/metrics into main

100.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
./packages/logger/src
   Logger.ts100%100%100%100%
   helpers.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/formatter
   LogFormatter.ts100%100%100%100%
   PowertoolLogFormatter.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/log
   LogItem.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src
   Metrics.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%

@github-actions
Copy link
Contributor

Coverage after merging feature/metrics into main

100.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
./packages/logger/src
   Logger.ts100%100%100%100%
   helpers.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/formatter
   LogFormatter.ts100%100%100%100%
   PowertoolLogFormatter.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/log
   LogItem.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src
   Metrics.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%

packages/metrics/README.md Outdated Show resolved Hide resolved
packages/metrics/README.md Show resolved Hide resolved
packages/metrics/README.md Show resolved Hide resolved
Copy link
Contributor

@saragerion saragerion 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 @alan-churley ! I left a new round of comments - none of them are major or a priority for the beta, but let's keep track of possible improvement points via issues please.
Happy to approve once this is done!

packages/metrics/src/Metrics.ts Outdated Show resolved Hide resolved
packages/metrics/src/Metrics.ts Outdated Show resolved Hide resolved
packages/metrics/src/Metrics.ts Outdated Show resolved Hide resolved
packages/metrics/src/Metrics.ts Outdated Show resolved Hide resolved
packages/metrics/src/Metrics.ts Show resolved Hide resolved
packages/metrics/tests/unit/Metrics.test.ts Show resolved Hide resolved
private serviceVariable = 'POWERTOOLS_SERVICE_NAME';

public get(name: string): string {
return process.env[name]?.trim() || '';
Copy link
Contributor

Choose a reason for hiding this comment

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

@bahrmichael what's your take on this? One of these:

  1. Keep it as it is;
  2. Change it as you suggested, for the beta;
  3. Create a ticket to explore the issue after the beta;

I am in favour of 1 or 3.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 6, 2021

Coverage after merging feature/metrics into main

100.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
./packages/logger/src
   Logger.ts100%100%100%100%
   helpers.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/formatter
   LogFormatter.ts100%100%100%100%
   PowertoolLogFormatter.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/log
   LogItem.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src
   Metrics.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%

bahrmichael
bahrmichael previously approved these changes Aug 10, 2021
@github-actions
Copy link
Contributor

Coverage after merging feature/metrics into main

100.00%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
./packages/logger/src
   Logger.ts100%100%100%100%
   helpers.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/formatter
   LogFormatter.ts100%100%100%100%
   PowertoolLogFormatter.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/logger/src/log
   LogItem.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src
   Metrics.ts100%100%100%100%
   index.ts100%100%100%100%
./packages/metrics/src/config
   ConfigService.ts100%100%100%100%
   EnvironmentVariablesService.ts100%100%100%100%
   index.ts100%100%100%100%

saragerion
saragerion previously approved these changes Aug 10, 2021
Copy link
Contributor

@saragerion saragerion left a comment

Choose a reason for hiding this comment

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

LGTM

packages/metrics/src/Metrics.ts Outdated Show resolved Hide resolved
throw new RangeError('The number of metrics recorded must be higher than zero');
}

/* TODO: Potentially a logger.warn users here if default namespace should be used? */
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the default namespace? "Default"? +1 for adding a console.warn.

Pull Requests automation moved this from Pull Requests - Review needed to Pull Requests - Approved and ready to be merged Aug 11, 2021
@alan-churley alan-churley merged commit cf22210 into main Aug 11, 2021
Pull Requests automation moved this from Pull Requests - Approved and ready to be merged to Pull Requests - Merged or Closed Aug 11, 2021
@alan-churley alan-churley deleted the feature/metrics branch August 11, 2021 10:08
@flochaz flochaz mentioned this pull request Dec 6, 2021
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Pull Requests
Pull Requests - Merged or Closed
Development

Successfully merging this pull request may close these issues.

RFC: naming convention of core utilities
5 participants