-
Notifications
You must be signed in to change notification settings - Fork 4k
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(app-gen, worker): Add MetricsService #4928
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2d6972b
feat(app-gen): Add metrics service and module
rifont d333636
test(api): Tidy up metrics service tests
rifont 7f7345f
test(app-gen): Throw errors on invalid metrics environment configuration
rifont 691cbd7
feat(app-gen): Export metrics service
rifont 43754e5
feat(worker): Use metrics service in worker
rifont bb942d7
fix(worker): Use metrics module only in workflow module
rifont 40dd417
feat(worker): Add env config for metrics service
rifont f9a1da8
feat(app-gen): Add startup logging to metrics service
rifont b137f26
fix(api): Encapsulate validity checker into metrics service
rifont 8aae1ba
fix(app-gen): Tidy up
rifont 1a470b5
fix(app-gen): Use correct storate resolution
rifont 555076b
test(worker): Add metrics service to tests
rifont File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
const nr = require('newrelic'); | ||
|
||
import { | ||
ActiveJobsMetricQueueService, | ||
ActiveJobsMetricWorkerService, | ||
MetricsService, | ||
QueueBaseService, | ||
WorkerOptions, | ||
} from '@novu/application-generic'; | ||
|
@@ -18,7 +17,7 @@ export class ActiveJobsMetricService { | |
public readonly activeJobsMetricQueueService: ActiveJobsMetricQueueService; | ||
public readonly activeJobsMetricWorkerService: ActiveJobsMetricWorkerService; | ||
|
||
constructor(@Inject('BULLMQ_LIST') private tokenList: QueueBaseService[]) { | ||
constructor(@Inject('BULLMQ_LIST') private tokenList: QueueBaseService[], private metricsService: MetricsService) { | ||
if (process.env.NOVU_MANAGED_SERVICE === 'true' && process.env.NEW_RELIC_LICENSE_KEY) { | ||
this.activeJobsMetricQueueService = new ActiveJobsMetricQueueService(); | ||
this.activeJobsMetricWorkerService = new ActiveJobsMetricWorkerService(); | ||
|
@@ -100,11 +99,9 @@ export class ActiveJobsMetricService { | |
|
||
Logger.verbose('Recording active, waiting, and delayed metrics'); | ||
|
||
nr.recordMetric(`Queue/${deploymentName}/${queueService.topic}/waiting`, waitCount); | ||
nr.recordMetric(`Queue/${deploymentName}/${queueService.topic}/delayed`, delayedCount); | ||
nr.recordMetric(`Queue/${deploymentName}/${queueService.topic}/active`, activeCount); | ||
|
||
Logger.verbose(`Queue/${deploymentName}/${queueService.topic}`, { waitCount, delayedCount, activeCount }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verbose logging is handled in the metrics service now. |
||
this.metricsService.recordMetric(`Queue/${deploymentName}/${queueService.topic}/waiting`, waitCount); | ||
this.metricsService.recordMetric(`Queue/${deploymentName}/${queueService.topic}/delayed`, delayedCount); | ||
this.metricsService.recordMetric(`Queue/${deploymentName}/${queueService.topic}/active`, activeCount); | ||
} | ||
|
||
return resolve(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
"reflect-metadata": "^0.1.13" | ||
}, | ||
"dependencies": { | ||
"@aws-sdk/client-cloudwatch": "^3.382.0", | ||
"@aws-sdk/client-s3": "^3.382.0", | ||
"@aws-sdk/s3-request-presigner": "^3.382.0", | ||
"@azure/storage-blob": "^12.11.0", | ||
|
@@ -137,12 +138,14 @@ | |
"@istanbuljs/nyc-config-typescript": "^1.0.1", | ||
"@types/analytics-node": "^3.1.9", | ||
"@types/jest": "29.5.2", | ||
"@types/newrelic": "^9", | ||
"@types/sinon": "^9.0.0", | ||
"codecov": "^3.5.0", | ||
"cpx": "^1.5.0", | ||
"dotenv": "^8.2.0", | ||
"chai": "^4.2.0", | ||
"jest": "^27.1.0", | ||
"newrelic": "^9", | ||
"npm-run-all": "^4.1.5", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding newrelic as devDependecies to keep the peer deps working as normal. |
||
"nyc": "^15.1.0", | ||
"prettier": "~2.8.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { QueuesModule } from './queues.module'; | ||
export { BaseApiQueuesModule } from './queues.module'; | ||
export { MetricsModule } from './metrics.module'; |
23 changes: 23 additions & 0 deletions
23
packages/application-generic/src/modules/metrics.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Module, Provider } from '@nestjs/common'; | ||
import { MetricsService, metricsServiceList } from '../services/metrics'; | ||
import { | ||
AwsMetricsService, | ||
AzureMetricsService, | ||
GCPMetricsService, | ||
NewRelicMetricsService, | ||
} from '../services/metrics/metrics.service'; | ||
|
||
const PROVIDERS: Provider[] = [ | ||
MetricsService, | ||
NewRelicMetricsService, | ||
GCPMetricsService, | ||
AzureMetricsService, | ||
AwsMetricsService, | ||
metricsServiceList, | ||
]; | ||
|
||
@Module({ | ||
providers: [...PROVIDERS], | ||
exports: [...PROVIDERS], | ||
}) | ||
export class MetricsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't being used, it's overridden below.