-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add health, metrics and version
- Loading branch information
1 parent
7f6f41d
commit 95ec6a5
Showing
13 changed files
with
156 additions
and
75 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,11 +1,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
|
||
import { AppController } from './app.controller'; | ||
import { AppService } from './app.service'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { HealthModule } from './health/health.module'; | ||
import { MetricsModule } from './metrics/metrics.module'; | ||
import { VersionModule } from './version/version.module'; | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
imports: [ | ||
ConfigModule.forRoot({ isGlobal: true }), | ||
HealthModule, | ||
MetricsModule, | ||
VersionModule, | ||
], | ||
}) | ||
export class AppModule {} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,39 @@ | ||
import { Controller, Get, Inject } from '@nestjs/common'; | ||
import { | ||
HealthCheck, | ||
HealthCheckService, | ||
MemoryHealthIndicator, | ||
MicroserviceHealthIndicator, | ||
} from '@nestjs/terminus'; | ||
import { Transport } from '@nestjs/microservices'; | ||
import { azkaban_cronjob } from '@toxictoast/azkaban-broker-rabbitmq'; | ||
|
||
@Controller('health') | ||
export class HealthController { | ||
constructor( | ||
@Inject('MEMORY_HEAP_TRESHOLD') private readonly heapTreshold: number, | ||
@Inject('MEMORY_RSS_TRESHOLD') private readonly rssTreshold: number, | ||
@Inject('BROKER_CONNECTION_STRING') | ||
private readonly brokerConnectionString: string, | ||
private readonly service: HealthCheckService, | ||
private readonly memory: MemoryHealthIndicator, | ||
private readonly microservices: MicroserviceHealthIndicator, | ||
) {} | ||
|
||
@Get() | ||
@HealthCheck() | ||
check() { | ||
return this.service.check([ | ||
() => this.memory.checkHeap('memory_heap', this.heapTreshold), | ||
() => this.memory.checkRSS('memory_rss', this.rssTreshold), | ||
() => | ||
this.microservices.pingCheck('rabbitmq', { | ||
transport: Transport.RMQ, | ||
options: { | ||
urls: [this.brokerConnectionString], | ||
queue: azkaban_cronjob, | ||
}, | ||
}), | ||
]); | ||
} | ||
} |
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,42 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TerminusModule } from '@nestjs/terminus'; | ||
import { HealthController } from './health.controller'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
@Module({ | ||
imports: [ | ||
TerminusModule.forRoot({ | ||
errorLogStyle: 'pretty', | ||
}), | ||
], | ||
controllers: [HealthController], | ||
providers: [ | ||
{ | ||
provide: 'MEMORY_HEAP_TRESHOLD', | ||
useFactory: (config: ConfigService) => { | ||
return config.get('MEMORY_HEAP_TRESHOLD', 0); | ||
}, | ||
inject: [ConfigService], | ||
}, | ||
{ | ||
provide: 'MEMORY_RSS_TRESHOLD', | ||
useFactory: (config: ConfigService) => { | ||
return config.get('MEMORY_RSS_TRESHOLD', 0); | ||
}, | ||
inject: [ConfigService], | ||
}, | ||
{ | ||
provide: 'BROKER_CONNECTION_STRING', | ||
useFactory: (config: ConfigService) => { | ||
const username = config.get('BROKER_USERNAME', 'guest'); | ||
const password = config.get('BROKER_PASSWORD', 'guest'); | ||
const hostname = config.get('BROKER_HOST', 'localhost'); | ||
const port = config.get('BROKER_PORT', 5672); | ||
// | ||
return `amqp://${username}:${password}@${hostname}:${port}`; | ||
}, | ||
inject: [ConfigService], | ||
}, | ||
], | ||
}) | ||
export class HealthModule {} |
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,17 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { PrometheusModule } from '@willsoto/nestjs-prometheus'; | ||
|
||
@Module({ | ||
imports: [ | ||
PrometheusModule.register({ | ||
defaultMetrics: { | ||
enabled: true, | ||
}, | ||
defaultLabels: { | ||
app: 'cronjob-service', | ||
}, | ||
path: '/metrics', | ||
}), | ||
], | ||
}) | ||
export class MetricsModule {} |
14 changes: 14 additions & 0 deletions
14
apps/cronjob-service/src/app/version/version.controller.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,14 @@ | ||
import { Controller } from '@nestjs/common'; | ||
import { VersionService } from './version.service'; | ||
import { MessagePattern } from '@nestjs/microservices'; | ||
import { CronjobTopics } from '@toxictoast/azkaban-broker-rabbitmq'; | ||
|
||
@Controller('version') | ||
export class VersionController { | ||
constructor(private readonly service: VersionService) {} | ||
|
||
@MessagePattern(CronjobTopics.VERSION) | ||
async getVersion() { | ||
return this.service.getVersion(); | ||
} | ||
} |
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,19 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { VersionController } from './version.controller'; | ||
import { VersionService } from './version.service'; | ||
import { ConfigService } from '@nestjs/config'; | ||
|
||
@Module({ | ||
controllers: [VersionController], | ||
providers: [ | ||
VersionService, | ||
{ | ||
provide: 'APP_VERSION', | ||
useFactory: (config: ConfigService) => { | ||
return config.get('APP_VERSION', 'local'); | ||
}, | ||
inject: [ConfigService], | ||
}, | ||
], | ||
}) | ||
export class VersionModule {} |
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,10 @@ | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class VersionService { | ||
constructor(@Inject('APP_VERSION') private readonly appVersion: string) {} | ||
|
||
getVersion(): string { | ||
return this.appVersion; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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