From 711fd0100ebd0edd7f54f251e0eb640cc8200e91 Mon Sep 17 00:00:00 2001 From: Kathleen Koh Date: Wed, 13 Mar 2024 15:47:25 +0800 Subject: [PATCH] chore: adding duration logs for virus scan file download --- src/app/modules/submission/submission.service.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/app/modules/submission/submission.service.ts b/src/app/modules/submission/submission.service.ts index 3ee78d48f5..9fda84768f 100644 --- a/src/app/modules/submission/submission.service.ts +++ b/src/app/modules/submission/submission.service.ts @@ -33,6 +33,7 @@ import { ParsedClearFormFieldResponse, } from '../../../types/api' import { aws as AwsConfig } from '../../config/config' +// import { statsdClient } from '../../config/datadog-statsd-client' import { createLoggerWithLabel } from '../../config/logger' import getPendingSubmissionModel from '../../models/pending_submission.server.model' import getSubmissionModel, { @@ -385,6 +386,7 @@ export const downloadCleanFile = (cleanFileKey: string, versionId: string) => { }) .createReadStream() + const timeDownloadStart = Date.now() logger.info({ message: 'File download from S3 has started', meta: logMeta, @@ -401,6 +403,12 @@ export const downloadCleanFile = (cleanFileKey: string, versionId: string) => { }) resolve(buffer) }) + const timeDownloadEnd = Date.now() + + logger.info({ + message: 'Duration of file download from S3', + meta: { ...logMeta, time: timeDownloadEnd - timeDownloadStart }, + }) readStream.on('error', (error) => { reject(error) @@ -418,6 +426,14 @@ export const downloadCleanFile = (cleanFileKey: string, versionId: string) => { ) } +// statsdClient.distribution( +// 'formsg.submissions.virusScanFile.duration', +// duration, +// { +// rating: `${rating}`, +// }, +// ) + /** * Helper function to trigger virus scanning and download clean file. * @param response quarantined attachment response from storage submissions v2.1+.