Skip to content

Commit

Permalink
switched from healthchecks to status checks
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Jan 28, 2023
1 parent 832de33 commit f9b1347
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 26 deletions.
2 changes: 1 addition & 1 deletion calendar/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
EXPOSE 8083

ENTRYPOINT ["tini", "--"]
HEALTHCHECK --start-period=20m --timeout=10s CMD curl --fail localhost:8083/api/health || exit 1
HEALTHCHECK --start-period=20m --timeout=10s CMD curl --fail localhost:8083/api/calendar/status || exit 1
CMD /bin/navigatum-calendar
12 changes: 8 additions & 4 deletions calendar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ use actix_web::{get, middleware, web, App, HttpResponse, HttpServer};

const MAX_JSON_PAYLOAD: usize = 1024 * 1024; // 1 MB

#[get("/api/calendar/health")]
async fn health_handler() -> HttpResponse {
#[get("/api/calendar/status")]
async fn health_status_handler() -> HttpResponse {
let github_link = match std::env::var("GIT_COMMIT_SHA") {
Ok(hash) => format!("https://github.com/TUM-Dev/navigatum/tree/{hash}"),
Err(_) => "unknown commit hash, probably running in development".to_string(),
};
HttpResponse::Ok()
.content_type("text/plain")
.body("healthy")
.body(format!("healthy\nsource_code: {github_link}"))
}

#[actix_web::main]
Expand All @@ -33,7 +37,7 @@ async fn main() -> std::io::Result<()> {
.wrap(middleware::Logger::default())
.wrap(middleware::Compress::default())
.app_data(web::JsonConfig::default().limit(MAX_JSON_PAYLOAD))
.service(health_handler)
.service(health_status_handler)
})
.bind(std::env::var("BIND_ADDRESS").unwrap_or_else(|_| "0.0.0.0:8060".to_string()))?
.run()
Expand Down
4 changes: 2 additions & 2 deletions deployment/k3s/templates/deployments/calendar-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ spec:
memory: 500Mi
livenessProbe:
httpGet:
path: /api/calendar/health
path: /api/calendar/status
port: calendar
failureThreshold: 2
periodSeconds: 10
startupProbe:
httpGet:
path: /api/calendar/health
path: /api/calendar/status
port: calendar
failureThreshold: 60
periodSeconds: 1
4 changes: 2 additions & 2 deletions deployment/k3s/templates/deployments/feedback-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ spec:
memory: 40Mi
livenessProbe:
httpGet:
path: /api/feedback/health
path: /api/feedback/status
port: feedback
failureThreshold: 2
periodSeconds: 1
startupProbe:
httpGet:
path: /api/feedback/health
path: /api/feedback/status
port: feedback
failureThreshold: 6
periodSeconds: 1
Expand Down
4 changes: 2 additions & 2 deletions deployment/k3s/templates/deployments/server-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ spec:
memory: 700Mi
livenessProbe:
httpGet:
path: /api/health
path: /api/status
port: api
failureThreshold: 1
periodSeconds: 1
startupProbe:
httpGet:
path: /api/health
path: /api/status
port: api
failureThreshold: 60
periodSeconds: 1
Expand Down
2 changes: 1 addition & 1 deletion feedback/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
EXPOSE 8070

ENTRYPOINT ["tini", "--"]
HEALTHCHECK --start-period=20m --timeout=10s CMD curl --fail localhost:8070/api/feedback/health || exit 1
HEALTHCHECK --start-period=20m --timeout=10s CMD curl --fail localhost:8070/api/feedback/status || exit 1
CMD /bin/navigatum-feedback
14 changes: 9 additions & 5 deletions feedback/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ pub struct Opt {
jwt_key: Option<String>,
}

#[get("/api/feedback/health")]
async fn health_handler() -> HttpResponse {
#[get("/api/feedback/status")]
async fn health_status_handler() -> HttpResponse {
let github_link = match std::env::var("GIT_COMMIT_SHA") {
Ok(hash) => format!("https://github.com/TUM-Dev/navigatum/tree/{hash}"),
Err(_) => "unknown commit hash, probably running in development".to_string(),
};
HttpResponse::Ok()
.content_type("text/plain")
.body("healthy")
.body(format!("healthy\nsource_code: {github_link}"))
}

#[tokio::main]
Expand All @@ -48,10 +52,10 @@ async fn main() -> std::io::Result<()> {

App::new()
.wrap(cors)
.wrap(middleware::Logger::default().exclude("/api/feedback/health"))
.wrap(middleware::Logger::default().exclude("/api/feedback/status"))
.wrap(middleware::Compress::default())
.app_data(web::JsonConfig::default().limit(MAX_JSON_PAYLOAD))
.service(health_handler)
.service(health_status_handler)
.service(
web::scope("/api/feedback")
.configure(core::configure)
Expand Down
35 changes: 29 additions & 6 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ paths:
- Not found
tags:
- migration
/api/health:
/api/status:
get:
operationId: api-health
summary: API healthcheck
Expand All @@ -950,14 +950,15 @@ paths:
text/plain:
schema:
type: string
enum:
- healthy
example: |
healthy
source code: https://github.com/TUM-Dev/navigatum/tree/8a0fb71819ac88c8af35683cfb46291f0d0c9b0a
'503':
description: Service Unavailable
content: {}
tags:
- health
/api/feedback/health:
/api/feedback/status:
get:
operationId: feedback-health
summary: feedback-API healthcheck
Expand All @@ -970,8 +971,30 @@ paths:
text/plain:
schema:
type: string
enum:
- healthy
example: |
healthy
source code: https://github.com/TUM-Dev/navigatum/tree/8a0fb71819ac88c8af35683cfb46291f0d0c9b0a
'503':
description: Service Unavailable
content: {}
tags:
- health
/api/calendar/status:
get:
operationId: calendar-health
summary: calendar-API healthcheck
description: |
If this endpoint does not return 200, the API is experiencing a catastrophic outage. Should never happen.
responses:
'200':
description: Ok
content:
text/plain:
schema:
type: string
example: |
healthy
source code: https://github.com/TUM-Dev/navigatum/tree/8a0fb71819ac88c8af35683cfb46291f0d0c9b0a
'503':
description: Service Unavailable
content: {}
Expand Down
2 changes: 1 addition & 1 deletion server/Dockerfile.server
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA}
EXPOSE 8080

ENTRYPOINT ["tini", "--"]
HEALTHCHECK --start-period=20m --timeout=10s CMD curl --fail localhost:8080/api/health || exit 1
HEALTHCHECK --start-period=20m --timeout=10s CMD curl --fail localhost:8080/api/status || exit 1
CMD /bin/navigatum-server
4 changes: 2 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod utils;

const MAX_JSON_PAYLOAD: usize = 1024 * 1024; // 1 MB

#[get("/api/health")]
#[get("/api/status")]
async fn health_handler() -> HttpResponse {
HttpResponse::Ok()
.content_type("text/plain")
Expand All @@ -29,7 +29,7 @@ async fn main() -> std::io::Result<()> {

App::new()
.wrap(cors)
.wrap(middleware::Logger::default().exclude("/api/health"))
.wrap(middleware::Logger::default().exclude("/api/status"))
.wrap(middleware::Compress::default())
.app_data(web::JsonConfig::default().limit(MAX_JSON_PAYLOAD))
.service(health_handler)
Expand Down

0 comments on commit f9b1347

Please sign in to comment.