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

Add health check to users service #268

Merged
merged 2 commits into from
Feb 27, 2023
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
9 changes: 6 additions & 3 deletions infrastructure/cdk/src/providers/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ export class NetworkStack extends cdk.Stack {
const config = new Config()

/** Create a stage-specific Ec2 VPC and ECS cluster */
this.vpc = new ec2.Vpc(this, config.getFullStackResourceName(this.name, 'vpc'))
this.cluster = new ecs.Cluster(this, config.getFullStackResourceName(this.name, 'cluster'), { vpc: this.vpc })

this.vpc = new ec2.Vpc(this, config.getFullStackResourceName(this.name, 'vpc'), {
natGateways: 0
})
this.cluster = new ecs.Cluster(this, config.getFullStackResourceName(this.name, 'cluster'), {
vpc: this.vpc
})
}
}
8 changes: 7 additions & 1 deletion infrastructure/cdk/src/providers/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class UsersStack extends cdk.Stack {
const { certificate, cluster, hostedZone } = props

/** Create a load-balanced service for the users express API */
new ecsPatterns.ApplicationLoadBalancedFargateService(this, config.getFullStackResourceName(this.name, 'fargate'), {
const usersService = new ecsPatterns.ApplicationLoadBalancedFargateService(this, config.getFullStackResourceName(this.name, 'fargate'), {
assignPublicIp: true,
certificate,
cluster,
domainName: `${subdomains.users}.${rootDomain}`, // e.g. users.casimir.co or users.dev.casimir.co
Expand All @@ -36,5 +37,10 @@ export class UsersStack extends cdk.Stack {
}
}
})

/** Override the default health check path */
usersService.targetGroup.configureHealthCheck({
path: '/health'
})
}
}
2 changes: 2 additions & 0 deletions services/users/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import cors from 'cors'
import login from './routes/login'
import auth from './routes/auth'
import users from './routes/users'
import health from './routes/health'

const port = process.env.PUBLIC_AUTH_PORT || 4000

Expand All @@ -13,6 +14,7 @@ app.use(cors())
app.use('/login', login)
app.use('/auth', auth)
app.use('/users', users)
app.use('/health', health)

app.listen(port)
console.log(`Auth server listening on port ${port}`)
9 changes: 9 additions & 0 deletions services/users/src/routes/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import express from 'express'

const router = express.Router()

router.get('/', (_req, res) => {
res.status(200).send('OK')
})

export default router