Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SYS-343: Introduced two new endpoints, /is-alive and /is-healthy #57

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This is a node that runs as part of the shardus network, with the function of re

To release, just run `npm run release`

## Health Check

GET `/is-alive` this endpoint returns 200 if the server is running.
GET `/is-healthy` currently the same as `/is-alive` but will be expanded.

## Contributing

Contributions are very welcome! Everyone interacting in our codebases, issue trackers, and any other form of communication, including chat rooms and mailing lists, is expected to follow our [code of conduct](./CODE_OF_CONDUCT.md) so we can all enjoy the effort we put into this project.
14 changes: 14 additions & 0 deletions src/routes/healthCheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { FastifyPluginCallback } from 'fastify'

export const healthCheckRouter: FastifyPluginCallback = function (fastify, opts, done) {
fastify.get('/is-alive', (req, res) => {
return res.status(200).send('OK')
})

fastify.get('/is-healthy', (req, res) => {
// TODO: Add actual health check logic
return res.status(200).send('OK')
})

done()
}
2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { loadGlobalAccounts, syncGlobalAccount } from './GlobalAccount'
import { setShutdownCycleRecord, cycleRecordWithShutDownMode } from './Data/Cycles'
import { registerRoutes } from './API'
import { Utils as StringUtils } from '@shardus/types'
import { healthCheckRouter } from './routes/healthCheck'

const configFile = join(process.cwd(), 'archiver-config.json')
let logDir: string
Expand Down Expand Up @@ -438,6 +439,7 @@ async function startServer(): Promise<void> {
timeWindow: 10,
allowList: ['127.0.0.1', '0.0.0.0'], // Excludes local IPs from rate limits
})
await server.register(healthCheckRouter)

server.addContentTypeParser('application/json', { parseAs: 'string' }, (req, body, done) => {
try {
Expand Down
Loading