#health #rocket #rocket-framework #http #microservices #json #environment

app http-envinfo

This package provides JSON API of health for microservice. It's using rocket framework.

1 unstable release

new 0.1.0 Jan 6, 2025

#123 in HTTP server

Download history 93/week @ 2025-01-01

93 downloads per month

MIT license

21KB
253 lines

envinfo

Getting started

EnvInfo is an open-source project. This goal is to provide a very small micro-service which display the execution environment in a JSON on the HTTP protocol.

It is written in the Rust language with the Rocket framework and offers a container image for using in a Kubernetes cluster, for example.

Below, find the instruction for localy rebuild the project and create a container image (based on docker runtime). Else, the current docker image is provide in gitlab registry registry.gitlab.com/tech-engineering/tools/envinfo.

Build and run source codes

Build source code:

cargo build

And run the source code, run http server on port 8000:

ROCKET_PROFILE=debug cargo run

Test with httpie:

http http://127.0.0.1:8000

Build container image

Build image for two platform CPU architecture (amd64 and arm64):

docker buildx build \
       --push \
       --platform linux/amd64,linux/arm64 \
       -t envinfo:v0.1-test \
       -f Dockerfile.alpine .
docker run --rm --name info -p 8080:8080 \
       -d envinfo:v0.1-test

Remark: The port and address allow are configured for 0.0.0.0 on 8080.

Test the endpoints (with httpie):

http http://localhost:8080
http http://localhost:8080/health
http http://localhost:8080/health/ready
http http://localhost:8080/health/alive
http http://localhost:8080/health/started

Health probes implemented

The microservice implemented 4 endpoints:

  • /health/alive
  • /health/ready
  • /health/started
  • /health

These endpoints respond with HTTP status 200 OK on success or 503 Service Unavailable on failure, and a JSON object like the following: Successful response for endpoints without additional per-check information:

{
    "status": "UP",
    "checks": []
}

Only for /health/started endpoint:

{
    "status": "STARTED",
    "endpoints": ["/health","/health/alive","/health/ready","/health/started"]
}

Deploy on kubernetes cluster

The yaml manifest is ready to use. Apply on your cluster:

kubectl apply -f deploy/k8s/envinfo-deploy.yaml

Check it:

kubectl port-forward svc/envinfo-svc --address 0.0.0.0 80:8080

Using

Test the endpoints (with httpie):

http http://localhost
http http://localhost/health
http http://localhost/health/ready
http http://localhost/health/alive
http http://localhost/health/started

Example, hostname of container:

http http://localhost | jq ".hostname"

or distro:

http http://localhost | jq ".distro"

or ip:

http http://localhost | jq ".net_interface.[].ip"

or name of environment variables:

http http://localhost | jq ".environment.[].name"

Search in particular an environment variable (here ROCKET_ADDRESS):

http http://localhost | jq '.environment.[] | select (.name=="ROCKET_ADDRESS")'

or (only value):

http http://localhost | jq '.environment.[] | select (.name=="ROCKET_ADDRESS")' | jq ".value"

Contributing

Thanks to participate at this project if you want :)

I need any ideas about what display informations, or other.

License

MIT License

Dependencies

~16–46MB
~782K SLoC