Skip to content

Commit

Permalink
Add specs for caching on timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewvc committed Mar 9, 2018
1 parent 2a7ec1f commit 2d6228a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/logstash/filters/dns.rb
Expand Up @@ -69,6 +69,9 @@ class LogStash::Filters::DNS < LogStash::Filters::Base
# Use custom hosts file(s). For example: `["/var/db/my_custom_hosts"]`
config :hostsfile, :validate => :array

attr_reader :hit_cache
attr_reader :failed_cache

public
def register
if @nameserver.nil? && @hostsfile.nil?
Expand All @@ -90,7 +93,6 @@ def register

public
def filter(event)

if @resolve
return if resolve(event).nil?
end
Expand Down
11 changes: 9 additions & 2 deletions spec/filters/dns_spec.rb
Expand Up @@ -322,10 +322,11 @@

describe "retries" do

let(:host) { "unknownhost" }
let(:subject) { LogStash::Filters::DNS.new(config) }
let(:event) { LogStash::Event.new("message" => "unkownhost") }
let(:event) { LogStash::Event.new("message" => host) }
let(:max_retries) { 3 }
let(:config) { { "resolve" => ["message"], "max_retries" => max_retries } }
let(:config) { { "resolve" => ["message"], "max_retries" => max_retries, "failed_cache_size" => 10 } }

before(:each) { subject.register }

Expand All @@ -338,6 +339,12 @@
expect(subject).to receive(:getaddress).exactly(max_retries+1).times
subject.filter(event)
end

it "should cache the timeout" do
expect do
subject.filter(event)
end.to change { subject.failed_cache[host] }.from(nil).to(true)
end
end

context "when failing temporarily" do
Expand Down

0 comments on commit 2d6228a

Please sign in to comment.