Skip to content

Commit

Permalink
feat: healthcheck for external services (#4048)
Browse files Browse the repository at this point in the history
* chore: installed terminus package and scaffolded the health module

* feat: added healthcheck for database with prisma

* chore: renamed label from prisma to database in health check route

* chore: reverted target of hopp-old-backend service to prod
  • Loading branch information
balub committed May 7, 2024
1 parent 391e5a2 commit 5c4b651
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/hoppscotch-backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"@nestjs/passport": "10.0.2",
"@nestjs/platform-express": "10.2.7",
"@nestjs/schedule": "4.0.1",
"@nestjs/terminus": "10.2.3",
"@nestjs/throttler": "5.0.1",
"@prisma/client": "5.8.1",
"argon2": "0.30.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/hoppscotch-backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { loadInfraConfiguration } from './infra-config/helper';
import { MailerModule } from './mailer/mailer.module';
import { PosthogModule } from './posthog/posthog.module';
import { ScheduleModule } from '@nestjs/schedule';
import { HealthModule } from './health/health.module';

@Module({
imports: [
Expand Down Expand Up @@ -100,6 +101,7 @@ import { ScheduleModule } from '@nestjs/schedule';
InfraConfigModule,
PosthogModule,
ScheduleModule.forRoot(),
HealthModule,
],
providers: [GQLComplexityPlugin],
controllers: [AppController],
Expand Down
24 changes: 24 additions & 0 deletions packages/hoppscotch-backend/src/health/health.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Controller, Get } from '@nestjs/common';
import {
HealthCheck,
HealthCheckService,
PrismaHealthIndicator,
} from '@nestjs/terminus';
import { PrismaService } from 'src/prisma/prisma.service';

@Controller('health')
export class HealthController {
constructor(
private health: HealthCheckService,
private prismaHealth: PrismaHealthIndicator,
private prisma: PrismaService,
) {}

@Get()
@HealthCheck()
check() {
return this.health.check([
async () => this.prismaHealth.pingCheck('database', this.prisma),
]);
}
}
10 changes: 10 additions & 0 deletions packages/hoppscotch-backend/src/health/health.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from '@nestjs/common';
import { HealthController } from './health.controller';
import { PrismaModule } from 'src/prisma/prisma.module';
import { TerminusModule } from '@nestjs/terminus';

@Module({
imports: [PrismaModule, TerminusModule],
controllers: [HealthController],
})
export class HealthModule {}
105 changes: 105 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5c4b651

Please sign in to comment.