Удалил docker-compose.dev.yml. поменял наименование контейнера. Убрал дебаг логи.
This commit is contained in:
@@ -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<string, unknown>,
|
||||
): 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(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
37
src/main.ts
37
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<CurrentDatabaseRow>(
|
||||
'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();
|
||||
|
||||
Reference in New Issue
Block a user