Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support and/or section #1897

Merged
merged 15 commits into from
Apr 5, 2018
Merged

Support and/or section #1897

merged 15 commits into from
Apr 5, 2018

Conversation

okkez
Copy link
Contributor

@okkez okkez commented Mar 15, 2018

For example:

<filter>
  @type grep
  <and>
    <regexp>
      key level
      pattern ^WARN|ERROR$
    </regexp>
    <regexp>
      key method
      pattern ^GET$
    </regexp>
  </and>
</filter>

For more details, see test code

See #1858

end

attr_reader :_regexp_and_conditions, :_exluce_and_conditions, :_regexp_or_conditions, :_exclude_or_conditions

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small spelling mistake: _exluce_and_conditions -> _exclude_and_conditions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I've fixed.

okkez added 3 commits March 16, 2018 17:02
:_exluce_and_conditions ->
:_exclude_and_conditions
@@ -122,5 +201,18 @@ def filter(tag, time, record)
end
result
end

class Expression
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using Struct for it?

Expression = Struct.new(:key, :pattern) do
  def match?(record)
    ::Fluent::StringUtil.match_regexp(pattern, key.call(record).to_s)
  end
end

end
end

def filter(tag, time, record)
result = nil
begin
catch(:break_loop) do
@_regexps.each do |key, regexp|
throw :break_loop unless ::Fluent::StringUtil.match_regexp(regexp, key.call(record).to_s)
@_regexp_and_conditions.each do |key, expression|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very small optimization but how about using array for conditions?
In filter, we don't use key and hash related operations so array is good structure.

(1..REGEXP_MAX_NUM).each do |i|
next unless conf["regexp#{i}"]
key, regexp = conf["regexp#{i}"].split(/ /, 2)
raise Fluent::ConfigError, "regexp#{i} does not contain 2 parameters" unless regexp
raise Fluent::ConfigError, "regexp#{i} contains a duplicated key, #{key}" if rs[key]
rs[key] = Regexp.compile(regexp)
raise Fluent::ConfigError, "regexp#{i} contains a duplicated key, #{key}" if @_regexp_and_conditions[key]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about logging info or warning message for top level setting?
Top level multiple <regexp> is intepreted as 'and' condition.

okkez added 3 commits March 20, 2018 11:41
Because it is unclear how interpret for top level <regexp> and <exclude>.
Because we don't use Hash key and Hash related operations.

very simple benchmark result is here:

              user     system      total        real
    new   2.427028   0.000255   2.427283 (  2.435108)
    old   2.497610   0.004182   2.501792 (  2.507315)

See also https://gist.github.com/okkez/2b33ee7a946d137478fb5a6454551dfa
@JohnStarich
Copy link

This looks great. @repeatedly can this get merged? (The failing test in Travis looks unrelated to these changes)

@repeatedly
Copy link
Member

Sorry for the delay. Will check it again!

config_param :key, :string
desc "The regular expression."
config_param :pattern do |value|
if value.start_with?("/") and value.end_with?("/")
Copy link
Member

@repeatedly repeatedly Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... I see lots of similar patterns. We need to :regexp type for config_param.

@okkez Could you write a patch for adding regexp type in other PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will write a patch for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #1927


def configure(conf)
super

rs = {}
_regexp_and_conditions = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name is conflicts with attr_reader's definition. Yeah, I know local variable is preferred but using other name , e.g. _regexp_and_conds, is better. Others are same.

@okkez okkez mentioned this pull request Apr 4, 2018
@repeatedly
Copy link
Member

@okkez We enabled DCO for fluentd repository. Could you re-commit last commit with -s?

Because these names conflict with attr_reader's definition.

Signed-off-by: Kenji Okimoto <okimoto@clear-code.com>
@okkez
Copy link
Contributor Author

okkez commented Apr 5, 2018

I've re-committed and pushed the last commit with -s. @repeatedly

@repeatedly repeatedly merged commit 03ce0bd into fluent:master Apr 5, 2018
@repeatedly
Copy link
Member

Thanks!

@okkez okkez deleted the support-and-or branch April 5, 2018 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants