add basic auth for metrics
All checks were successful
Build and push image for doorman-homeassistant / docker (push) Successful in 28s
Build and push Doorman UI / API / docker (push) Successful in 1m32s
Build and push image for doorman-homeassistant / deploy-gitainer (push) Successful in 4s

This commit is contained in:
Martin Dimitrov 2024-12-22 14:38:26 -08:00
parent c3c12e1591
commit 070c5634cd
3 changed files with 13 additions and 3 deletions

View File

@ -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<T extends DoormanLambdaContext, U extends BaseEvent>
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<T extends DoormanLambdaContext, U extends BaseEvent>
console.log("[CommonHandler] attempting to push metrics...");
try {
console.log(await getMetricFromRegistry<Summary>(metricsRegistry, CommonMetrics.RUNTIME).get());
await pushGateway.push({
jobName: functionName,
groupings: {

View File

@ -7,5 +7,7 @@ export enum Stage {
export interface DoormanLambdaContext extends EnvironmentVariables {
PUSHGATEWAY_URL: string;
PUSHGATEWAY_USER: string;
PUSHGATEWAY_PW: string;
STAGE: string;
};

View File

@ -7,3 +7,5 @@ AUTH_TOKEN=
# metrics
PUSHGATEWAY_URL=https://metrics.chromart.cc
STAGE=prod
PUSHGATEWAY_USER=doorman
PUSHGATEWAY_PW=doormanmetrics