-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(incident-2024-05-05): add a healthcheck that gets and sets a redis r…
…ecord (#803)
- Loading branch information
Showing
7 changed files
with
85 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
import axios from "axios"; | ||
|
||
const PORT = 8080; | ||
|
||
// We don't spin up the server in this test. | ||
it("check health", async () => { | ||
// wait ten seconds | ||
await sleep(10000); | ||
// register empty definition | ||
const healthResponse = await axios.get(`http://localhost:${PORT}/health`); | ||
expect(healthResponse.status).toEqual(200); | ||
}); | ||
const response = await fetch(`http://localhost:${PORT}/health`); | ||
expect(response.status).toEqual(200); | ||
}, 100_000); | ||
|
||
function sleep(ms: number): Promise<void> { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { LOGGER } from "../app/FdrApplication"; | ||
import { CachedDocsResponse } from "../services/docs-cache/DocsDefinitionCache"; | ||
import RedisDocsDefinitionStore from "../services/docs-cache/RedisDocsDefinitionStore"; | ||
|
||
const HEALTHCHECK_KEY = "https://healthcheck.buildwithfern.com"; | ||
const HEALTHCHECK_DOCS_RESPONSE: CachedDocsResponse = { | ||
dbFiles: {}, | ||
isPrivate: true, | ||
response: { | ||
baseUrl: { | ||
domain: "healthcheck.buildwithfern.com", | ||
}, | ||
definition: { | ||
pages: {}, | ||
apis: {}, | ||
config: { | ||
navigation: { | ||
items: [], | ||
}, | ||
}, | ||
files: {}, | ||
filesV2: {}, | ||
search: { | ||
type: "singleAlgoliaIndex", | ||
value: { | ||
type: "unversioned", | ||
indexSegment: { | ||
id: "healthcheck", | ||
searchApiKey: "dummy", | ||
}, | ||
}, | ||
}, | ||
}, | ||
lightModeEnabled: true, | ||
}, | ||
updatedTime: new Date(), | ||
version: "v1", | ||
}; | ||
|
||
export async function checkRedis({ redis }: { redis: RedisDocsDefinitionStore }): Promise<boolean> { | ||
try { | ||
const healthcheckURL = new URL(HEALTHCHECK_KEY); | ||
await redis.set({ url: healthcheckURL, value: HEALTHCHECK_DOCS_RESPONSE }); | ||
const record = await redis.get({ url: healthcheckURL }); | ||
|
||
if (record?.response.baseUrl.domain !== healthcheckURL.hostname) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} catch (err) { | ||
LOGGER.error("Encountered error while retrieving and storing redis entries", err); | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters