So long to a classic mongodb ping and liveness check. Hello to a new exercise project, mdb_isready

Post Status: Work-in-Progress

One of my favorite ways to check end-to-end network health of a mongod process was with a very basic curl test to the server.

I value(d) this simple health check because an HTTP handshake with a mongod will return:

$ curl localhost:27017
It looks like you are trying to access MongoDB over HTTP on the native driver port.

This seemingly simple test is incredibly insightful, especially when dealing with multiple proxies (potentially terminated and relayed), compared to nc or telnet and friends.

Not only did we receive a connection, implying DNS, routing, security groups and network policies, are all functioning; we also know for a fact that the responding service was a mongod server. All with a simple utility available even in many “minimal” container images. We didn’t need mongosh or mongo and have a fairly high confidence we can move on to the next troubleshooting task.

I suspect the origin of this response in the mongod sources from an old HTTP REST/CRUD like service that used to be included in the mongod executable. This feature was deprecated in MongoDB 3.2.

Code must be cleaned up and mongod removed some of the last remnants of this feature in MongoDB 8.2.

How does the server behave to HTTP requests now?

$ curl -vk localhost:27777
* processing: localhost:27777
*   Trying [::1]:27777...
* Connected to localhost (::1) port 27777
> GET / HTTP/1.1
> Host: localhost:27777
> User-Agent: curl/8.2.1
> Accept: */*
> 
* Empty reply from server
* Closing connection
curl: (52) Empty reply from server

Still useful, but not as confidence boosting.

Oh well, maybe this is for the best. It got me thinking about how there isn’t a solid equivalient of pg_isready for MongoDB. There’s a need here for a lightweight executable that has strong confidence that a database is ready for reads and writes. So I started a small educational project to write mdb_isready in a handful of different languages and image packaging. It’s been a fun experiment, especially the “bit-banging” c-diet attempt.

Github Repo: jalder/mdb_isready

Please feel free to use the source and examples as inspiration for your own kubernetes initContainers, readinessProbe/livenessProbe checks, and other health check executables.

Some excerpts from the repo README.md that I think are interesting:


mdb_isready in Rust!

Statically compiled with musl and this turns out to be the smallest of the implementations so far.

docker.io/jalder85/mdb_isready                                         rust           3224c41d313b  4 minutes ago  9.74 MB
docker.io/jalder85/mdb_isready                                         go             0dbdb0bff331  22 hours ago   12.9 MB
docker.io/jalder85/mdb_isready                                         c              7bb21bd2175c  23 hours ago   62.9 MB

The c-diet experiment was the smallest, but has the least features:

Image Size

jak@localhost:~/Repositories/mdb_isready/c-diet$ docker image ls | grep diet
localhost/mdb_isready                                                  c-diet         606fcf684b00  About a minute ago  958 kB