LibclusterEtcd

Etcd strategy for libcluster. It utilisez Etcd v2 API.

Installation

If available in Hex, the package can be installed by adding libcluster_etcd to your list of dependencies in mix.exs:

def deps do
  [
    {:libcluster_etcd, "~> 1.0.0"}
  ]
end

Configuration

Minimal configuration is list of etcd nodes etcd_nodes and directory name directory:

config :libcluster,
  topologies: [
    etcd: [
      strategy: LibclusterEtcd.Strategy,
      config: [
        etcd_nodes: ["http://10.0.0.1:2379", "http://10.0.0.2:2379"],
        directory: "cluster"
      ]
    ]
  ]

In addition to that you can control polling interval, ttl of the keys and ttl refresh interval, httpc options:

config :libcluster,
  topologies: [
    etcd: [
      strategy: LibclusterEtcd.Strategy,
      config: [
        etcd_nodes: ["http://10.0.0.1:2379", "http://10.0.0.2:2379"],
        directory: "cluster",
        ttl: 10_000,
        ttl_refresh_interval: 5_000,
        polling_interval: 5_000
      ]
    ]
  ]
ParameterRequired?Default ValueDescription
etcd_nodesYesList of etcd nodes
directoryYesEtcd directory to store cluster nodes registrations
ttlNo10_000Node’s registration ttl in ms. Uses etcd ttl to keep key alive.
ttl_refresh_intervalNo5_000How often to refresh ttl of a key, ms. Should be less than ttl.
polling_intervalNo5_000How often to scan directory and connect and disconnect nodes, ms.
http_optsNo[ timeout: 10_000, connect_timeout: 2_000, autoredirect: false, relaxed: true ]httpc options used for each request to etcd.

ttl, ttl_refresh_interval, timeout and connect_timeout should be carefully chosen. If connect_timeout is greater or equal to ttl then most likely etcd key will expire before it will be renewed if etcd client tries to connect to a dead node.