From 8bb568da2ac25d59d4878d86ea72a69057ed6c47 Mon Sep 17 00:00:00 2001 From: Jayc Date: Fri, 15 Mar 2024 15:16:19 +0530 Subject: [PATCH] chore: add request size metric --- src/controllers/userTransform.ts | 3 ++- src/services/userTransform.ts | 17 +++++++---------- src/util/prometheus.js | 4 ++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/controllers/userTransform.ts b/src/controllers/userTransform.ts index c344bd072a..3e01686a52 100644 --- a/src/controllers/userTransform.ts +++ b/src/controllers/userTransform.ts @@ -15,9 +15,10 @@ export class UserTransformController { '(User transform - router:/customTransform ):: Request to transformer', JSON.stringify(ctx.request.body), ); + const requestSize = Number(ctx.request.get('content-length')); const events = ctx.request.body as ProcessorTransformationRequest[]; const processedRespone: UserTransformationServiceResponse = - await UserTransformService.transformRoutine(events, ctx.state.features); + await UserTransformService.transformRoutine(events, ctx.state.features, requestSize); ctx.body = processedRespone.transformedEvents; ControllerUtility.postProcess(ctx, processedRespone.retryStatus); logger.debug( diff --git a/src/services/userTransform.ts b/src/services/userTransform.ts index 71a0c63e97..18c47ddc83 100644 --- a/src/services/userTransform.ts +++ b/src/services/userTransform.ts @@ -28,6 +28,7 @@ export class UserTransformService { public static async transformRoutine( events: ProcessorTransformationRequest[], features: FeatureFlags = {}, + requestSize = 0, ): Promise { let retryStatus = 200; const groupedEvents: NonNullable = groupBy( @@ -162,24 +163,20 @@ export class UserTransformService { ), ); stats.counter('user_transform_errors', eventsToProcess.length, { - ...getTransformationMetadata(eventsToProcess[0]?.metadata), status, ...metaTags, + ...getTransformationMetadata(eventsToProcess[0]?.metadata), }); } finally { stats.timing('user_transform_request_latency', userFuncStartTime, { - ...getTransformationMetadata(eventsToProcess[0]?.metadata), ...metaTags, + ...getTransformationMetadata(eventsToProcess[0]?.metadata), }); - stats.histogram( - 'user_transform_request_size', - Buffer.byteLength(JSON.stringify(eventsToProcess)), - { - ...getTransformationMetadata(eventsToProcess[0]?.metadata), - ...metaTags, - }, - ); + stats.histogram('user_transform_batch_size', requestSize, { + ...metaTags, + ...getTransformationMetadata(eventsToProcess[0]?.metadata), + }); } stats.counter('user_transform_requests', 1, {}); diff --git a/src/util/prometheus.js b/src/util/prometheus.js index 9c26347208..5de7ac899d 100644 --- a/src/util/prometheus.js +++ b/src/util/prometheus.js @@ -675,8 +675,8 @@ class Prometheus { ], }, { - name: 'user_transform_request_size', - help: 'user_transform_request_size', + name: 'user_transform_batch_size', + help: 'user_transform_batch_size', type: 'histogram', labelNames: [ 'workspaceId',