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

Adds a simple healthcheck endpoint for the requests service #747

Merged
merged 3 commits into from
Jan 26, 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
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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I saw this, I was slightly concerned that it might be a vector for leaking secrets.

It isn't, but is there a risk that someone might unwittingly expose something in the future by adding it to the 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 };
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ class RequestsApi(
} ~ get {
lookupRequests(userIdentifier)
}
}
},
pathPrefix("management") {
concat(path("healthcheck") {
get {
complete("message" -> "ok")
}
})
}
)
}

Expand Down
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