From b057ea154a390cf596c2ea6330fca9750365fb9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B2=20=D0=90=D1=80=D1=82?= =?UTF-8?q?=D0=B5=D0=BC?= Date: Sat, 4 Jul 2026 14:06:53 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20docker-c?= =?UTF-8?q?ompose.dev.yml.=20=D0=BF=D0=BE=D0=BC=D0=B5=D0=BD=D1=8F=D0=BB=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B8=D0=BC=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BE=D0=BD=D1=82=D0=B5=D0=B9=D0=BD=D0=B5?= =?UTF-8?q?=D1=80=D0=B0.=20=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B4=D0=B5?= =?UTF-8?q?=D0=B1=D0=B0=D0=B3=20=D0=BB=D0=BE=D0=B3=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 3 -- docker-compose.dev.yml | 21 ------------- docker-compose.yml | 4 +-- src/ingest/ingest.controller.ts | 53 ++------------------------------- src/main.ts | 37 +---------------------- 5 files changed, 4 insertions(+), 114 deletions(-) delete mode 100644 docker-compose.dev.yml diff --git a/.env.example b/.env.example index c9e5984..c304264 100644 --- a/.env.example +++ b/.env.example @@ -5,8 +5,5 @@ DATABASE_URL=postgres://greact:pG3526l4@194.36.208.86:5433/cloud # Optional. When set, POST /api/ingest requires x-api-key: . INGEST_API_KEY= -# Optional. Logs POST /api/ingest request metadata without x-api-key. -INGEST_DEBUG_LOG= - # Poll interval for GET /api/current/events SSE snapshots. CURRENT_EVENTS_POLL_MS=1000 diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml deleted file mode 100644 index 3691adb..0000000 --- a/docker-compose.dev.yml +++ /dev/null @@ -1,21 +0,0 @@ -services: - drill-cloud-v3-dev: - container_name: drill-cloud-v3${branch:+-${branch}} - build: . - restart: unless-stopped - environment: - NODE_ENV: production - BRANCH: ${branch:-} - PORT: ${PORT} - DATABASE_URL: ${DATABASE_URL} - INGEST_API_KEY: ${INGEST_API_KEY} - INGEST_DEBUG_LOG: ${INGEST_DEBUG_LOG:-} - CURRENT_EVENTS_POLL_MS: ${CURRENT_EVENTS_POLL_MS} - expose: - - "3101" - networks: - - proxy - -networks: - proxy: - external: true diff --git a/docker-compose.yml b/docker-compose.yml index 4fe08ad..962b693 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,15 +1,13 @@ services: drill-cloud-v3: - container_name: drill-cloud-v3${branch:+-${branch}} + container_name: container-drill-cloud-v3${branch:+-${branch}} build: . restart: unless-stopped environment: NODE_ENV: production - BRANCH: ${branch:-} PORT: ${PORT} DATABASE_URL: ${DATABASE_URL} INGEST_API_KEY: ${INGEST_API_KEY} - INGEST_DEBUG_LOG: ${INGEST_DEBUG_LOG:-} CURRENT_EVENTS_POLL_MS: ${CURRENT_EVENTS_POLL_MS} expose: - "3101" diff --git a/src/ingest/ingest.controller.ts b/src/ingest/ingest.controller.ts index 72d1a58..90a9129 100644 --- a/src/ingest/ingest.controller.ts +++ b/src/ingest/ingest.controller.ts @@ -1,5 +1,4 @@ -import { Body, Controller, Logger, Param, Post, Req, UseGuards } from '@nestjs/common'; -import type { Request } from 'express'; +import { Body, Controller, Param, Post, UseGuards } from '@nestjs/common'; import { IngestApiKeyGuard } from '../common/ingest-api-key.guard'; import { IngestEdgeValuesDto } from './dto/ingest-edge-values.dto'; import { IngestPointDto } from './dto/ingest-point.dto'; @@ -8,19 +7,10 @@ import { IngestService } from './ingest.service'; @Controller('ingest') @UseGuards(IngestApiKeyGuard) export class IngestController { - private readonly logger = new Logger(IngestController.name); - constructor(private readonly ingest: IngestService) {} @Post() - ingestPoint(@Body() point: IngestPointDto, @Req() request: Request) { - this.logIngestRequest(request, { - kind: 'point', - edge: point.edge, - tag: point.tag, - timestamp: point.timestamp, - }); - + ingestPoint(@Body() point: IngestPointDto) { return this.ingest.ingestPoint(point); } @@ -28,17 +18,7 @@ export class IngestController { ingestEdgeValues( @Param('edge') edge: string, @Body() body: IngestEdgeValuesDto, - @Req() request: Request, ) { - const tags = Object.keys(body.values); - this.logIngestRequest(request, { - kind: 'edge-values', - edge, - tagCount: tags.length, - firstTags: tags.slice(0, 5), - timestamp: body.timestamp, - }); - const points = Object.entries(body.values).map(([tag, value]) => ({ edge, tag, @@ -48,33 +28,4 @@ export class IngestController { return this.ingest.ingestPoints(points); } - - private logIngestRequest( - request: Request, - payload: Record, - ): void { - if (!this.isDebugLogEnabled()) { - return; - } - - this.logger.log({ - event: 'ingest.received', - method: request.method, - url: request.originalUrl, - host: request.get('host'), - ip: request.ip, - remoteAddress: request.socket.remoteAddress, - forwardedFor: request.get('x-forwarded-for'), - realIp: request.get('x-real-ip'), - userAgent: request.get('user-agent'), - contentLength: request.get('content-length'), - ...payload, - }); - } - - private isDebugLogEnabled(): boolean { - return ['1', 'true', 'yes', 'on'].includes( - (process.env.INGEST_DEBUG_LOG ?? '').toLowerCase(), - ); - } } diff --git a/src/main.ts b/src/main.ts index eafb9ba..6aeb819 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,30 +1,9 @@ -import { Logger, ValidationPipe } from '@nestjs/common'; +import { ValidationPipe } from '@nestjs/common'; import { NestFactory } from '@nestjs/core'; import compression from 'compression'; import { AppModule } from './app.module'; -import { DbService } from './db/db.service'; - -type CurrentDatabaseRow = { - database: string; -}; - -function getMaskedDatabaseUrl(): string | undefined { - const databaseUrl = process.env.DATABASE_URL; - if (!databaseUrl) { - return undefined; - } - - try { - const url = new URL(databaseUrl); - const username = url.username ? `${url.username}:***@` : ''; - return `${url.protocol}//${username}${url.host}${url.pathname}`; - } catch { - return databaseUrl.replace(/:\/\/([^:]+):([^@]+)@/, '://$1:***@'); - } -} async function bootstrap() { - const logger = new Logger('Bootstrap'); const app = await NestFactory.create(AppModule); app.use(compression()); app.setGlobalPrefix('api'); @@ -38,20 +17,6 @@ async function bootstrap() { ); await app.listen(process.env.PORT as string); - - const db = app.get(DbService); - const currentDatabase = await db.query( - 'SELECT current_database() AS database', - ); - - logger.log({ - event: 'cloud.started', - port: process.env.PORT, - branch: process.env.BRANCH ?? process.env.branch ?? '', - database: currentDatabase.rows[0]?.database, - databaseUrl: getMaskedDatabaseUrl(), - ingestDebugLog: process.env.INGEST_DEBUG_LOG ?? '', - }); } void bootstrap();