From 644bc645f94d57094dacf33294ff5f6d3dafa6b4 Mon Sep 17 00:00:00 2001 From: Etienne Bechara Date: Mon, 11 Nov 2024 19:55:11 -0300 Subject: [PATCH] fix(app): remove automatic status endpoint --- source/app/app.controller.ts | 12 ---------- source/app/app.dto.out.ts | 40 ---------------------------------- source/app/app.interface.ts | 2 -- source/app/app.module.ts | 17 +-------------- source/app/app.service.spec.ts | 21 ------------------ source/app/app.service.ts | 26 ---------------------- source/trace/trace.service.ts | 2 +- 7 files changed, 2 insertions(+), 118 deletions(-) delete mode 100644 source/app/app.dto.out.ts delete mode 100644 source/app/app.service.spec.ts diff --git a/source/app/app.controller.ts b/source/app/app.controller.ts index 59c6f57b..8db24108 100644 --- a/source/app/app.controller.ts +++ b/source/app/app.controller.ts @@ -1,26 +1,14 @@ import { Controller, Get, HttpCode, HttpStatus } from '@nestjs/common'; import { ApiExcludeController } from '@nestjs/swagger'; -import { AppStatusDto } from './app.dto.out'; -import { AppService } from './app.service'; - @Controller() @ApiExcludeController() export class AppController { - public constructor( - private readonly appService: AppService, - ) { } - @Get() @HttpCode(HttpStatus.NO_CONTENT) public get(): void { return; } - @Get('status') - public getStatus(): AppStatusDto { - return this.appService.getStatus(); - } - } diff --git a/source/app/app.dto.out.ts b/source/app/app.dto.out.ts deleted file mode 100644 index e4103540..00000000 --- a/source/app/app.dto.out.ts +++ /dev/null @@ -1,40 +0,0 @@ -import os from 'os'; - -export interface AppStatusSystemDto { - version: string; - type: string; - release: string; - architecture: string; - endianness: string; - uptime: number; -} - -export interface AppStatusMemoryDto { - total: number; - free: number; -} - -export interface AppStatusCpuTimesDto { - user: number; - nice: number; - sys: number; - idle: number; - irq: number; -} - -export interface AppStatusCpuDto { - model: string; - speed: number; - times: AppStatusCpuTimesDto; -} - -export interface AppStatusNetworkDto { - interfaces: NodeJS.Dict; -} - -export interface AppStatusDto { - system: AppStatusSystemDto; - cpus: AppStatusCpuDto[]; - memory: AppStatusMemoryDto; - network: AppStatusNetworkDto; -} diff --git a/source/app/app.interface.ts b/source/app/app.interface.ts index 4f648b0c..ef761474 100644 --- a/source/app/app.interface.ts +++ b/source/app/app.interface.ts @@ -22,8 +22,6 @@ export interface AppOptions extends ModuleMetadata { disableAll?: boolean; /** Disables automatically importing `*.module.ts` files. */ disableScan?: boolean; - /** Disables status endpoints `/` and `/status`. */ - disableStatus?: boolean; /** Disables built-in exception filter `app.filter.ts`. */ disableFilter?: boolean; /** Disables validation pipe which applies `class-validator` decorators. */ diff --git a/source/app/app.module.ts b/source/app/app.module.ts index b88d00cd..99689c5c 100644 --- a/source/app/app.module.ts +++ b/source/app/app.module.ts @@ -131,7 +131,6 @@ export class AppModule { this.options.disableLogs = true; this.options.disableMetrics = true; this.options.disableScan = true; - this.options.disableStatus = true; this.options.disableValidator = true; } @@ -271,7 +270,7 @@ export class AppModule { return { module: AppModule, imports: this.buildModules('imports'), - controllers: this.buildControllers(), + controllers: [ ...this.options.controllers, AppController ], providers: this.buildProviders(), exports: [ AppConfig, @@ -355,20 +354,6 @@ export class AppModule { return preloadedModules; } - /** - * Adds app controller with machine status information. - */ - private static buildControllers(): any[] { - const { disableStatus, controllers } = this.options; - const preloadedControllers = [ ]; - - if (!disableStatus) { - preloadedControllers.push(AppController); - } - - return [ ...preloadedControllers, ...controllers ]; - } - /** * Adds exception filter, serializer, timeout and validation pipe. */ diff --git a/source/app/app.service.spec.ts b/source/app/app.service.spec.ts deleted file mode 100644 index 0531c4ae..00000000 --- a/source/app/app.service.spec.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { AppModule } from './app.module'; -import { AppService } from './app.service'; - -describe('AppService', () => { - let appService: AppService; - - beforeAll(async () => { - const app = await AppModule.compile({ disableAll: true }); - appService = app.get(AppService); - }); - - describe('getAppStatus', () => { - it('should read application cpu, memory and network', () => { - const appStatus = appService.getStatus(); - expect(appStatus.system.uptime).toBeGreaterThan(0); - expect(appStatus.memory.total).toBeGreaterThan(0); - expect(appStatus.cpus.length).toBeGreaterThan(0); - }); - }); -}); - diff --git a/source/app/app.service.ts b/source/app/app.service.ts index fff17b6f..58162184 100644 --- a/source/app/app.service.ts +++ b/source/app/app.service.ts @@ -1,12 +1,10 @@ import { HttpStatus, Injectable } from '@nestjs/common'; import { SpanStatusCode } from '@opentelemetry/api'; import { SemanticAttributes } from '@opentelemetry/semantic-conventions'; -import os from 'os'; import { ContextService } from '../context/context.service'; import { HttpMethod } from '../http/http.enum'; import { MetricService } from '../metric/metric.service'; -import { AppStatusDto } from './app.dto.out'; import { AppTraffic } from './app.enum'; @Injectable() @@ -17,30 +15,6 @@ export class AppService { private readonly metricService: MetricService, ) { } - /** - * Reads data regarding current runtime and network. - */ - public getStatus(): AppStatusDto { - return { - system: { - version: os.version(), - type: os.type(), - release: os.release(), - architecture: os.arch(), - endianness: os.endianness(), - uptime: os.uptime(), - }, - memory: { - total: os.totalmem(), - free: os.freemem(), - }, - cpus: os.cpus(), - network: { - interfaces: os.networkInterfaces(), - }, - }; - } - /** * Register logs, metrics and tracing of inbound request. * diff --git a/source/trace/trace.service.ts b/source/trace/trace.service.ts index 4e9856a7..cf7c768a 100644 --- a/source/trace/trace.service.ts +++ b/source/trace/trace.service.ts @@ -45,7 +45,7 @@ export class TraceService { const traceUrl = this.buildTraceUrl(); if (!this.appConfig.APP_OPTIONS.disableTraces && !traceUrl) { - this.logService.warning('Trace disable due to missing URL'); + this.logService.warning('Trace disabled due to missing URL'); this.appConfig.APP_OPTIONS.disableTraces = true; }