Skip to content

Commit

Permalink
chore: add request size metric
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayachand committed Mar 15, 2024
1 parent 21c8b48 commit 8bb568d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/controllers/userTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Check warning on line 18 in src/controllers/userTransform.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/userTransform.ts#L18

Added line #L18 was not covered by tests
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);

Check warning on line 21 in src/controllers/userTransform.ts

View check run for this annotation

Codecov / codecov/patch

src/controllers/userTransform.ts#L21

Added line #L21 was not covered by tests
ctx.body = processedRespone.transformedEvents;
ControllerUtility.postProcess(ctx, processedRespone.retryStatus);
logger.debug(
Expand Down
17 changes: 7 additions & 10 deletions src/services/userTransform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class UserTransformService {
public static async transformRoutine(
events: ProcessorTransformationRequest[],
features: FeatureFlags = {},
requestSize = 0,
): Promise<UserTransformationServiceResponse> {
let retryStatus = 200;
const groupedEvents: NonNullable<unknown> = groupBy(
Expand Down Expand Up @@ -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, {});
Expand Down
4 changes: 2 additions & 2 deletions src/util/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 8bb568d

Please sign in to comment.