From 0494e45ce10b67ccfe676a156bc3e36d50f3b711 Mon Sep 17 00:00:00 2001 From: zi-yang-uni Date: Thu, 5 Sep 2024 13:42:35 -0700 Subject: [PATCH] create new metric handler duration --- lib/entities/aws-metrics-logger.ts | 1 + lib/handlers/base/api-handler.ts | 5 +++-- lib/handlers/hard-quote/handler.ts | 1 + lib/handlers/quote/handler.ts | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/entities/aws-metrics-logger.ts b/lib/entities/aws-metrics-logger.ts index 7f40caa..a99e239 100644 --- a/lib/entities/aws-metrics-logger.ts +++ b/lib/entities/aws-metrics-logger.ts @@ -46,6 +46,7 @@ export enum Metric { QUOTE_REQUESTED = 'QUOTE_REQUESTED', QUOTE_LATENCY = 'QUOTE_LATENCY', QUOTE_RESPONSE_COUNT = 'QUOTE_RESPONSE_COUNT', + HANDLER_DURATION = 'HANDLER_DURATION', QUOTE_POST_ERROR = 'QUOTE_POST_ERROR', QUOTE_POST_ATTEMPT = 'QUOTE_POST_ATTEMPT', diff --git a/lib/handlers/base/api-handler.ts b/lib/handlers/base/api-handler.ts index 81752c9..e79ebf5 100644 --- a/lib/handlers/base/api-handler.ts +++ b/lib/handlers/base/api-handler.ts @@ -96,8 +96,9 @@ export abstract class APIGLambdaHandler< const response = await handler(event, context); const requestEnd = new Date().getTime(); - // Track latency - metric.putMetric(Metric.QUOTE_LATENCY, requestEnd - requestStart, MetricLoggerUnit.Milliseconds); + // Track handler duration + metric.putDimensions({ HandlerName: this.handlerName }); + metric.putMetric(Metric.HANDLER_DURATION, requestEnd - requestStart, MetricLoggerUnit.Milliseconds); return { ...response, diff --git a/lib/handlers/hard-quote/handler.ts b/lib/handlers/hard-quote/handler.ts index 0174bdd..2ca9fbe 100644 --- a/lib/handlers/hard-quote/handler.ts +++ b/lib/handlers/hard-quote/handler.ts @@ -110,6 +110,7 @@ export class QuoteHandler extends APIGLambdaHandler< }); if (response.statusCode == 200 || response.statusCode == 201) { metric.putMetric(Metric.QUOTE_200, 1, MetricLoggerUnit.Count); + metric.putMetric(Metric.QUOTE_LATENCY, Date.now() - start, MetricLoggerUnit.Milliseconds); const hardResponse = new HardQuoteResponse(request, cosignedOrder); if (!bestQuote) { // The RFQ responses are logged in getBestQuote() diff --git a/lib/handlers/quote/handler.ts b/lib/handlers/quote/handler.ts index 6d62212..0d14b34 100644 --- a/lib/handlers/quote/handler.ts +++ b/lib/handlers/quote/handler.ts @@ -61,6 +61,7 @@ export class QuoteHandler extends APIGLambdaHandler< log.info({ bestQuote: bestQuote }, 'bestQuote'); metric.putMetric(Metric.QUOTE_200, 1, MetricLoggerUnit.Count); + metric.putMetric(Metric.QUOTE_LATENCY, Date.now() - start, MetricLoggerUnit.Milliseconds); return { statusCode: 200, body: bestQuote.toResponseJSON(),