add basic auth for metrics
This commit is contained in:
parent
c3c12e1591
commit
070c5634cd
@ -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: {
|
||||
|
||||
@ -7,5 +7,7 @@ export enum Stage {
|
||||
|
||||
export interface DoormanLambdaContext extends EnvironmentVariables {
|
||||
PUSHGATEWAY_URL: string;
|
||||
PUSHGATEWAY_USER: string;
|
||||
PUSHGATEWAY_PW: string;
|
||||
STAGE: string;
|
||||
};
|
||||
|
||||
@ -7,3 +7,5 @@ AUTH_TOKEN=
|
||||
# metrics
|
||||
PUSHGATEWAY_URL=https://metrics.chromart.cc
|
||||
STAGE=prod
|
||||
PUSHGATEWAY_USER=doorman
|
||||
PUSHGATEWAY_PW=doormanmetrics
|
||||
Loading…
x
Reference in New Issue
Block a user