Skip to content

Commit

Permalink
Fix prom healthcheck return type (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad authored Sep 6, 2023
1 parent fb204e5 commit 6e42d42
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
30 changes: 10 additions & 20 deletions lib/plugins/healthcheckMetricsPlugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
},
},
Expand All @@ -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,
}
},
},
Expand All @@ -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,
}
},
},
Expand All @@ -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,
}
},
},
Expand All @@ -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,
}
},
},
Expand Down
11 changes: 5 additions & 6 deletions lib/plugins/healthcheckMetricsPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Either } from '@lokalise/node-core'
import type { FastifyInstance } from 'fastify'
import fp from 'fastify-plugin'

Expand All @@ -15,7 +14,7 @@ export type HealthcheckResult = {

export type PrometheusHealthCheck = {
name: string
checker: (app: FastifyInstance) => Promise<Either<Error, HealthcheckResult>>
checker: (app: FastifyInstance) => Promise<HealthcheckResult>
}

function plugin(
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
},
})
Expand Down

0 comments on commit 6e42d42

Please sign in to comment.