diff --git a/packages/doorman-api/src/common/DoormanHandler.ts b/packages/doorman-api/src/common/DoormanHandler.ts index d7f4d48..805c126 100644 --- a/packages/doorman-api/src/common/DoormanHandler.ts +++ b/packages/doorman-api/src/common/DoormanHandler.ts @@ -2,6 +2,7 @@ import { ServerlessCallback, ServerlessFunctionSignature } from "@twilio-labs/se import { PrometheusContentType, Registry, Pushgateway, Summary, Counter } from "prom-client"; import { DoormanLambdaContext } from "./DoormanHandlerContext"; import { shouldBlockRequest } from "../utils/blockUserAgent"; +import { RequestOptions } from "https"; export type BaseEvent = { request: { cookies: {}; headers: {}; }; } @@ -34,7 +35,13 @@ export function withMetrics return async (context, event, callback) => { console.log("[CommonHandler] creating metrics registry"); const metricsRegistry = new Registry(); - const pushGateway = new Pushgateway(context.PUSHGATEWAY_URL, {}, metricsRegistry); + const requestOptions: RequestOptions = { + headers: { + 'Authorization': 'Basic ' + Buffer.from(context.PUSHGATEWAY_USER + ':' + context.PUSHGATEWAY_PW).toString('base64'), + }, + }; + + const pushGateway = new Pushgateway(context.PUSHGATEWAY_URL, requestOptions, metricsRegistry); metricsRegistry.registerMetric(new Summary({ name: CommonMetrics.RUNTIME, @@ -109,7 +116,6 @@ export function withMetrics console.log("[CommonHandler] attempting to push metrics..."); try { - console.log(await getMetricFromRegistry(metricsRegistry, CommonMetrics.RUNTIME).get()); await pushGateway.push({ jobName: functionName, groupings: { diff --git a/packages/doorman-api/src/common/DoormanHandlerContext.ts b/packages/doorman-api/src/common/DoormanHandlerContext.ts index ba9c64e..259bfdb 100644 --- a/packages/doorman-api/src/common/DoormanHandlerContext.ts +++ b/packages/doorman-api/src/common/DoormanHandlerContext.ts @@ -7,5 +7,7 @@ export enum Stage { export interface DoormanLambdaContext extends EnvironmentVariables { PUSHGATEWAY_URL: string; + PUSHGATEWAY_USER: string; + PUSHGATEWAY_PW: string; STAGE: string; }; diff --git a/packages/doorman-client/.env.example b/packages/doorman-client/.env.example index fd99292..3d98815 100644 --- a/packages/doorman-client/.env.example +++ b/packages/doorman-client/.env.example @@ -6,4 +6,6 @@ AUTH_TOKEN= # metrics PUSHGATEWAY_URL=https://metrics.chromart.cc -STAGE=prod \ No newline at end of file +STAGE=prod +PUSHGATEWAY_USER=doorman +PUSHGATEWAY_PW=doormanmetrics \ No newline at end of file