-
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.
- Loading branch information
1 parent
310eb12
commit 010d6ee
Showing
18 changed files
with
334 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": ["../../.eslintrc.json"], | ||
"ignorePatterns": ["!**/*"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.ts", "*.tsx"], | ||
"rules": {} | ||
}, | ||
{ | ||
"files": ["*.js", "*.jsx"], | ||
"rules": {} | ||
} | ||
] | ||
} |
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 @@ | ||
.env |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-disable */ | ||
export default { | ||
displayName: 'azkaban-webhooks', | ||
preset: '../../jest.preset.js', | ||
testEnvironment: 'node', | ||
transform: { | ||
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }], | ||
}, | ||
moduleFileExtensions: ['ts', 'js', 'html'], | ||
coverageDirectory: '../../coverage/apps/azkaban-webhooks', | ||
}; |
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,38 @@ | ||
{ | ||
"name": "azkaban-webhooks", | ||
"$schema": "../../node_modules/nx/schemas/project-schema.json", | ||
"sourceRoot": "apps/azkaban-webhooks/src", | ||
"projectType": "application", | ||
"tags": [], | ||
"targets": { | ||
"serve": { | ||
"executor": "@nx/js:node", | ||
"defaultConfiguration": "development", | ||
"options": { | ||
"buildTarget": "azkaban-webhooks:build" | ||
}, | ||
"configurations": { | ||
"development": { | ||
"buildTarget": "azkaban-webhooks:build:development" | ||
}, | ||
"production": { | ||
"buildTarget": "azkaban-webhooks:build:production" | ||
} | ||
} | ||
}, | ||
"test": { | ||
"executor": "@nx/jest:jest", | ||
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"], | ||
"options": { | ||
"jestConfig": "apps/azkaban-webhooks/jest.config.ts" | ||
} | ||
}, | ||
"docker-build": { | ||
"dependsOn": ["build"], | ||
"command": "docker build -f apps/azkaban-webhooks/Dockerfile . -t azkaban2015/webhooks:{args.VERSION}" | ||
}, | ||
"docker-push": { | ||
"command": "docker push azkaban2015/webhooks:{args.VERSION}" | ||
} | ||
} | ||
} |
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,28 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { HealthModule } from './health/health.module'; | ||
import { MetricsModule } from './metrics/metrics.module'; | ||
import { VersionModule } from './version/version.module'; | ||
import { RouterModule } from '@nestjs/core'; | ||
|
||
@Module({ | ||
imports: [ | ||
HealthModule, | ||
MetricsModule, | ||
VersionModule, | ||
RouterModule.register([ | ||
{ | ||
path: 'health', | ||
module: HealthModule, | ||
}, | ||
{ | ||
path: 'metrics', | ||
module: MetricsModule, | ||
}, | ||
{ | ||
path: 'version', | ||
module: VersionModule, | ||
}, | ||
]), | ||
], | ||
}) | ||
export class AppModule {} |
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,40 @@ | ||
import { Controller, Get, Inject } from '@nestjs/common'; | ||
import { | ||
HealthCheck, | ||
HealthCheckService, | ||
MemoryHealthIndicator, | ||
MicroserviceHealthIndicator, | ||
TypeOrmHealthIndicator, | ||
} from '@nestjs/terminus'; | ||
import { Transport } from '@nestjs/microservices'; | ||
|
||
@Controller() | ||
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, | ||
private readonly database: TypeOrmHealthIndicator | ||
) {} | ||
|
||
@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], | ||
}, | ||
}), | ||
() => this.database.pingCheck('postgres'), | ||
]); | ||
} | ||
} |
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,27 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TerminusModule } from '@nestjs/terminus'; | ||
import { HealthController } from './health.controller'; | ||
|
||
@Module({ | ||
imports: [ | ||
TerminusModule.forRoot({ | ||
errorLogStyle: 'pretty', | ||
}), | ||
], | ||
controllers: [HealthController], | ||
providers: [ | ||
{ | ||
provide: 'MEMORY_HEAP_TRESHOLD', | ||
useValue: process.env.MEMORY_HEAP_TRESHOLD, | ||
}, | ||
{ | ||
provide: 'MEMORY_RSS_TRESHOLD', | ||
useValue: process.env.MEMORY_RSS_TRESHOLD, | ||
}, | ||
{ | ||
provide: 'BROKER_CONNECTION_STRING', | ||
useValue: `amqp://${process.env.BROKER_USERNAME}:${process.env.BROKER_PASSWORD}@${process.env.BROKER_HOST}:${process.env.BROKER_PORT}`, | ||
}, | ||
], | ||
}) | ||
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: 'azkaban-webhooks', | ||
}, | ||
path: '/metrics', | ||
}), | ||
], | ||
}) | ||
export class MetricsModule {} |
12 changes: 12 additions & 0 deletions
12
apps/azkaban-webhooks/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,12 @@ | ||
import { Controller, UseGuards } from '@nestjs/common'; | ||
import { ThrottlerGuard } from '@nestjs/throttler'; | ||
import { VersionService } from './version.service'; | ||
|
||
@Controller() | ||
export class VersionController { | ||
constructor(private readonly service: VersionService) {} | ||
|
||
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,15 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { VersionController } from './version.controller'; | ||
import { VersionService } from './version.service'; | ||
|
||
@Module({ | ||
controllers: [VersionController], | ||
providers: [ | ||
VersionService, | ||
{ | ||
provide: 'APP_VERSION', | ||
useValue: process.env.APP_VERSION, | ||
}, | ||
], | ||
}) | ||
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; | ||
} | ||
} |
Empty file.
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,52 @@ | ||
import { INestApplication, Logger } from '@nestjs/common'; | ||
import { NestFactory } from '@nestjs/core'; | ||
import { Transport } from '@nestjs/microservices'; | ||
import { AppModule } from './app/app.module'; | ||
|
||
async function createApp(): Promise<INestApplication> { | ||
return await NestFactory.create(AppModule, { | ||
cors: true, | ||
snapshot: true, | ||
rawBody: true, | ||
}); | ||
} | ||
|
||
async function createMicroservice(app: INestApplication): Promise<void> { | ||
const queue = 'azkaban_webhook_queue'; | ||
const connectionString = `amqp://${process.env.BROKER_USERNAME}:${process.env.BROKER_PASSWORD}@${process.env.BROKER_HOST}:${process.env.BROKER_PORT}`; | ||
const noAck = process.env.BROKER_ACK === 'yes' ? true : false; | ||
// | ||
app.connectMicroservice({ | ||
transport: Transport.RMQ, | ||
options: { | ||
queue: queue, | ||
queueOptions: { | ||
durable: true, | ||
}, | ||
urls: [connectionString], | ||
noAck: noAck, | ||
}, | ||
}); | ||
} | ||
|
||
function configureApp(app: INestApplication): void { | ||
const globalPrefix = 'api'; | ||
app.setGlobalPrefix(globalPrefix); | ||
app.enableShutdownHooks(); | ||
} | ||
|
||
async function startApp(app: INestApplication): Promise<void> { | ||
const port = process.env.PORT ?? 3000; | ||
await app.listen(port); | ||
Logger.log(`🚀 Listening on Port: ${port}`); | ||
} | ||
|
||
async function bootstrap() { | ||
const app = await createApp(); | ||
configureApp(app); | ||
await createMicroservice(app); | ||
await startApp(app); | ||
Logger.log(`🚀 Azkaban-Webhooks is running`); | ||
Logger.log(`🚀 Version: ${process.env.APP_VERSION}`); | ||
} | ||
bootstrap().catch((err) => Logger.error(err)); |
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,12 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["node"], | ||
"emitDecoratorMetadata": true, | ||
"target": "es2021" | ||
}, | ||
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"], | ||
"include": ["src/**/*.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,16 @@ | ||
{ | ||
"extends": "../../tsconfig.base.json", | ||
"files": [], | ||
"include": [], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.app.json" | ||
}, | ||
{ | ||
"path": "./tsconfig.spec.json" | ||
} | ||
], | ||
"compilerOptions": { | ||
"esModuleInterop": true | ||
} | ||
} |
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 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "../../dist/out-tsc", | ||
"module": "commonjs", | ||
"types": ["jest", "node"] | ||
}, | ||
"include": [ | ||
"jest.config.ts", | ||
"src/**/*.test.ts", | ||
"src/**/*.spec.ts", | ||
"src/**/*.d.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,19 @@ | ||
const { NxAppWebpackPlugin } = require('@nx/webpack/app-plugin'); | ||
const { join } = require('path'); | ||
|
||
module.exports = { | ||
output: { | ||
path: join(__dirname, '../../dist/apps/azkaban-webhooks'), | ||
}, | ||
plugins: [ | ||
new NxAppWebpackPlugin({ | ||
target: 'node', | ||
compiler: 'tsc', | ||
main: './src/main.ts', | ||
tsConfig: './tsconfig.app.json', | ||
assets: ['./src/assets'], | ||
optimization: false, | ||
outputHashing: 'none', | ||
}), | ||
], | ||
}; |