Software Circuit Breakers in Ruby

I found an interesting article in this week’s Ruby Weekly newsletter—a post from Martin Fowler about the circuit breaker concept in Ruby.

The idea is pretty simple, but pretty slick: wrap calls to external services that can fail in a ‘circuit breaker’, which will detect when the call is failing (or acting particularly slow) and short-circuit calls. In the simplest case, this can help avoid slow-downs when a non-critical remote service fails. For example, if you normally made an inline call to send a welcome email to new signups, you might fall back to just enqueuing the task if the mailserver call slows down—or perhaps just take them to a webpage with the same content.

In the best case, this can prevent cascading failures. Webpages make a blocking call to an external service, which goes down, thus filling up the queue of available application servers, thus leading to a service outage.

TripleO / Ironic Meetup in Sunnyvale

Last week a group of developers working on the OpenStack projects TripleO and Ironic convened in the sunny vale of Sunnyvale for a mid-cycle meetup.

Yahoo! Sunnyvale Campus

My focus was primarily on Ironic, though lots of discussion about TripleO happened. (Here is some Tuskar documentation, for example.) I thought it would be worthwhile to quickly summarize my experiences:

  • About 40 people turned out, including some really bright folks from HP, Yahoo!, Mirantis, Rackspace, and Red Hat. (And surely some others that I’ve temporarily forgotten—sorry!) Just meeting everyone I’ve been working with online was pretty valuable.
  • A whole ton of patches got rapidly tested and merged, since sitting in the same room instead of being on separate continents made it much more efficient. In fact, a lot of patches got written and merged.
  • We hit feature freeze Tuesday. On Monday, -2’s were given to bigger patches to ensure that we had time to review everything. The -2 will be lifted once development for Juno opens up. Some of the things bumped include:
  • Because of feature freeze across projects, the Ironic driver for Nova was temporarily copied into Ironic’s source tree so we can work on it there.
  • Described in the same email linked above, a lot of work went into extending CI coverage for Ironic though it hasn’t yet landed. This test integration will be necessary to graduate from incubation.
  • We also identified end-user documentation as an important task, one which is both required to graduate incubation and as something that can be done during feature freeze in addition to bugfixes. This Etherpad tries to outline what’s required.
  • A lot of whiteboarding was done around a ramdisk agent for Ironic. The idea is that nodes can boot up a richer agent to support more advanced configuration and lifecycle management. The link here goes to the introduction of a pretty interesting thread.

Fixing Alembic error with multiple heads

Today I went to run automated tests in my Ironic development setup, and tests failed with a slew of errors like this:

CommandError: Only a single head is supported. The script
 directory has multiple heads (due to branching), which must be 
 resolved by manually editing the revision files to form a linear 
 sequence. Run `alembic branches` to see the divergence(s).

This was quite baffling to me, and I at first assumed it was a git thing, given the references to branches and head.

I am still moderately confused. But here is how I fixed it.

Please note that: * I have little idea what I’m doing. This is what worked for me, not necessarily what someone clueful would do. * My fix involves trashing your database and recreating it. That’s perfectly acceptable for my test database, but proceed with caution.

Run alembic branches

The error told me to run alembic branches, but that failed:

$ alembic branches
  No config file 'alembic.ini' found, or file
  has no '[alembic]' section

The solution is to find your alembic.ini file. In Ironic, that’s ironic/db/sqlalchemy. cd into there, and now it will work:

$ alembic branches
None -> 2581ebaf0cb2 (branchpoint), initial migration
     -> 2581ebaf0cb2 -> 21b7629c61e7 (head), 
     -> 2581ebaf0cb2 -> 21b331f883ef (head), Add provision_updated_at

The alembic documentation talks a little bit about this, for further reading.

Look for .pyc files

Each of those hashes should point to a Python file in alembic/versions/.

I think where I went wrong is that I had switched branches and ended up with a .pyc file, but not matching .py. The name should match one of the hashes above. (I suppose you could safely just delete all the .pyc files, actually.)

Downgrade to alembic base

I’m actually not sure if this was necessary, but I did this: alembic downgrade base. If it bombs out with errors, I think we’ll fix them momentarily.

Delete the tables from your database

Now we’re basically going to start a new database.

I fired up mysql, ran USE ironic, and then deleted all the tables. You might have to play with ordering to get it right, due ot foreign key constraints.

Re-run alembic

In Ironic, we have ironic-dbsync to do this for us. If not using Ironic, I think alembic upgrade head is analogous.

And then you should be good. Hopefully.

Typing Accented Characters on Fedora 20

Being an American, I have long tended to ignore accent marks on characters from other languages, assuming they are unimportant and mostly decorative. No need to be all fancy and type résumé when “resume” works.

That ended when I tried to show off my Spanish around New Year’s, wishing someone online a “feliz ano nuevo,” only to learn that I had wished them a “happy new anus”. It turns out that the accent mark is quite important in differentiating “ano” (Spanish for ‘anus’) from “año” (Spanish for “year”). Ever since, I’ve accepted that, while more difficult to type, it’s important to use the right characters.

I’m now taking Czech lessons at work, and wish to make sure that I don’t embarrass myself again. The Czech language has a lot of accented characters. But switching to the Czech keyboard layout is awfully confusing.

Thanks to Tomas for introducing me to the concept of the “Compose” key in Linux, allowing you to type , ‘, and a to get á. The ‘Compose’ key can be mapped to any modifier key. But it’s hard to find documentation.

To enable the Compose key on Fedora 20 (in GNOME): Open the Settings menu and select ‘Keyboard’. From the Shortcut tab, find ‘Typing’, and you can now choose a key to map the Compose Key to.

Fedora 20 Compose Key

I chose the right Alt key, because I don’t use it.

To use it: Press your Compose key and release it. (You don’t have to hold it down.) Press a key corresponding to the accent, then the letter it should go over. For example, ñ is Compose, “~”, then “n”.

Here is an exhaustive list of possible characters, but here is a quick list of some common modifiers:

  • ~ will do a tilde over the character, as in ñ.
  • (single quote, next to Enter) will do a right accent, as in á
  • ` (backtick, below escape) will do a left accent, as in è
  • c will do a caron (as it is apparently called?), as in ž
  • (double quote) will do an umlaut, as in ü
  • , (comma) will do a cédille, as in ç
  • <, 3 will form a heart (♥) — remember you need shift when typing the <

Remember, you don’t have to hold down the Compose key. Just tap it, then type the next character. I keep forgetting this and doing weird gymnastics trying to type.

There are many more characters you can type, like ə, Đ, ç, ø, plus some currency signs and numeric super/subscripts, but I’ll let you view the full list to find them.

Now, typing čeština is easy! Understanding it will still be a long battle for me, but I can type it!