clear metrics
This commit is contained in:
parent
070c5634cd
commit
e31451bae5
@ -1,5 +1,5 @@
|
|||||||
import { ServerlessCallback, ServerlessFunctionSignature } from "@twilio-labs/serverless-runtime-types/types";
|
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 { DoormanLambdaContext } from "./DoormanHandlerContext";
|
||||||
import { shouldBlockRequest } from "../utils/blockUserAgent";
|
import { shouldBlockRequest } from "../utils/blockUserAgent";
|
||||||
import { RequestOptions } from "https";
|
import { RequestOptions } from "https";
|
||||||
@ -33,6 +33,9 @@ export function withMetrics<T extends DoormanLambdaContext, U extends BaseEvent>
|
|||||||
handler: DoormanLambda<T, U>
|
handler: DoormanLambda<T, U>
|
||||||
): ServerlessFunctionSignature<T, U> {
|
): ServerlessFunctionSignature<T, U> {
|
||||||
return async (context, event, callback) => {
|
return async (context, event, callback) => {
|
||||||
|
console.log("[CommonHandler] clearing old metrics");
|
||||||
|
register.clear();
|
||||||
|
|
||||||
console.log("[CommonHandler] creating metrics registry");
|
console.log("[CommonHandler] creating metrics registry");
|
||||||
const metricsRegistry = new Registry();
|
const metricsRegistry = new Registry();
|
||||||
const requestOptions: RequestOptions = {
|
const requestOptions: RequestOptions = {
|
||||||
@ -126,6 +129,8 @@ export function withMetrics<T extends DoormanLambdaContext, U extends BaseEvent>
|
|||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error("[CommonHandler] failed to push metrics, quietly discarding them", e);
|
console.error("[CommonHandler] failed to push metrics, quietly discarding them", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
clearTimeout(metricsTimeout);
|
clearTimeout(metricsTimeout);
|
||||||
callback(...result);
|
callback(...result);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user