apache/hadoop · error · MetricsException

Illegal tag pattern: {}

Error message

Illegal tag pattern: {}

What it means

AbstractPatternFilter (base of RegexFilter and GlobFilter in metrics2) parses each include.tags entry as 'tagname:pattern' against the RE2J regex ^(\w+):(.*) during init(). Entries for included tags that lack the colon separator, or whose tag name is not a bare word ([A-Za-z0-9_]+), throw MetricsException('Illegal tag pattern: ...') and abort metrics system startup. The same format rule applies to exclude.tags.

Source

Thrown at hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/filter/AbstractPatternFilter.java:69

    excludeTagPatterns = Maps.newHashMap();
  }

  @Override
  public void init(SubsetConfiguration conf) {
    String patternString = conf.getString(INCLUDE_KEY);
    if (patternString != null && !patternString.isEmpty()) {
      setIncludePattern(compile(patternString));
    }
    patternString = conf.getString(EXCLUDE_KEY);
    if (patternString != null && !patternString.isEmpty()) {
      setExcludePattern(compile(patternString));
    }
    String[] patternStrings = conf.getStringArray(INCLUDE_TAGS_KEY);
    if (patternStrings != null && patternStrings.length != 0) {
      for (String pstr : patternStrings) {
        Matcher matcher = tagPattern.matcher(pstr);
        if (!matcher.matches()) {
          throw new MetricsException("Illegal tag pattern: "+ pstr);
        }
        setIncludeTagPattern(matcher.group(1), compile(matcher.group(2)));
      }
    }
    patternStrings = conf.getStringArray(EXCLUDE_TAGS_KEY);
    if (patternStrings != null && patternStrings.length != 0) {
      for (String pstr : patternStrings) {
        Matcher matcher = tagPattern.matcher(pstr);
        if (!matcher.matches()) {
          throw new MetricsException("Illegal tag pattern: "+ pstr);
        }
        setExcludeTagPattern(matcher.group(1), compile(matcher.group(2)));
      }
    }
  }

  void setIncludePattern(Pattern includePattern) {
    this.includePattern = includePattern;

View on GitHub (pinned to 2add963021)

Solutions

  1. Format each entry as tagname:pattern, e.g. include.tags=recordType:.* or context:dfs.
  2. Restrict the tag name to word characters; put any punctuation into the pattern half after the colon.
  3. Validate every entry compiles under RE2J semantics (no backreferences/lookaround) — compile() failures are a separate but adjacent trap.

Example fix

# before
*.filter.foo.include.tags=MyTag

# after
*.filter.foo.include.tags=MyTag:.*
Defensive patterns

Strategy: validation

Validate before calling

// Pre-flight check for include.tags entries before daemon restart
private static final java.util.regex.Pattern TAG = java.util.regex.Pattern.compile("^(\\w+):(.*)");
for (String e : conf.getStringArray("include.tags")) {
  if (!TAG.matcher(e).matches()) {
    throw new IllegalArgumentException("Bad include.tags entry (need tag:pattern): " + e);
  }
  com.google.re2j.Pattern.compile(TAG.matcher(e).group(2)); // RE2J compileability
}

Prevention

When it happens

Trigger: hadoop-metrics2.properties sets *.filter.<name>.include.tags=MyTag (no colon); tag name containing dots/dashes (context.name:pattern); a bare regex like '.*' pasted where a tag entry belongs.

Common situations: Writing metrics filter configs by hand from the Hadoop metrics2 docs; migrating a filter block and forgetting the tag prefix; using metric-name patterns where tag patterns are expected.

Related errors


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/24530258a6df9cd9. Report an issue: GitHub.