Compare commits
8 Commits
5260b8a9c5
...
docker-imp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5e98348cac | ||
|
|
3bf4cebbe6 | ||
|
|
907c24c45b | ||
|
|
b057ea154a | ||
|
|
0e2a7eeeec | ||
|
|
c702946393 | ||
| 32ea0d7c4d | |||
| 15fe566d53 |
@@ -1,5 +1,4 @@
|
|||||||
PORT=3101
|
PORT=3101
|
||||||
branch=
|
|
||||||
DATABASE_URL=postgres://greact:pG3526l4@194.36.208.86:5433/cloud
|
DATABASE_URL=postgres://greact:pG3526l4@194.36.208.86:5433/cloud
|
||||||
|
|
||||||
# Optional. When set, POST /api/ingest requires x-api-key: <value>.
|
# Optional. When set, POST /api/ingest requires x-api-key: <value>.
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
services:
|
services:
|
||||||
drill-cloud-v3:
|
drill-cloud-v3:
|
||||||
container_name: drill-cloud-v3${branch:+-${branch}}
|
|
||||||
build: .
|
build: .
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
@@ -8,7 +7,6 @@ services:
|
|||||||
PORT: ${PORT}
|
PORT: ${PORT}
|
||||||
DATABASE_URL: ${DATABASE_URL}
|
DATABASE_URL: ${DATABASE_URL}
|
||||||
INGEST_API_KEY: ${INGEST_API_KEY}
|
INGEST_API_KEY: ${INGEST_API_KEY}
|
||||||
INGEST_DEBUG_LOG: ${INGEST_DEBUG_LOG:-}
|
|
||||||
CURRENT_EVENTS_POLL_MS: ${CURRENT_EVENTS_POLL_MS}
|
CURRENT_EVENTS_POLL_MS: ${CURRENT_EVENTS_POLL_MS}
|
||||||
expose:
|
expose:
|
||||||
- "3101"
|
- "3101"
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import { Body, Controller, Logger, Param, Post, Req, UseGuards } from '@nestjs/common';
|
import { Body, Controller, Param, Post, UseGuards } from '@nestjs/common';
|
||||||
import type { Request } from 'express';
|
|
||||||
import { IngestApiKeyGuard } from '../common/ingest-api-key.guard';
|
import { IngestApiKeyGuard } from '../common/ingest-api-key.guard';
|
||||||
import { IngestEdgeValuesDto } from './dto/ingest-edge-values.dto';
|
import { IngestEdgeValuesDto } from './dto/ingest-edge-values.dto';
|
||||||
import { IngestPointDto } from './dto/ingest-point.dto';
|
import { IngestPointDto } from './dto/ingest-point.dto';
|
||||||
@@ -8,19 +7,10 @@ import { IngestService } from './ingest.service';
|
|||||||
@Controller('ingest')
|
@Controller('ingest')
|
||||||
@UseGuards(IngestApiKeyGuard)
|
@UseGuards(IngestApiKeyGuard)
|
||||||
export class IngestController {
|
export class IngestController {
|
||||||
private readonly logger = new Logger(IngestController.name);
|
|
||||||
|
|
||||||
constructor(private readonly ingest: IngestService) {}
|
constructor(private readonly ingest: IngestService) {}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
ingestPoint(@Body() point: IngestPointDto, @Req() request: Request) {
|
ingestPoint(@Body() point: IngestPointDto) {
|
||||||
this.logIngestRequest(request, {
|
|
||||||
kind: 'point',
|
|
||||||
edge: point.edge,
|
|
||||||
tag: point.tag,
|
|
||||||
timestamp: point.timestamp,
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.ingest.ingestPoint(point);
|
return this.ingest.ingestPoint(point);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,17 +18,7 @@ export class IngestController {
|
|||||||
ingestEdgeValues(
|
ingestEdgeValues(
|
||||||
@Param('edge') edge: string,
|
@Param('edge') edge: string,
|
||||||
@Body() body: IngestEdgeValuesDto,
|
@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]) => ({
|
const points = Object.entries(body.values).map(([tag, value]) => ({
|
||||||
edge,
|
edge,
|
||||||
tag,
|
tag,
|
||||||
@@ -48,33 +28,4 @@ export class IngestController {
|
|||||||
|
|
||||||
return this.ingest.ingestPoints(points);
|
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(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import { NestFactory } from '@nestjs/core';
|
|||||||
import compression from 'compression';
|
import compression from 'compression';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
|
||||||
/** Запускает HTTP API со сжатием и глобальной валидацией DTO. */
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
|
|||||||
Reference in New Issue
Block a user