Browse files

Revert "Resolve non-IP hosts to an IP immediately rather than incur a…

… DNS lookup for each socket send"

This reverts commit 8bcb43d addressing issue #5.

Thanks @ktheory for pointing out it's both incorrect & unnecessary!

Conflicts:

	lib/statsd.rb
	spec/statsd_spec.rb
  • Loading branch information...
1 parent 2cc97db commit d4084a846f05d07e29f0c0d7062b89db48271401 @jeremy committed Dec 19, 2011
Showing with 8 additions and 22 deletions.
  1. +2 −14 lib/statsd.rb
  2. +6 −8 spec/statsd_spec.rb
View
16 lib/statsd.rb
@@ -17,8 +17,7 @@ class Statsd
attr_reader :namespace
# StatsD host. Defaults to 127.0.0.1.
- # Setting a hostname resolves to an IP address to avoid excess DNS lookups.
- attr_reader :host
+ attr_accessor :host
# StatsD port. Defaults to 8125.
attr_accessor :port
@@ -48,19 +47,8 @@ def namespace=(namespace) #:nodoc:
@prefix = "#{namespace}."
end
- # If the argument is a hostname, resolve it to an IP address.
def host=(host) #:nodoc:
- if host
- require 'ipaddr'
- begin
- @host = IPAddr.new(host).to_s
- rescue ArgumentError
- require 'resolv'
- @host = Resolv.getaddress(host)
- end
- else
- @host = '127.0.0.1'
- end
+ @host = host || '127.0.0.1'
end
def port=(port) #:nodoc:
View
14 spec/statsd_spec.rb
@@ -7,15 +7,15 @@ class Statsd
end
before do
- @statsd = Statsd.new('1.2.3.4', 1234)
+ @statsd = Statsd.new('localhost', 1234)
@statsd.socket = FakeUDPSocket.new
end
after { @statsd.socket.clear }
describe "#initialize" do
it "should set the host and port" do
- @statsd.host.must_equal '1.2.3.4'
+ @statsd.host.must_equal 'localhost'
@statsd.port.must_equal 1234
end
@@ -27,18 +27,16 @@ class Statsd
end
describe "#host and #port" do
- before { require 'resolv'; def Resolv.getaddress(host) '127.0.0.1' end }
-
it "should set host and port" do
- @statsd.host = '5.6.7.8'
+ @statsd.host = '1.2.3.4'
@statsd.port = 5678
- @statsd.host.must_equal '5.6.7.8'
+ @statsd.host.must_equal '1.2.3.4'
@statsd.port.must_equal 5678
end
- it "should resolve hostnames to IPs" do
+ it "should not resolve hostnames to IPs" do
@statsd.host = 'localhost'
- @statsd.host.must_equal '127.0.0.1'
+ @statsd.host.must_equal 'localhost'
end
it "should set nil host to default" do

0 comments on commit d4084a8

Please sign in to comment.