Skip to content

Commit

Permalink
Refactor: use timeout_scope as the new config name
Browse files Browse the repository at this point in the history
Fixes #153
  • Loading branch information
kares committed Nov 18, 2019
1 parent 3c5e4c5 commit 8fcb5f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 7 additions & 6 deletions lib/logstash/filters/grok.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,12 @@ class LogStash::Filters::Grok < LogStash::Filters::Base
# Set to 0 to disable timeouts
config :timeout_millis, :validate => :number, :default => 30000

# Group timeout for multiple patterns instead of having a timeout per pattern.
# When set to true timeout_millis effectively becomes a timeout over several patterns.
# Timeouts are per pattern matched by default but for multiple matches over a
# particular field it's usually better to scope the timeout for the whole event.
# The `timeout_millis` than effectively becomes a timeout over several matches.
# Default is false due backwards compatibility.
# Has only an effect when timeout_millis > 0
config :timeout_grouped, :validate => :boolean, :default => false
config :timeout_scope, :validate => %w(pattern event), :default => "pattern"

# Tag to apply if a grok regexp times out.
config :tag_on_timeout, :validate => :string, :default => '_groktimeout'
Expand Down Expand Up @@ -289,7 +290,7 @@ def register
@failure_counter = metric.counter(:failures)

@timeout = @timeout_millis > 0.0 ? RubyTimeout.new(@timeout_millis) : NoopTimeout.new
@matcher = @timeout_grouped ? GlobalMatcher.new(self) : DefaultMatcher.new(self)
@matcher = ( @timeout_scope.eql?('event') ? EventTimeoutMatcher : PatternTimeoutMatcher ).new(self)
end # def register

def filter(event)
Expand Down Expand Up @@ -380,15 +381,15 @@ def execute(context, grok)
end

# @private
class GlobalMatcher < Matcher
class EventTimeoutMatcher < Matcher
# @override
def match(context, groks, event, break_on_match)
@filter.with_timeout(context) { super }
end
end

# @private
class DefaultMatcher < Matcher
class PatternTimeoutMatcher < Matcher
# @override
def execute(context, grok)
@filter.with_timeout(context) { super }
Expand Down
4 changes: 2 additions & 2 deletions spec/filters/grok_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def pattern_path(path)
]
}
timeout_millis => 500
timeout_grouped => false
timeout_scope => 'pattern'
}
}
CONFIG
Expand All @@ -459,7 +459,7 @@ def pattern_path(path)
]
}
timeout_millis => 500
timeout_grouped => true
timeout_scope => 'event'
}
}
CONFIG
Expand Down

0 comments on commit 8fcb5f8

Please sign in to comment.