Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpStatus, Inject, Injectable } from '@nestjs/common'
import { HealthIndicatorService } from '@nestjs/terminus'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { PLUGIN_NAME } from './argocd.constants'

@Injectable()
export class ArgoCDHealthService {
Expand All @@ -9,8 +10,8 @@ export class ArgoCDHealthService {
@Inject(HealthIndicatorService) private readonly healthIndicator: HealthIndicatorService,
) {}

async check(key: string) {
const indicator = this.healthIndicator.check(key)
async check() {
const indicator = this.healthIndicator.check(PLUGIN_NAME)
const urlBase = this.config.getInternalOrPublicArgoCDUrl()
if (!urlBase) return indicator.down('Not configured')

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpStatus, Inject, Injectable } from '@nestjs/common'
import { HealthIndicatorService } from '@nestjs/terminus'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { PLUGIN_NAME } from '../vault/vault.constants'

@Injectable()
export class GitlabHealthService {
Expand All @@ -9,8 +10,8 @@ export class GitlabHealthService {
@Inject(HealthIndicatorService) private readonly healthIndicator: HealthIndicatorService,
) {}

async check(key: string) {
const indicator = this.healthIndicator.check(key)
async check() {
const indicator = this.healthIndicator.check(PLUGIN_NAME)
const urlBase = this.config.getInternalOrPublicGitlabUrl()
if (!urlBase) return indicator.down('Not configured')

Expand Down
51 changes: 4 additions & 47 deletions apps/server-nestjs/src/modules/healthz/healthz.controller.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,14 @@
import { Controller, Get, Inject } from '@nestjs/common'
import { HealthCheck, HealthCheckService } from '@nestjs/terminus'
import { ArgoCDHealthService } from '../argocd/argocd-health.service'
import { GitlabHealthService } from '../gitlab/gitlab-health.service'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { DatabaseHealthService } from '../infrastructure/database/database-health.service'
import { KeycloakHealthService } from '../keycloak/keycloak-health.service'
import { NexusHealthService } from '../nexus/nexus-health.service'
import { RegistryHealthService } from '../registry/registry-health.service'
import { ServiceChainHealthService } from '../service-chain/service-chain-health.service'
import { VaultHealthService } from '../vault/vault-health.service'
import { HealthCheck } from '@nestjs/terminus'
import { HealthzService } from './healthz.service'

@Controller('api/v1/healthz')
export class HealthzController {
constructor(
@Inject(HealthCheckService) private readonly health: HealthCheckService,
@Inject(DatabaseHealthService) private readonly database: DatabaseHealthService,
@Inject(KeycloakHealthService) private readonly keycloak: KeycloakHealthService,
@Inject(GitlabHealthService) private readonly gitlab: GitlabHealthService,
@Inject(VaultHealthService) private readonly vault: VaultHealthService,
@Inject(NexusHealthService) private readonly nexus: NexusHealthService,
@Inject(RegistryHealthService) private readonly registry: RegistryHealthService,
@Inject(ArgoCDHealthService) private readonly argocd: ArgoCDHealthService,
@Inject(ServiceChainHealthService) private readonly opencds: ServiceChainHealthService,
@Inject(ConfigurationService) private readonly config: ConfigurationService,
) {}
constructor(@Inject(HealthzService) private readonly healthz: HealthzService) {}

@Get()
@HealthCheck()
check() {
const checks = [
() => this.database.check('database'),
() => this.keycloak.check('keycloak'),
]

if (this.config.openCdsUrl) {
checks.push(() => this.opencds.check('opencds'))
}
if (this.config.gitlabUrl) {
checks.push(() => this.gitlab.check('gitlab'))
}
if (this.config.vaultUrl) {
checks.push(() => this.vault.check('vault'))
}
if (this.config.nexusUrl) {
checks.push(() => this.nexus.check('nexus'))
}
if (this.config.harborUrl) {
checks.push(() => this.registry.check('registry'))
}
if (this.config.argocdUrl) {
checks.push(() => this.argocd.check('argocd'))
}

return this.health.check(checks)
return this.healthz.check()
}
}
2 changes: 2 additions & 0 deletions apps/server-nestjs/src/modules/healthz/healthz.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { RegistryModule } from '../registry/registry.module'
import { ServiceChainModule } from '../service-chain/service-chain.module'
import { VaultModule } from '../vault/vault.module'
import { HealthzController } from './healthz.controller'
import { HealthzService } from './healthz.service'

@Module({
imports: [
Expand All @@ -25,5 +26,6 @@ import { HealthzController } from './healthz.controller'
ServiceChainModule,
],
controllers: [HealthzController],
providers: [HealthzService],
})
export class HealthzModule {}
44 changes: 44 additions & 0 deletions apps/server-nestjs/src/modules/healthz/healthz.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { HealthIndicatorFunction } from '@nestjs/terminus'
import { Inject, Injectable } from '@nestjs/common'
import { HealthCheckService } from '@nestjs/terminus'
import { ArgoCDHealthService } from '../argocd/argocd-health.service'
import { GitlabHealthService } from '../gitlab/gitlab-health.service'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { DatabaseHealthService } from '../infrastructure/database/database-health.service'
import { KeycloakHealthService } from '../keycloak/keycloak-health.service'
import { NexusHealthService } from '../nexus/nexus-health.service'
import { RegistryHealthService } from '../registry/registry-health.service'
import { ServiceChainHealthService } from '../service-chain/service-chain-health.service'
import { VaultHealthService } from '../vault/vault-health.service'

@Injectable()
export class HealthzService {
constructor(
@Inject(ConfigurationService) private readonly config: ConfigurationService,
@Inject(HealthCheckService) private readonly health: HealthCheckService,
@Inject(DatabaseHealthService) private readonly database: DatabaseHealthService,
@Inject(KeycloakHealthService) private readonly keycloak: KeycloakHealthService,
@Inject(GitlabHealthService) private readonly gitlab: GitlabHealthService,
@Inject(VaultHealthService) private readonly vault: VaultHealthService,
@Inject(NexusHealthService) private readonly nexus: NexusHealthService,
@Inject(RegistryHealthService) private readonly registry: RegistryHealthService,
@Inject(ArgoCDHealthService) private readonly argocd: ArgoCDHealthService,
@Inject(ServiceChainHealthService) private readonly serviceChainHealth: ServiceChainHealthService,
) {}

check() {
const checks: HealthIndicatorFunction[] = [
() => this.database.check(),
() => this.keycloak.check(),
]

if (this.config.gitlabUrl) checks.push(() => this.gitlab.check())
if (this.config.vaultUrl) checks.push(() => this.vault.check())
if (this.config.nexusUrl) checks.push(() => this.nexus.check())
if (this.config.harborUrl) checks.push(() => this.registry.check())
if (this.config.argocdUrl) checks.push(() => this.argocd.check())
if (this.config.openCdsUrl) checks.push(() => this.serviceChainHealth.check())

return this.health.check(checks)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Inject, Injectable } from '@nestjs/common'
import { HealthIndicatorService } from '@nestjs/terminus'
import { SERVICE_NAME } from './database.constants'
import { PrismaService } from './prisma.service'

@Injectable()
Expand All @@ -9,8 +10,8 @@ export class DatabaseHealthService {
@Inject(HealthIndicatorService) private readonly healthIndicator: HealthIndicatorService,
) {}

async check(key: string) {
const indicator = this.healthIndicator.check(key)
async check() {
const indicator = this.healthIndicator.check(SERVICE_NAME)
try {
await this.prisma.$queryRaw`SELECT 1`
return indicator.up()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Health indicator name for the database
export const SERVICE_NAME = 'database'
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpStatus, Inject, Injectable } from '@nestjs/common'
import { HealthIndicatorService } from '@nestjs/terminus'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { PLUGIN_NAME } from './keycloak.constants'

@Injectable()
export class KeycloakHealthService {
Expand All @@ -11,8 +12,8 @@ export class KeycloakHealthService {
private readonly healthIndicator: HealthIndicatorService,
) {}

async check(key: string) {
const indicator = this.healthIndicator.check(key)
async check() {
const indicator = this.healthIndicator.check(PLUGIN_NAME)
const url = this.config.getKeycloakOpenidConfigurationUrl()
if (!url) return indicator.down('Not configured')

Expand Down
5 changes: 3 additions & 2 deletions apps/server-nestjs/src/modules/nexus/nexus-health.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpStatus, Inject, Injectable } from '@nestjs/common'
import { HealthIndicatorService } from '@nestjs/terminus'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { PLUGIN_NAME } from './nexus.constants'

@Injectable()
export class NexusHealthService {
Expand All @@ -9,8 +10,8 @@ export class NexusHealthService {
@Inject(HealthIndicatorService) private readonly healthIndicator: HealthIndicatorService,
) {}

async check(key: string) {
const indicator = this.healthIndicator.check(key)
async check() {
const indicator = this.healthIndicator.check(PLUGIN_NAME)
if (!this.config.nexusInternalUrl) return indicator.down('Not configured')

const url = new URL('/service/rest/v1/status', this.config.nexusInternalUrl).toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpStatus, Inject, Injectable } from '@nestjs/common'
import { HealthIndicatorService } from '@nestjs/terminus'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { PLUGIN_NAME } from './registry.constants'

@Injectable()
export class RegistryHealthService {
Expand All @@ -9,8 +10,8 @@ export class RegistryHealthService {
@Inject(HealthIndicatorService) private readonly healthIndicator: HealthIndicatorService,
) {}

async check(key: string) {
const indicator = this.healthIndicator.check(key)
async check() {
const indicator = this.healthIndicator.check(PLUGIN_NAME)
if (!this.config.harborInternalUrl) return indicator.down('Not configured')

const url = new URL('/api/v2.0/ping', this.config.harborInternalUrl).toString()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpStatus, Inject, Injectable } from '@nestjs/common'
import { HealthIndicatorService } from '@nestjs/terminus'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { PLUGIN_NAME } from './service-chain.constants'

@Injectable()
export class ServiceChainHealthService {
Expand All @@ -9,8 +10,8 @@ export class ServiceChainHealthService {
@Inject(HealthIndicatorService) private readonly healthIndicator: HealthIndicatorService,
) {}

async check(key: string) {
const indicator = this.healthIndicator.check(key)
async check() {
const indicator = this.healthIndicator.check(PLUGIN_NAME)
if (!this.config.openCdsUrl) return indicator.down('Not configured')

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Plugin name for the service-chain module
export const PLUGIN_NAME = 'service-chain'
5 changes: 3 additions & 2 deletions apps/server-nestjs/src/modules/vault/vault-health.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpStatus, Inject, Injectable } from '@nestjs/common'
import { HealthIndicatorService } from '@nestjs/terminus'
import { ConfigurationService } from '../infrastructure/configuration/configuration.service'
import { PLUGIN_NAME } from './vault.constants'

@Injectable()
export class VaultHealthService {
Expand All @@ -9,8 +10,8 @@ export class VaultHealthService {
@Inject(HealthIndicatorService) private readonly healthIndicator: HealthIndicatorService,
) {}

async check(key: string) {
const indicator = this.healthIndicator.check(key)
async check() {
const indicator = this.healthIndicator.check(PLUGIN_NAME)
const urlBase = this.config.getInternalOrPublicVaultUrl()
if (!urlBase) return indicator.down('Not configured')

Expand Down
Loading