Repository is archived
No commit activity in last 3 years
No release in over 3 years
This is a library that provides a generic interface to multiple cluster providers. Cluster providers include: EC2 Tags, EC2 AutoScaling Groups, and Consul
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0

Runtime

~> 2.2
~> 0.15
 Project Readme

Cluster::Discovery

This is a library that provides a generic interface to multiple cluster providers.

Cluster Providers

Cluster providers are something that provides metadata about a collection of hosts in a cluster. Supported providers are as follows:

  • EC2 Tags
  • EC2 AutoScaling Groups
  • Consul Services
  • Static Lists

Installation

Add this line to your application's Gemfile:

gem 'cluster-discovery'

And then execute:

$ bundle

Or install it yourself as:

$ gem install cluster-discovery

Usage

EC2 Tags

To discover cluster instances with EC2 Tags use something like the following example. The keys aws_region, aws_tags(key, value) are all required.

This returns an Array of EC2 Instance Objects

instances = Cluster::Discovery.discover(
  'ec2_tag',
  aws_region: 'us-east-1',
  aws_tags: [{ key: 'Service', value: 'router' }])

instances.map(&:instance_id)

AutoScaling Groups

To discover cluster instances by AutoScaling Group use something like the following example. The keys aws_region, aws_asg are all required.

instances = Cluster::Discovery.discover(
  'ec2_asg',
  aws_region: 'us-east-1',
  aws_asg: 'foo-prod-v000')

instances.map(&:instance_id)

Consul

To discover cluster instances using Consul use something like the following example. The keys consul_url and consul_service are required, leader, tags, and health are optional.

By default this will only return nodes passing all health checks. To change this behavior set healthy to false.

instances = Cluster::Discovery.discover(
  'consul',
  consul_url: 'http://my.consul.cluster:8500',
  consul_service: 'redis',
  leader: true,
  tags: 'master',
  health: true)
instances.map(&:Address)

Contributing

Running the tests

TEST_CONSUL_HOST=my.consul.cluster rake spec

Or just:

rake spec
  1. Fork it ( https://github.com/rapid7/cluster-discovery/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request