From e4b7aeaaf8c82ed3bf3dae84e2e4e27ea228fe29 Mon Sep 17 00:00:00 2001 From: Five Grant <5@fivegrant.com> Date: Tue, 10 Oct 2023 15:28:21 -0500 Subject: [PATCH 1/2] Add version to health endpoint The healthcheck has been moved from '/' to '/health' and now includes the Git SHA. Also, the Dockefile has been refactored to not build dependencies when there's only a change in source. --- docker/Dockerfile.api | 9 +++++++-- src/SimulationService.jl | 28 +++++++++++++++++++--------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/docker/Dockerfile.api b/docker/Dockerfile.api index a1caeaf..180fcb9 100644 --- a/docker/Dockerfile.api +++ b/docker/Dockerfile.api @@ -2,12 +2,17 @@ FROM julia:1.9 WORKDIR /sciml-service # Install SimulationService.jl +ENV JULIA_PROJECT=. COPY Project.toml /sciml-service/ COPY Manifest.toml /sciml-service/ +RUN julia -e 'using Pkg; Pkg.instantiate();' COPY src/ /sciml-service/src/ COPY examples/ /sciml-service/examples/ -ENV JULIA_PROJECT=. -RUN julia -e 'using Pkg; Pkg.instantiate();' + +COPY .git/HEAD .git/HEAD +COPY .git/refs .git/refs +RUN grep '^ref:' .git/HEAD && cp .git/`cat .git/HEAD | awk '/^ref: / {print $2}'` .version || cp .git/HEAD /sciml-service/.version +RUN rm -fr .git # Launch sciml-service EXPOSE 8080 diff --git a/src/SimulationService.jl b/src/SimulationService.jl index 2b3fe50..258ee4b 100644 --- a/src/SimulationService.jl +++ b/src/SimulationService.jl @@ -103,14 +103,14 @@ function start!(; host=HOST[], port=PORT[], kw...) JobSchedulers.set_scheduler(max_cpu=JobSchedulers.SCHEDULER_MAX_CPU, max_mem=0.5, update_second=0.05, max_job=5000) Oxygen.resetstate() - Oxygen.@get "/" health + Oxygen.@get "/health" health Oxygen.@get "/status/{id}" job_status - Oxygen.@post "/kill/{id}" job_kill + Oxygen.@post "/kill/{id}" job_kill Oxygen.@post "/simulate" req -> operation(req, "simulate") Oxygen.@post "/calibrate" req -> operation(req, "calibrate") Oxygen.@post "/ensemble-simulate" req -> operation(req, "ensemble-simulate") - Oxygen.@post "/ensemble-calibrate" req -> operation(req, "ensemble-calibrate") + Oxygen.@post "/ensemble-calibrate" req -> operation(req, "ensemble-calibrate") # For /docs Oxygen.mergeschema(openapi_spec[]) @@ -189,12 +189,22 @@ function job_kill(::HTTP.Request, id::String) end #-----------------------------------------------------------------------------# health: GET / -health(::HTTP.Request) = ( - status = "ok", - RABBITMQ_ENABLED = RABBITMQ_ENABLED[], - RABBITMQ_ROUTE = RABBITMQ_ROUTE[], - ENABLE_TDS = ENABLE_TDS[] -) +function health(::HTTP.Request) + version_filepath = normpath(joinpath(@__FILE__,"../../.version")) + version = + if ispath(version_filepath) + version_filepath |> strip ∘ String ∘ read ∘ open + else + "unknown" + end + ( + status = "ok", + git_sha = version, + RABBITMQ_ENABLED = RABBITMQ_ENABLED[], + RABBITMQ_ROUTE = RABBITMQ_ROUTE[], + ENABLE_TDS = ENABLE_TDS[] + ) +end #-----------------------------------------------------------------------------# OperationRequest Base.@kwdef mutable struct OperationRequest From 11bc7710646b18fbdebc4ecc518f84e54603fe6f Mon Sep 17 00:00:00 2001 From: Josh Day Date: Wed, 11 Oct 2023 10:08:43 -0400 Subject: [PATCH 2/2] Fix test --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 8958d3d..21869e9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -215,8 +215,8 @@ end #-----------------------------------------------------------------------------# test routes @testset "Server Routes" begin SimulationService.with_server() do url - @testset "/" begin - res = HTTP.get(url) + @testset "/health" begin + res = HTTP.get("$url/health") @test res.status == 200 @test JSON3.read(res.body).status == "ok" end