-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
In issue #867 I suggested an idea to make tags that depend on the result of scripts, just like health checks.
I run mongo in the cloud with multiple machines all spun up from the same image. On boot they will query for mongodb.service.consul and join the cluster. That all works flawlessly. In being a good Ops person I have a cron job that will kill random machines in my infrastructure at random times. It will eventually hit the mongodb master, the system will hiccup and a slave will be promoted automatically. Life is fantastic.
In comes Legacy Software that must connect directly to the master mongodb instance. I would like to have master.mongodb.service.consul resolve to the one IP of the master in the cluster.
Current solution (runs via cron on all machines):
- Get my service definition through API
- Check the status of the cluster. This determines if we should or should not have a tag.
- Determine if the service definition's tag list needs to be updated.
- If an update is required, POST data back to the API.
Ideal solution:
- Set up my service definition with dynamic tags.
- Write a script that returns the status of the cluster, with an exit code of 0 meaning to apply the tag.
- Let consul update itself automatically.
Sample JSON (one static tag, one dynamic tag):
{
"service": {
"name": "mongodb",
"tags": [
"fault-tolerant",
{
"name": "master",
"script": "/usr/local/bin/mongo-is-master.sh",
"interval": "10s"
}
],
"address": "127.0.0.1",
"port": 8000,
"checks": [
{
"script": "/usr/local/bin/mongo-health-check.sh",
"interval": "10s"
}
]
}
}
This sort of solution could apply to issue #155 and #867, and possibly other.