Support setting multiple URLS in the configuration #175

Closed
wants to merge 3 commits into
from

Conversation

Projects
None yet
5 participants

cover commented Dec 17, 2011

Currently Tire supports just one ElasticSearch url, it would be useful to support more and let it randomly use one of the available urls on requests (some kind of failover would be nice too, maybe next)

Owner

karmi commented Dec 17, 2011

Hi Fabio, thanks for the patch, I'll have a look at it in the light of proposed changes at karmi/tire#162.

cover commented Dec 17, 2011

Hi Karmi, damn, I didn't see that one, I'm reading it right now :)

cover commented Dec 17, 2011

After reading it I've changed something, now it's possible to do
Tire.configuration { url 'http://es1.example.com', 'http://es2.example.com' }

I kept the sample/choice in order to return one random url from the ones available and not breaking anything, at least until there will be the round-robin support.

cover commented Dec 17, 2011

...and...

Tire.configuration { url ['http://es1.example.com', 'http://es2.example.com'] }

which could be more realistic with something like:

elasticsearch = YAML::load( File.open( Rails.root.join('config', 'elasticsearch.yml') ) )
Tire.configuration { url elasticsearch[Rails.env][:hosts] }

Owner

karmi commented Mar 19, 2012

@karmi @vhyza Bump!

hopefully this gets merge into master soon

nvdk commented Jun 14, 2012

just wanted to add my interest for this option here :)

krae commented Jun 18, 2012

Yah, same. Are you still looking at this?

@karmi karmi commented on the diff Oct 23, 2012

lib/tire/configuration.rb
@@ -2,8 +2,14 @@ module Tire
class Configuration
- def self.url(value=nil)
- @url = (value ? value.to_s.gsub(%r|/*$|, '') : nil) || @url || "http://localhost:9200"
+ def self.urls
+ @urls || ["http://localhost:9200"]
+ end
+
+ def self.url(*values)
+ values.flatten!
+ @urls = values.map{|value| value.to_s.gsub(%r|/*$|, '')} if values.any?
+ urls.respond_to?(:sample) ? urls.sample : urls.choice
@karmi

karmi Oct 23, 2012

Owner

Hey, I'm a bit uncertain how this would work with the HTTP clients. The methods accepts an array, sets the @urls, and the returns a random item from the array, correct?

I think we need much more robust implementation, as outlined in #162.

What I like about the implementation is that everybody can simply stick this:

module Tire
  class Configuration

    def self.url(*values)
      values.flatten!
      @urls = values.map{|value| value.to_s.gsub(%r|/*$|, '')} if values.any?
      urls.respond_to?(:sample) ? urls.sample : urls.choice
    end

  end
end

into their lib and they get the behaviour. I'm leaning towards closing this and focusing on the more robust implementation with round robin pooling, graceful handling of failed IPs, auto-discovery of cluster nodes a la the Perl client, etc. What do you think?

Owner

karmi commented Oct 26, 2012

Closing in favour of a more complete implementation.

karmi closed this Oct 26, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment