Skip to content

Commit

Permalink
Add version to health endpoint (#123)
Browse files Browse the repository at this point in the history
The healthcheck has been moved from '/' to '/health' and now includes the Git SHA. Also, the Dockerfile has been refactored to not build dependencies when there's only a change in source

Co-authored-by: Josh Day <emailjoshday@gmail.com>
  • Loading branch information
fivegrant and joshday authored Oct 11, 2023
1 parent 52b7165 commit 63a46a6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
9 changes: 7 additions & 2 deletions docker/Dockerfile.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 19 additions & 9 deletions src/SimulationService.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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[])
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 63a46a6

Please sign in to comment.