Skip to content

Commit

Permalink
Merge pull request #749 from wellcomecollection/rk/add-healthcheck-en…
Browse files Browse the repository at this point in the history
…dpoint-concepts

Adds a simple healthcheck endpoint for the concepts service
  • Loading branch information
kenoir authored Jan 26, 2024
2 parents c137f3f + dc6161e commit c939911
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
2 changes: 2 additions & 0 deletions concepts/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
conceptController,
conceptsController,
errorHandler,
healthcheckController,
} from "./controllers";
import { Config } from "../config";
import { Clients } from "./types";
Expand All @@ -16,6 +17,7 @@ const createApp = (clients: Clients, config: Config) => {

app.get("/concepts", conceptsController(clients, config));
app.get("/concepts/:id", conceptController(clients, config));
app.get("/management/healthcheck", healthcheckController(config));

app.use(errorHandler);

Expand Down
16 changes: 16 additions & 0 deletions concepts/src/controllers/healthcheck.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { RequestHandler } from "express";
import asyncHandler from "express-async-handler";
import { Config } from "../../config";

type PathParams = { id: string };

const healthcheckController = (config: Config): RequestHandler<PathParams> => {
return asyncHandler(async (req, res) => {
res.status(200).json({
status: "ok",
config,
});
});
};

export default healthcheckController;
3 changes: 2 additions & 1 deletion concepts/src/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import conceptController from "./concept";
import conceptsController from "./concepts";
import healthcheckController from "./healthcheck";

export { errorHandler } from "./error";
export { conceptController, conceptsController };
export { conceptController, conceptsController, healthcheckController };
20 changes: 4 additions & 16 deletions terraform/modules/service/target_group.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,10 @@ resource "aws_lb_target_group" "tcp" {
# updated service. Reducing this parameter to 90s makes deployments faster.
deregistration_delay = 90

dynamic "health_check" {
for_each = var.tcp_healthcheck == false ? toset([]) : toset([1])

content {
protocol = "TCP"
}
}

dynamic "health_check" {
for_each = var.tcp_healthcheck == true ? toset([]) : toset([1])

content {
protocol = "HTTP"
path = var.healthcheck_path
matcher = "200"
}
health_check {
protocol = "HTTP"
path = var.healthcheck_path
matcher = "200"
}
}

Expand Down
7 changes: 0 additions & 7 deletions terraform/modules/service/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,7 @@ variable "app_memory" {
type = number
}

variable "tcp_healthcheck" {
# TODO: Remove this when all services use HTTP healthcheck
type = bool
default = true
}

variable "healthcheck_path" {
# Note: this is only used when tcp_healthcheck is set to false
type = string
default = "/management/healthcheck"
}
Expand Down

0 comments on commit c939911

Please sign in to comment.