GithubHelp home page GithubHelp logo

elasticsearch-drain's Introduction

Elasticsearch Drain

The purpose of this utility is to drain documents from Elasticsearch nodes in an AutoScaling Group.

This will help you do Elasticsearch node replacement while keeping the cluster healthy. This is useful if you want to change the instance type of your nodes, or if you use custom AMIs and need to rollout a new AMI.

Consider the following deployment procedure:

  • Start with an AutoScaling Group with Elasticsearch nodes in a cluster
  • Create a new AutoScaling Group with Elasticsearch nodes that join the above cluster
  • Drain all data off older AutoScaling Group and remove instances from the AutoScaling Group and terminate instances

How does it work?

  1. Get the list of instances we want to remove from the cluster
  • In this case it's an entire AutoScaling Group
  1. Ask the cluster for the _id(s) of those instances
  2. Then, tell the cluster to exclude these nodes from routing, which effectively removes all documents from the nodes
  3. Loop on these nodes asking the cluster how many documents each node is storing, when one reaches 0 we move on to the next step
  4. Remove the instance from the AutoScaling Group
  5. Terminate the instance
  6. Wait a moment and go back to step 4 and continue until there are 0 instances in the AutoScaling Group

Installation

$ gem install elasticsearch-drain

Usage

  1. Create a new AutoScaling Group and populate with the same number of instances as the previous AutoScaling Group
  2. Run the tool, to start draining:
$ drain asg --asg="test-asg-0" --region="us-east-1" --host="localhost:9200"

What's next?

  • Remove a single node from the cluster
  • Drain only mode

Testing

Install all dependencies:

gem install bundler
bundle install

To enable the tests that will hit the AWS APIs pass ALLOW_DISABLED_VCR=true

Run test tests (unit and style):

rake

Or on a tight loop with guard:

bundle exec guard

If you need to make a new http request or refresh the fixtures you will need to start a test cluster.

By default the test cluster install is version 1.7.2, this can be changed by setting the ES_VERSION enviroment variable.

Install and Start the Cluster:

rake elasticsearch:install elasticsearch:start

Run the tests:

rake test

Stop the Cluster:

rake elasticsearch:stop

And, to wrap all that up:

rake refresh_fixtures

Contributing

  1. Fork it ( https://github.com/rapid7/elasticsearch-drain/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

elasticsearch-drain's People

Contributors

athompson-r7 avatar eheaney-r7 avatar dgreene-r7 avatar devkmsg avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.