fluent/fluentd · error · Fluent::ConfigError

exclude#{i} does not contain 2 parameters

Error message

exclude#{i} does not contain 2 parameters

What it means

The exclude counterpart of the regexpN check: each excludeN directive must be 'key pattern'. After split(/ /, 2), a missing pattern leaves the exclude variable nil and configure raises Fluent::ConfigError.

Source

Thrown at lib/fluent/plugin/filter_grep.rb:107

      super

      regexp_and_conditions = {}
      regexp_or_conditions = {}
      exclude_and_conditions = {}
      exclude_or_conditions = {}

      (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 regexp_and_conditions[key]
        regexp_and_conditions[key] = Expression.new(record_accessor_create(key), Regexp.compile(regexp))
      end

      (1..REGEXP_MAX_NUM).each do |i|
        next unless conf["exclude#{i}"]
        key, exclude = conf["exclude#{i}"].split(/ /, 2)
        raise Fluent::ConfigError, "exclude#{i} does not contain 2 parameters" unless exclude
        raise Fluent::ConfigError, "exclude#{i} contains a duplicated key, #{key}" if exclude_or_conditions[key]
        exclude_or_conditions[key] = Expression.new(record_accessor_create(key), Regexp.compile(exclude))
      end

      if @regexps.size > 1
        log.info "Top level multiple <regexp> is interpreted as 'and' condition"
      end
      @regexps.each do |e|
        raise Fluent::ConfigError, "Duplicate key: #{e.key}" if regexp_and_conditions.key?(e.key)
        regexp_and_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)
      end

      if @excludes.size > 1
        log.info "Top level multiple <exclude> is interpreted as 'or' condition"
      end
      @excludes.each do |e|
        raise Fluent::ConfigError, "Duplicate key: #{e.key}" if exclude_or_conditions.key?(e.key)
        exclude_or_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)

View on GitHub (pinned to dd45c6e18d)

Solutions

  1. Provide both tokens: exclude1 hostname ^web-
  2. Prefer the modern section: <exclude> key hostname pattern /^web-/ </exclude>
  3. Run fluentd --dry-run -c fluent.conf before deploying
  4. Double-check erb/YAML templates that generate excludeN lines

Example fix

# before
<filter app.**>
  @type grep
  exclude1 hostname
</filter>

# after
<filter app.**>
  @type grep
  <exclude>
    key hostname
    pattern /^web-/
  </exclude>
</filter>
Defensive patterns

Strategy: validation

Validate before calling

(1..20).each do |i|
  next unless (v = conf["exclude#{i}"])
  abort "exclude#{i} must be '<key> <pattern>': got '#{v}'" unless v.include?(' ')
end
# or: system('fluentd --dry-run -c /etc/fluent/fluent.conf')

Try / catch

begin
  Fluent::Plugin::GrepFilter.new.configure(conf)
rescue Fluent::ConfigError => e
  abort "grep exclude syntax rejected: #{e.message}" # names the excludeN index at fault
end

Prevention

When it happens

Trigger: A line like exclude1 hostname with no pattern after the field name, or templating that emits only the key half of the directive.

Common situations: Hand-edited configs where the pattern was accidentally deleted; deprecated v0.12 syntax kept during an upgrade with a truncated line; environment-variable interpolation producing an empty pattern.

Understand the failure class

Background: Config validation failed: what "invalid value for {key}" and settings-rejection errors mean across 19 open-source libraries — this error's family across 19 libraries.

Related errors


AI-assisted analysis of fluent/fluentd@dd45c6e18d (2026-08-21). Data as JSON: /api/errors/517d16f1ed14317d. Report an issue: GitHub.