-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from airbnb/custom_watchers
Allow pluggable watchers
- Loading branch information
Showing
16 changed files
with
212 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
require 'synapse/log' | ||
require 'fileutils' | ||
require 'tempfile' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
require 'fileutils' | ||
require 'json' | ||
require 'synapse/log' | ||
require 'socket' | ||
|
||
module Synapse | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
## Watcher Classes | ||
|
||
Watchers are the piece of Synapse that watch an external service registry | ||
and reflect those changes in the local HAProxy state. Watchers should look | ||
like: | ||
|
||
```ruby | ||
require "synapse/service\_watcher/base" | ||
|
||
module Synapse::ServiceWatcher | ||
class MyWatcher < BaseWatcher | ||
def start | ||
# write code which begins running service discovery | ||
end | ||
|
||
def stop | ||
# write code which tears down the service discovery | ||
end | ||
|
||
def ping? | ||
# write code to check in on the health of the watcher | ||
end | ||
|
||
private | ||
def validate_discovery_opts | ||
# here, validate any required options in @discovery | ||
end | ||
|
||
... | ||
|
||
end | ||
end | ||
``` | ||
|
||
### Watcher Plugin Inteface | ||
Synapse deduces both the class path and class name from the `method` key within | ||
the watcher configuration. Every watcher is passed configuration with the | ||
`method` key, e.g. `zookeeper` or `ec2tag`. | ||
|
||
#### Class Location | ||
Synapse expects to find your class at `synapse/service\_watcher/#{method}`. You | ||
must make your watcher available at that path, and Synapse can "just work" and | ||
find it. | ||
|
||
#### Class Name | ||
These method strings are then transformed into class names via the following | ||
function: | ||
|
||
``` | ||
method_class = method.split('_').map{|x| x.capitalize}.join.concat('Watcher') | ||
``` | ||
|
||
This has the effect of taking the method, splitting on '_', capitalizing each | ||
part and recombining with an added 'Watcher' on the end. So `zookeeper\_dns` | ||
becomes `ZookeeperDnsWatcher`, and `zookeeper` becomes `Zookeeper`. Make sure | ||
your class name is correct. | ||
|
||
### Watcher Class Interface | ||
ServiceWatchers should conform to the interface provided by `BaseWatcher`: | ||
|
||
``` | ||
start: start the watcher on a service registry | ||
stop: stop the watcher on a service registry | ||
ping?: healthcheck the watcher's connection to the service registry | ||
private | ||
validate_discovery_opts: check if the configuration has the right options | ||
``` | ||
|
||
When your watcher has received an update from the service registry you should | ||
call `set\_backends(new\_backends)` to trigger a sync of your watcher state | ||
with local HAProxy state. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.