From ae48d7a2dbec6f6b9a43b14b0fdcbd510610f1e0 Mon Sep 17 00:00:00 2001 From: Jayc Date: Thu, 8 Feb 2024 14:34:39 +0530 Subject: [PATCH 1/5] chore: adding a metric to capture event batch size --- src/services/userTransform.ts | 13 ++++++++----- src/util/prometheus.js | 12 ++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/services/userTransform.ts b/src/services/userTransform.ts index bf34e3d82a..91c110ecef 100644 --- a/src/services/userTransform.ts +++ b/src/services/userTransform.ts @@ -14,7 +14,7 @@ import { RetryRequestError, extractStackTraceUptoLastSubstringMatch, } from '../util/utils'; -import { getMetadata, isNonFuncObject } from '../v0/util'; +import { getMetadata, getTransformationMetadata, isNonFuncObject } from '../v0/util'; import { SUPPORTED_FUNC_NAMES } from '../util/ivmFactory'; import logger from '../logger'; import stats from '../util/stats'; @@ -162,15 +162,18 @@ export class UserTransformService { ), ); stats.counter('user_transform_errors', eventsToProcess.length, { - transformationId: eventsToProcess[0]?.metadata?.transformationId, - workspaceId: eventsToProcess[0]?.metadata?.workspaceId, + ...getTransformationMetadata(eventsToProcess[0]?.metadata), status, ...metaTags, }); } finally { stats.timing('user_transform_request_latency', userFuncStartTime, { - workspaceId: eventsToProcess[0]?.metadata?.workspaceId, - transformationId: eventsToProcess[0]?.metadata?.transformationId, + ...getTransformationMetadata(eventsToProcess[0]?.metadata), + ...metaTags, + }); + + stats.histogram('user_transform_request_size', JSON.stringify(eventsToProcess).length, { + ...getTransformationMetadata(eventsToProcess[0]?.metadata), ...metaTags, }); } diff --git a/src/util/prometheus.js b/src/util/prometheus.js index d7ba3b7c61..07399cccaf 100644 --- a/src/util/prometheus.js +++ b/src/util/prometheus.js @@ -642,6 +642,18 @@ class Prometheus { 'k8_namespace', ], }, + { + name: 'user_transform_request_size', + help: 'user_transform_request_size', + type: 'histogram', + labelNames: [ + 'workspaceId', + 'transformationId', + 'sourceType', + 'destinationType', + 'k8_namespace', + ], + }, { name: 'source_transform_request_latency', help: 'source_transform_request_latency', From b17efa3d9883eefc86397341528bf1bdd20201c4 Mon Sep 17 00:00:00 2001 From: Abhimanyu Babbar Date: Wed, 14 Feb 2024 23:47:32 +0530 Subject: [PATCH 2/5] Using buffer bytesLength to account for utf-8 characters having variable size --- src/services/userTransform.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/services/userTransform.ts b/src/services/userTransform.ts index 91c110ecef..ddc2c1e9c5 100644 --- a/src/services/userTransform.ts +++ b/src/services/userTransform.ts @@ -172,10 +172,14 @@ export class UserTransformService { ...metaTags, }); - stats.histogram('user_transform_request_size', JSON.stringify(eventsToProcess).length, { - ...getTransformationMetadata(eventsToProcess[0]?.metadata), - ...metaTags, - }); + stats.histogram( + 'user_transform_request_size', + Buffer.byteLength(JSON.stringify(eventsToProcess)), + { + ...getTransformationMetadata(eventsToProcess[0]?.metadata), + ...metaTags, + }, + ); } stats.counter('user_transform_requests', 1, {}); From 2d0824e7aaaa655a1f7c04175a48975bb79f918d Mon Sep 17 00:00:00 2001 From: Jayc Date: Thu, 7 Mar 2024 23:28:28 +0530 Subject: [PATCH 3/5] add buckets to payload size --- src/util/prometheus.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/prometheus.js b/src/util/prometheus.js index dff024637d..2d181658dd 100644 --- a/src/util/prometheus.js +++ b/src/util/prometheus.js @@ -594,6 +594,7 @@ class Prometheus { help: 'tp_request_size', type: 'histogram', labelNames: ['sourceType', 'destinationType', 'k8_namespace'], + buckets: [1024, 102400, 524288, 1048576, 10485760, 20971520, 52428800, 104857600, 209715200, 524288000], }, { name: 'tp_request_latency', @@ -661,6 +662,7 @@ class Prometheus { 'destinationType', 'k8_namespace', ], + buckets: [1024, 102400, 524288, 1048576, 10485760, 20971520, 52428800, 104857600, 209715200, 524288000], // 1KB, 100KB, 0.5MB, 1MB, 10MB, 20MB, 50MB, 100MB, 200MB, 500MB }, { name: 'source_transform_request_latency', From 12d9bf160be400877a61632d3a0f72262ea5390f Mon Sep 17 00:00:00 2001 From: Jayc Date: Thu, 7 Mar 2024 23:35:02 +0530 Subject: [PATCH 4/5] chore: fixing lint --- src/util/prometheus.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/util/prometheus.js b/src/util/prometheus.js index 2d181658dd..9a9ca9cfb6 100644 --- a/src/util/prometheus.js +++ b/src/util/prometheus.js @@ -594,7 +594,10 @@ class Prometheus { help: 'tp_request_size', type: 'histogram', labelNames: ['sourceType', 'destinationType', 'k8_namespace'], - buckets: [1024, 102400, 524288, 1048576, 10485760, 20971520, 52428800, 104857600, 209715200, 524288000], + buckets: [ + 1024, 102400, 524288, 1048576, 10485760, 20971520, 52428800, 104857600, 209715200, + 524288000, + ], }, { name: 'tp_request_latency', @@ -662,7 +665,10 @@ class Prometheus { 'destinationType', 'k8_namespace', ], - buckets: [1024, 102400, 524288, 1048576, 10485760, 20971520, 52428800, 104857600, 209715200, 524288000], // 1KB, 100KB, 0.5MB, 1MB, 10MB, 20MB, 50MB, 100MB, 200MB, 500MB + buckets: [ + 1024, 102400, 524288, 1048576, 10485760, 20971520, 52428800, 104857600, 209715200, + 524288000, + ], // 1KB, 100KB, 0.5MB, 1MB, 10MB, 20MB, 50MB, 100MB, 200MB, 500MB }, { name: 'source_transform_request_latency', From 8bb568da2ac25d59d4878d86ea72a69057ed6c47 Mon Sep 17 00:00:00 2001 From: Jayc Date: Fri, 15 Mar 2024 15:16:19 +0530 Subject: [PATCH 5/5] 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',