Skip to content

Commit

Permalink
Merge pull request #5 from saint1991/healthcheck
Browse files Browse the repository at this point in the history
Add health check API
  • Loading branch information
saint1991 authored Nov 4, 2024
2 parents 3f114d7 + c2e147d commit 8b8fad3
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
paths:
- .github/workflows/docker.yml
- proto/**.proto
- src/**
- src/**.rs
- build.rs
- Cargo.toml
- Cargo.lock
push:
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/lint-rust.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name: check-rust
name: lint-rust

on:
pull_request:
paths:
- .github/workflows/lint-rust.yml
- **.rs
- .github/workflows/docker.yml
- src/**.rs
- build.rs
- Cargo.toml
- Cargo.lock

Expand Down
64 changes: 39 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ futures-core = { version = "0.3.31" }
log = { version = "0.4.22" }
prost = { version = "0.13.3" }
prost-types = { version = "0.13.3" }
thiserror = { version = "1.0.66" }
thiserror = { version = "1.0.67" }
tokio = { version = "1.41.0", features = ["rt-multi-thread", "macros", "sync" ] }
tokio-stream = { version = "0.1.16" }
tonic = { version = "0.12.3" }
tonic-health = { version = "0.12.3" }


[build-dependencies]
Expand Down
15 changes: 14 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# syntax=docker/dockerfile:1

ARG RUST_VERSION=1.82
ARG GRPC_HEALTH_PROBE_VERSION=0.4.35

FROM rust:${RUST_VERSION}-slim-bookworm AS builder

WORKDIR /home/gduck
Expand All @@ -14,10 +16,21 @@ RUN --mount=type=cache,target=/usr/local/cargo/registry \
&& mkdir /home/gduck/dist \
&& cp /home/gduck/target/release/gduck /home/gduck/dist

FROM builder AS probe

ARG GRPC_HEALTH_PROBE_VERSION

RUN apt-get update -y \
&& apt-get install -y wget \
&& wget -O /grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/v${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64

FROM debian:bookworm-slim

COPY --from=probe --chmod=100 /grpc_health_probe /usr/local/bin
COPY --from=builder /home/gduck/dist/gduck /gduck
ENV RUST_LOG=info RUST_BACKTRACE=1

ENTRYPOINT ["/gduck"]
HEALTHCHECK --interval=10s --timeout=5s --start-period=3s --retries=3 \
CMD [ "grpc_health_probe", "--addr=127.0.0.1:50051" ]

ENTRYPOINT ["/gduck", "--port", "50051"]
11 changes: 10 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,18 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let addr: SocketAddr = format!("{}:{}", args.bind_address, args.port).parse()?;

let (mut reporter, health_service) = tonic_health::server::health_reporter();
reporter
.set_serving::<proto::db_service_server::DbServiceServer<service::DuckDbService>>()
.await;

let service = service::DuckDbService::new_server();

log::info!("Start listening on {}", addr.to_string());
Server::builder().add_service(service).serve(addr).await?;
Server::builder()
.add_service(health_service)
.add_service(service)
.serve(addr)
.await?;
Ok(())
}

0 comments on commit 8b8fad3

Please sign in to comment.