Announcing Kong: A server description and deployment testing tool

At work we have to manage a ton of Django based sites. Just for our World Company sites, we have over 50 different settings files, and this doesn't take into account the sites that we host for other clients. At this size it becomes basically impossible to test each site in a browser when you push things to production. To solve this problem I have written a very basic server description tool. This allows you to describe sites (settings file, python path, url, etc.) and servers.

You can see a basic version running for my personal site. It is super barebones, but it should give you an idea of what exactly is possible.

The source is available on Github. A 0.1 release will be uploaded to Pypi soon, after a few of the blemishes have been worked out. I would like to thank Nathan Borror for the design parts that are pretty :)

What does it do?

Admin

On top of this base, I have written a way to run tests against these sites. You can categorize the sites by the type of site they are (We have Marketplace, ported Ellington, and old Ellington sites). This allows you to run tests against different types of sites. You may also have custom applications that run on only one or two certain domains. You can specify specific sites for tests to be run against as well.

The tests are written in Twill, which is a simple Python DSL for testing. Twill was chosen because it is really simple, and does functional testing well. The twill tests are actually rendered as Django templates, so you get the site that you are testing against in the context. A simple example that tests the front page of a site is as follows:

go {{ site.url }}
code 200
find "Latest News"

This simply loads the Site's front page, checks that the status code was 200, and checks that the string Latest News is on that page. The arguments to find are actually a regex, allowing for lots of power in checking for content.

This then gives you the ability to view all of the results for your tests in a web interface. Below is an example of the live view that I see when looking at our servers. We have only just started using Kong, but the tests it provides are really useful to make sure that functionality works after a deployment.

You can also see the history of a test on a site. Currently it shows the last 15 results, but paginating this page will be easy. It allows you to see if your test has been running well over time. Another nice thing is that it measures the Duration of the test, so that you can see if it is going slow or fast.

As you can see, the data display is really basic. It will be improved, but currently its basically the "simplest thing that could possibly work".

Using it yourself

When we deploy code changes, I generally run the Kong tests against our sites, making sure that things work. When we launch something new, I will write a kong test to exercise it across all sites. The tests usually take a minute to write, and save lots of time and heart ache, knowing all the sites work.

At the moment the tests can be kicked off by a django management command. The check_sites command will allow you to run all of the tests for a given Type or Test. Allowing you to run all of the Ellington tests across all sites, or just run one test across all sites.

 django-admin.py check_sites --type ellington
 django-admin.py check_sites --test test-front-page

We currently have this wired up to a cron job that runs every 10 minutes. If you set the KONG_MAIL_MANAGERS settings to True, it will send an email to the site managers on a test failure. At some point in the future, I will be integrating Kong into Nagios, so that Nagios will handle the running and alerting of errors. That is eventually the way that it will be run.

There are a lot of ways that this can be improved, however in it's current state it works for me. I figured releasing it will allow anyone who needs something like this to be able to use it. There is no documentation or tests, which will be fixed soon! The web display can also be improved a ton, and that is a high priority as well.

Let me know if you have any constructive criticism, or questions. There are a couple other little nuggets hidden in the source, so poke through if you want. Otherwise I'll write up some proper docs soon, so that you can use it.




Comments

1 Eric Florenzano says...

Hey, pretty cool!

Any reason why you chose to roll your own solution instead of using Selenium?

Posted at 8:03 a.m. on November 18, 2009

2 Benjamin Dell says...

Hi. This looks like a pretty awesome project. As I am sure is the case for many others out there, I host a number of sites internally as well as externally. To be able to track and test specific areas of the sites would be great.

I've downloaded it from github and had a play around with it, but am unable to get it to work. When i run check_sites it just returns "no action". Appreciate this project is in the early stages, but any documentation would be much welcomed.

Would also love to see a couple of other blog posts on this project.

Posted at 9:55 a.m. on November 18, 2009

3 John Chandler says...

Looks very cool indeed - good work! Will download and give it a try sometime as this could be ideal for some forthcoming projects using Django.

Posted at 10:30 a.m. on November 18, 2009

4 Jannis Leidel says...

Congrats, dude! Been looking forward to the release and will follow your example of writing tests for my own site in the #sitesprint. Thanks for sharing!

Posted at 1:41 p.m. on November 18, 2009

5 Brent O'Connor says...

Nice job. I think I'm going to file this under something to use when I have tons of sites to monitor.

Posted at 3:14 p.m. on November 18, 2009

6 Kevin says...

Looks terrific. Gonna go look for the nuggets of golden code you speak of now.

Posted at 3:45 p.m. on November 18, 2009

7 Marc Puig says...

I've just installed and tested kong and it looks awsome! Thanks for sharing!

Posted at 4:12 p.m. on November 18, 2009

8 Chris Heisel says...

This is great!

We were doing some basic Twill monitoring via cron at my last job but we always wanted to build something like this.

Posted at 4:58 p.m. on November 18, 2009

9 Michael Richardson says...

@eric - I don't think that this has a large overlap with Selenium. Selenium is great for testing complex browser interaction - Twill is a much simpler, much faster and lower level gut check. With Twill, the integration is fast and easy and tests are incredibly simple to write.

That being said, for sites that rely on heavy javascript interaction, I would say that Selenium is something that should be used - in my experience, however, it's been way overkill for most of what we needed to do.

Posted at 5:07 p.m. on November 18, 2009

10 Patrick Altman says...

This is very compelling. Going to be using this as soon as I can in my various web apps. Great work and thanks!

Posted at 6:02 p.m. on November 18, 2009

11 John Lamber says...

This is really cool. Thank you for sharing. I will download and give it a spin.

Posted at 6:07 p.m. on November 18, 2009

12 Ed Marshall says...

Nicely done; bolted up to a sqlite db, it should be resilient against database failure, which is one of my typical concerns about tools like this. :) Setup was simple enough.

It looks like I'll probably need to write a quick script to trim results beyond a certain age.

Posted at 8:12 p.m. on November 18, 2009

13 Ed Marshall says...

Also, the bare check for "http://" in the URL in models.py isn't quite appropriate; in my case, I have a few SSL websites to check. :-)

Perhaps something along the lines of this instead at line 48 in models.py?

if urlparse.urlsplit(curr_site).scheme == '':

Posted at 8:38 p.m. on November 18, 2009

Comments support markdown

Comments are closed.

Comments have been close for this post.