OK Computer - Application Health Check for Rails

Technologies: RSpec, Ruby, Ruby Gems, Rails Engines

Why Did I Make This?

We used Fitter Happier for simple health checks (both for HAProxy to verify a server is functioning and to alert us through Pingdom in case of other problems). This worked well, and was basically a plug-and-play solution to confirm that the app is working and that it can connect to the database.

But, one of our apps uses MongoDB instead of ActiveRecord. Fitter Happier provides no customization, so we subclassed FitterHappierController and overwrote the methods we wanted. Then in another project, we use Resque, and wanted to check the length of the “critical” queue and alert us if it gets backed up. More monkey patching commenced.

Now we needed it in some other project and copied and pasted the monkey patches, at which point I figured enough was enough.

We wanted a similar gem, where we could just insert it into our Gemfile and forget about it in the common case, but to be able to add or remove checks on a per-application basis.

OK Computer was born.

It comes with a default check that just renders some text (to confirm that Rails works) and another that connects to the database to verify that it works. Other built-in checks are available for Mongoid connections for Resque and easy to enable. Adding your own custom checks is also trivially easy.

We’re using this in production now in almost all of our apps and we’re incredibly happy with it. It’s still fairly new, and we want to let it bake a bit more before we bump it to 1.0.

What Did I Learn?

I learned a couple of things. Most concretely, I learned how to build a Rails engine. It’s not particularly well documented, and there’s a bunch of terrible examples out there. I don’t think mine is one of the terrible ones, but time will tell.

On a more abstract level, I learned a lot about building an extensible system. If you look over time, you’ll see that it shipped initially with an entirely different mechanism to return the result of a check. It wasn’t particularly good. The new implementation is far more flexible, but I’m still not entirely happy with it.

Posted 2013-04-05 in Projects.