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

Add health check API #5

Merged
merged 1 commit into from
Nov 4, 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
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(())
}