Skip to content

Commit ea3e294

Browse files
committed
invoke the metric scope
1 parent d489e65 commit ea3e294

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

lambdas/authorizer/src/__tests__/index.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ jest.mock("aws-embedded-metrics", () => {
1818

1919
return {
2020
metricScope: jest.fn(
21-
(handler: (metrics: typeof metricsMock) => unknown): void => {
22-
const wrapped = handler(metricsMock);
23-
if (typeof wrapped === "function") {
24-
wrapped();
25-
}
26-
},
21+
(handler) =>
22+
async () => {
23+
const wrapped = handler(metricsMock);
24+
if (typeof wrapped === "function") {
25+
await wrapped();
26+
}
27+
},
2728
),
2829
__metricsMock: metricsMock,
2930
};

lambdas/authorizer/src/authorizer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@ async function checkCertificateExpiry(
120120
const expiry = getCertificateExpiryInDays(certificate);
121121

122122
if (expiry <= deps.env.CLIENT_CERTIFICATE_EXPIRATION_ALERT_DAYS) {
123-
metricScope((metrics: MetricsLogger) => async () => {
123+
await metricScope((metrics: MetricsLogger) => async () => {
124124
deps.logger.warn(`APIM Certificated expiry in ${expiry} days`);
125125
metrics.setNamespace(
126-
process.env.AWS_LAMBDA_FUNCTION_NAME || "authorizer",
126+
process.env.AWS_LAMBDA_FUNCTION_NAME || "authorizer",
127127
);
128128
metrics.putMetric("apim-client-certificate-near-expiry", expiry, "Count");
129-
});
129+
})();
130130
}
131131
}

0 commit comments

Comments
 (0)