{"record":{"id":"b8be441216d9c767","repo":"fluent/fluentd","slug":"exclude-i-contains-a-duplicated-key-key","errorCode":null,"errorMessage":"exclude#{i} contains a duplicated key, #{key}","messagePattern":"exclude#(.+?) contains a duplicated key, #(.+?)","errorType":"validation","errorClass":"Fluent::ConfigError","httpStatus":null,"severity":"error","filePath":"lib/fluent/plugin/filter_grep.rb","lineNumber":108,"sourceCode":"\n      regexp_and_conditions = {}\n      regexp_or_conditions = {}\n      exclude_and_conditions = {}\n      exclude_or_conditions = {}\n\n      (1..REGEXP_MAX_NUM).each do |i|\n        next unless conf[\"regexp#{i}\"]\n        key, regexp = conf[\"regexp#{i}\"].split(/ /, 2)\n        raise Fluent::ConfigError, \"regexp#{i} does not contain 2 parameters\" unless regexp\n        raise Fluent::ConfigError, \"regexp#{i} contains a duplicated key, #{key}\" if regexp_and_conditions[key]\n        regexp_and_conditions[key] = Expression.new(record_accessor_create(key), Regexp.compile(regexp))\n      end\n\n      (1..REGEXP_MAX_NUM).each do |i|\n        next unless conf[\"exclude#{i}\"]\n        key, exclude = conf[\"exclude#{i}\"].split(/ /, 2)\n        raise Fluent::ConfigError, \"exclude#{i} does not contain 2 parameters\" unless exclude\n        raise Fluent::ConfigError, \"exclude#{i} contains a duplicated key, #{key}\" if exclude_or_conditions[key]\n        exclude_or_conditions[key] = Expression.new(record_accessor_create(key), Regexp.compile(exclude))\n      end\n\n      if @regexps.size > 1\n        log.info \"Top level multiple <regexp> is interpreted as 'and' condition\"\n      end\n      @regexps.each do |e|\n        raise Fluent::ConfigError, \"Duplicate key: #{e.key}\" if regexp_and_conditions.key?(e.key)\n        regexp_and_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)\n      end\n\n      if @excludes.size > 1\n        log.info \"Top level multiple <exclude> is interpreted as 'or' condition\"\n      end\n      @excludes.each do |e|\n        raise Fluent::ConfigError, \"Duplicate key: #{e.key}\" if exclude_or_conditions.key?(e.key)\n        exclude_or_conditions[e.key] = Expression.new(record_accessor_create(e.key), e.pattern)\n      end","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/fluent/fluentd/blob/dd45c6e18dc7be33b5e5a0f0767bf46307ff5626/lib/fluent/plugin/filter_grep.rb#L90-L126","documentation":"While parsing deprecated excludeN directives, configure tracks fields already used by exclude conditions (exclude_or_conditions hash). A second excludeN line naming the same key raises Fluent::ConfigError because the key is duplicated in the OR-condition set.","triggerScenarios":"Two lines such as exclude1 level debug and exclude2 level trace — the same key appears under two excludeN indices; duplicated generated lines in templated configs.","commonSituations":"Attempting 'exclude if field is X or Y' with two excludeN lines (the correct form is one combined regex or multiple <exclude> sections which are OR'ed); copy-paste of an exclude line with only the pattern changed but not the key.","solutions":["Merge into one regex: exclude1 level /(debug|trace)/","Use distinct keys if the conditions target different fields","Migrate to multiple <exclude> sections, which are already interpreted as OR conditions","Validate with fluentd --dry-run"],"exampleFix":"# before\nexclude1 level debug\nexclude2 level trace\n\n# after\n<exclude>\n  key level\n  pattern /debug|trace/\n</exclude>","handlingStrategy":"validation","validationCode":"keys = (1..20).filter_map { |i| conf[\"exclude#{i}\"]&.split(/ /, 2)&.first }\ndupes = keys.tally.select { |_, n| n > 1 }.keys\nabort \"duplicate excludeN keys: #{dupes.join(', ')}\" unless dupes.empty?","typeGuard":null,"tryCatchPattern":"begin\n  Fluent::Plugin::GrepFilter.new.configure(conf)\nrescue Fluent::ConfigError => e\n  # message contains the duplicated key; merge into /(x|y)/ and retry configure\n  raise\nend","preventionTips":["One excludeN per field; use alternation for multiple patterns","Remember excludes are OR'ed — duplicates are never needed","Dry-run in CI","Grep the filter stanza for repeated key tokens before shipping"],"tags":["fluentd","grep-filter","duplicate-key","configuration","configerror"],"backgroundTag":"duplicate-config-key","analyzedSha":"dd45c6e18dc7be33b5e5a0f0767bf46307ff5626","analyzedAt":"2026-08-21T16:22:07.332Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}