hashicorp / hashicorp/consul

Dynamic tags applied like health checks.

Open
#1,048 58 comments 66 reactions 0 assignees View on GitHub
theme/service-metadata thinking
Dominant language
Go
Stars
30.1k
Forks
4.6k
Avg merge
2d 6h
Merged PRs (30d)
43

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):
1. Get my service definition through API
2. Check the status of the cluster. This determines if we should or should not have a tag.
3. Determine if the service definition's tag list needs to be updated.
4. If an update is required, POST data back to the API.

Ideal solution:
1. Set up my service definition with dynamic tags.
2. Write a script that returns the status of the cluster, with an exit code of 0 meaning to apply the tag.
3. 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.