thanos-io/thanos · error

error matching tenant pattern

Error message

error matching tenant pattern %s (tenant %s): %w

What it means

This error wraps a filepath.Match failure that occurs while testing a tenant name against a glob-style tenant matcher in the receive hashring configuration. filepath.Match only fails when the pattern itself is malformed (e.g. unterminated '[' or unclosed escape), so this error indicates a bad glob pattern in the tenant matcher config, not a matching miss.

Solutions

  1. Check the wrapped error from filepath.Match to find the offending pattern and the byte offset of the syntax problem
  2. Fix the glob syntax in the tenant matcher config (balance brackets, avoid dangling escapes)
  3. If the intent was a literal tenant name, use TenantMatcherTypeExact instead of a glob matcher
  4. Add validation of tenant patterns at config-load time (filepath.Match against a sentinel string) to fail fast

Example fix

// before
tenants:
  - '[abc'
// after
tenants:
  - '[abc]'   # or use exact matching for literal names
matcher: glob
Defensive patterns

Strategy: validation

Validate before calling

func validGlob(p string) bool {
    _, err := filepath.Match(p, "__probe__")
    return err == nil
}
for _, pat := range tenantPatterns {
    if !validGlob(pat) { return fmt.Errorf("invalid tenant glob: %s", pat) }
}

Try / catch

if _, err := filepath.Match(pattern, tenant); err != nil {
    return false, fmt.Errorf("bad tenant pattern %q: %w", pattern, err)
}

Prevention

When it happens

Trigger: A hashring is configured with tenants using a glob matcher (TenantMatcherGlob) whose pattern string is a syntactically invalid glob, e.g. '[abc' or 'tenant[*'. The malformed pattern is hit while iterating tenant matchers in multiHashring/matchTenant.

Common situations: Hand-edited hashring YAML with typos in tenant patterns; dynamically generated patterns from template expansion that produced unbalanced brackets; copying shell-style globs that filepath.Match rejects.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/70cb3e6585221acf. Report an issue: GitHub.

Appendix: source

Thrown at pkg/receive/hashring.go:264

	}

	endpointIndex := c.sections[i].replicas[n]
	return c.endpoints[endpointIndex], nil
}

type tenantSet map[string]tenantMatcher

func (t tenantSet) match(tenant string) (bool, error) {
	// Fast path for the common case of direct match.
	if mt, ok := t[tenant]; ok && isExactMatcher(mt) {
		return true, nil
	} else {
		for tenantPattern, matcherType := range t {
			switch matcherType {
			case TenantMatcherGlob:
				matches, err := filepath.Match(tenantPattern, tenant)
				if err != nil {
					return false, fmt.Errorf("error matching tenant pattern %s (tenant %s): %w", tenantPattern, tenant, err)
				}
				if matches {
					return true, nil
				}
			case TenantMatcherTypeExact:
				// Already checked above, skipping.
				fallthrough
			default:
				continue
			}

		}
	}
	return false, nil
}

// multiHashring represents a set of hashrings.
// Which hashring to use for a tenant is determined

View on GitHub (pinned to 35b8b99117)