perf(cmpp): instrument inbound flow and unbatch submit worker
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BadRequestException, Body, Controller, Post } from '@nestjs/common';
|
||||
import { BadRequestException, Body, Controller, Optional, Post } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
GatewayInboundAuthDto,
|
||||
@@ -19,6 +19,7 @@ import { GatewayDownstreamConnectionEventDto } from '../sms-config/sms-config.co
|
||||
import { SmsConfigService } from '../sms-config/sms-config.service';
|
||||
import { ProtocolLogsService, type ProtocolLogInput } from '../protocol-logs/protocol-logs.service';
|
||||
import { SecurityDetectionService } from '../security-detection/security-detection.service';
|
||||
import { MetricsService } from '../metrics/metrics.service';
|
||||
|
||||
@ApiTags('gateway-events')
|
||||
@Controller('gateway/events')
|
||||
@@ -28,6 +29,7 @@ export class GatewayEventsController {
|
||||
private readonly smsConfig: SmsConfigService,
|
||||
private readonly protocolLogs: ProtocolLogsService,
|
||||
private readonly security: SecurityDetectionService,
|
||||
@Optional() private readonly metrics?: MetricsService,
|
||||
) {}
|
||||
|
||||
@Post('submit-result')
|
||||
@@ -139,6 +141,9 @@ export class GatewayEventsController {
|
||||
direction: ProtocolLogInput['direction'] = 'channel_to_platform',
|
||||
) {
|
||||
const startedAt = Date.now();
|
||||
const inboundMetricStartedAt = eventType === 'submit' && direction === 'client_to_platform'
|
||||
? this.metrics?.beginCmppInboundStage()
|
||||
: undefined;
|
||||
const value = body as Record<string, unknown>;
|
||||
const common: Omit<ProtocolLogInput, 'status'> = {
|
||||
protocol: 'cmpp',
|
||||
@@ -173,6 +178,9 @@ export class GatewayEventsController {
|
||||
status: 'success',
|
||||
durationMs: Date.now() - startedAt,
|
||||
});
|
||||
if (inboundMetricStartedAt != null) {
|
||||
this.metrics?.finishCmppInboundStage(inboundMetricStartedAt, 'total', 'success');
|
||||
}
|
||||
return result;
|
||||
} catch (error) {
|
||||
this.protocolLogs.record({
|
||||
@@ -181,6 +189,9 @@ export class GatewayEventsController {
|
||||
durationMs: Date.now() - startedAt,
|
||||
detail: { error: error instanceof Error ? error.message : 'unknown error' },
|
||||
});
|
||||
if (inboundMetricStartedAt != null) {
|
||||
this.metrics?.finishCmppInboundStage(inboundMetricStartedAt, 'total', 'error');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user