From e15707b5e91c329a614c2480e3605de71a3dd120 Mon Sep 17 00:00:00 2001 From: Igor Savin Date: Wed, 6 Sep 2023 20:25:19 +0300 Subject: [PATCH] Fix prom healthcheck return type --- lib/plugins/healthcheckMetricsPlugin.spec.ts | 30 +++++++------------- lib/plugins/healthcheckMetricsPlugin.ts | 11 ++++--- 2 files changed, 15 insertions(+), 26 deletions(-) diff --git a/lib/plugins/healthcheckMetricsPlugin.spec.ts b/lib/plugins/healthcheckMetricsPlugin.spec.ts index 71f55d9..f6cd5b6 100644 --- a/lib/plugins/healthcheckMetricsPlugin.spec.ts +++ b/lib/plugins/healthcheckMetricsPlugin.spec.ts @@ -36,10 +36,8 @@ describe('healthcheckMetricsPlugin', () => { // eslint-disable-next-line @typescript-eslint/require-await checker: async () => { return { - result: { - checkPassed: true, - checkTimeInMsecs: 345, - }, + checkPassed: true, + checkTimeInMsecs: 345, } }, }, @@ -60,10 +58,8 @@ describe('healthcheckMetricsPlugin', () => { // eslint-disable-next-line @typescript-eslint/require-await checker: async () => { return { - result: { - checkPassed: false, - checkTimeInMsecs: 1450, - }, + checkPassed: false, + checkTimeInMsecs: 1450, } }, }, @@ -84,10 +80,8 @@ describe('healthcheckMetricsPlugin', () => { // eslint-disable-next-line @typescript-eslint/require-await checker: async () => { return { - result: { - checkPassed: true, - checkTimeInMsecs: 345, - }, + checkPassed: true, + checkTimeInMsecs: 345, } }, }, @@ -96,10 +90,8 @@ describe('healthcheckMetricsPlugin', () => { // eslint-disable-next-line @typescript-eslint/require-await checker: async () => { return { - result: { - checkPassed: false, - checkTimeInMsecs: 1450, - }, + checkPassed: false, + checkTimeInMsecs: 1450, } }, }, @@ -124,10 +116,8 @@ describe('healthcheckMetricsPlugin', () => { // eslint-disable-next-line @typescript-eslint/require-await checker: async () => { return { - result: { - checkPassed: false, - checkTimeInMsecs: 1450, - }, + checkPassed: false, + checkTimeInMsecs: 1450, } }, }, diff --git a/lib/plugins/healthcheckMetricsPlugin.ts b/lib/plugins/healthcheckMetricsPlugin.ts index 0888423..77b9562 100644 --- a/lib/plugins/healthcheckMetricsPlugin.ts +++ b/lib/plugins/healthcheckMetricsPlugin.ts @@ -1,4 +1,3 @@ -import type { Either } from '@lokalise/node-core' import type { FastifyInstance } from 'fastify' import fp from 'fastify-plugin' @@ -15,7 +14,7 @@ export type HealthcheckResult = { export type PrometheusHealthCheck = { name: string - checker: (app: FastifyInstance) => Promise> + checker: (app: FastifyInstance) => Promise } function plugin( @@ -48,7 +47,7 @@ function plugin( async collect() { const checkResult = await check.checker(app) - if (checkResult.result?.checkPassed) { + if (checkResult.checkPassed) { this.set(1) } else { this.set(0) @@ -62,10 +61,10 @@ function plugin( async collect() { const checkResult = await check.checker(app) - if (checkResult.result?.checkPassed) { - this.set(checkResult.result.checkTimeInMsecs) + if (checkResult.checkPassed) { + this.set(checkResult.checkTimeInMsecs) } else { - this.set(checkResult.result?.checkTimeInMsecs ?? 0) + this.set(checkResult.checkTimeInMsecs ?? 0) } }, })