airbnb/synapse — pull request #102 by ajf8 (2014-12-02 17:49:59+00:00)
Title: virtual/indirect backends in zookeeper

Hi :)

I'm looking at using smartstack to replace our current mess of apache, mod_jk, and mod_rewrite rules which we use for some fairly complex SOA routing. We think smartstack is great and I've been able to get a lot working, integrated nicely with puppet. Thanks for sharing it.

Anyhow, one of the things we do a lot of is "blue/green" deployments. We test the dark deployment by routing to it using a special query parameter or cookie, and once it's OK our deployment scripts update a mod_rewrite map file which causes traffic to start being routed to it. Maybe we will move beyond the concept of "blue" or "green" to versions in the future.

I couldn't figure out a way to do this easily with nerve/synapse (would be interested if anyone else does this). So in the zookeeper backend I've added an optional level of indirection which you can use with the "indirect_path" discovery parameter. It sets up a watch on this node, as well as the one it refers to.

I thought I'd share it, just in case anyone else likes the idea.

So nerve registers into

/nerve/services/marketlist/blue and /nerve/services/marketlist/green

synapse has this configured for the dark service:

"indirect_path":"/nerve/services/marketlist/dark",
...
"shared_frontend":[
"acl url_marketlist path_beg /marketlist",
"acl url_marketlist_dark url_sub marketlist_dark",
"use_backend marketlist_dark if url_marketlist url_marketlist_dark"
],

and this for live:

"indirect_path":"/nerve/services/marketlist/live",
...
"shared_frontend":[
"acl url_marketlist path_beg /marketlist",
"use_backend marketlist_live if url_marketlist"
],

so in zookeeper

set /nerve/services/marketlist/dark /nerve/services/marketlist/blue
set /nerve/services/marketlist/live /nerve/services/marketlist/green

And now we can switch these round easily.