Skip to content

Dynamic tags applied like health checks. #1048

@fidian

Description

@fidian

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    theme/service-metadataAnything related to management/tracking of service metadatathinkingMore time is needed to research by the Consul Contributors

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions