diff --git a/packages/doorman-api/src/common/DoormanHandler.ts b/packages/doorman-api/src/common/DoormanHandler.ts index 805c126..cf656cb 100644 --- a/packages/doorman-api/src/common/DoormanHandler.ts +++ b/packages/doorman-api/src/common/DoormanHandler.ts @@ -1,5 +1,5 @@ import { ServerlessCallback, ServerlessFunctionSignature } from "@twilio-labs/serverless-runtime-types/types"; -import { PrometheusContentType, Registry, Pushgateway, Summary, Counter } from "prom-client"; +import { PrometheusContentType, Registry, Pushgateway, Summary, Counter, register } from "prom-client"; import { DoormanLambdaContext } from "./DoormanHandlerContext"; import { shouldBlockRequest } from "../utils/blockUserAgent"; import { RequestOptions } from "https"; @@ -33,6 +33,9 @@ export function withMetrics handler: DoormanLambda ): ServerlessFunctionSignature { return async (context, event, callback) => { + console.log("[CommonHandler] clearing old metrics"); + register.clear(); + console.log("[CommonHandler] creating metrics registry"); const metricsRegistry = new Registry(); const requestOptions: RequestOptions = { @@ -126,6 +129,8 @@ export function withMetrics } catch (e: any) { console.error("[CommonHandler] failed to push metrics, quietly discarding them", e); } + + clearTimeout(metricsTimeout); callback(...result);