rabbitmq / rabbitmq-autocluster

RabbitMQ peer discovery and cluster formation plugin, supports RabbitMQ 3.6.x
BSD 3-Clause "New" or "Revised" License
242 stars 54 forks source link

Add consul_deregister_after parameter #3

Closed Gsantomaggio closed 7 years ago

Gsantomaggio commented 7 years ago

Fixes https://github.com/aweber/rabbitmq-autocluster/issues/136

consul_deregister_after is a wrapper for the consul command deregister_critical_service_after

Param values:

Default value: "" = undefined

How to test it: 1.

CONSUL_DEREGISTER_AFTER=60  CONSUL_SVC_ADDR_AUTO=true AUTOCLUSTER_TYPE=consul  CONSUL_HOST=localhost  gmake run-broker

2. Check the RabbitMQ registration on Consul:

curl http://localhost:8500/v1/catalog/service/rabbitmq | python -m json.tool
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   337  100   337    0     0  57128      0 --:--:-- --:--:-- --:--:-- 67400
[
    {
        "Address": "10.100.1.68",
        "CreateIndex": 9,
        "ID": "0434e5f3-9e3a-3cc2-97ac-46b0c312a783",
        "ModifyIndex": 9,
        "Node": "mac",
        "NodeMeta": {},
        "ServiceAddress": "mac",
        "ServiceEnableTagOverride": false,
        "ServiceID": "rabbitmq:mac",
        "ServiceName": "rabbitmq",
        "ServicePort": 5672,
        "ServiceTags": [],
        "TaggedAddresses": {
            "lan": "10.100.1.68",
            "wan": "10.100.1.68"
        }
    }
]
  1. stop the node, after ~ 30s you will see:
2017/03/16 13:45:39 [WARN] agent: Check 'service:rabbitmq:mac' missed TTL, is now critical
2017/03/16 13:45:39 [INFO] agent: Synced check 'service:rabbitmq:mac'

and after ~60 seconds you will see:

2017/03/16 13:47:01 [INFO] agent: Check "service:rabbitmq:mac" for service "rabbitmq:mac" has been critical for too long; deregistered service
 2017/03/16 13:47:01 [INFO] agent: Deregistered check 'service:rabbitmq:mac'

and the service is removed from consul

curl http://localhost:8500/v1/catalog/service/rabbitmq                      
[]%  

Note: I put this log because (for my side) does not make sense to enable the deregister_critical_service_after param without TTL