thanos-io/thanos · error

parsing config YAML file

Error message

parsing config YAML file

What it means

NewIndexCache parses the user-supplied YAML configuration for the index cache into IndexCacheConfig using yaml.UnmarshalStrict. This error wraps any YAML syntax error or unknown/invalid field, because strict unmarshaling rejects fields not defined on IndexCacheConfig. It means the configuration content itself could not be decoded into the expected struct.

Solutions

  1. Validate the YAML syntax (e.g. with yamllint or a YAML parser) and fix indentation/typos.
  2. Compare the config against the IndexCacheConfig schema for the installed Thanos version and remove unknown fields.
  3. Ensure backend-specific options are nested under the correct field for the configured cache type.
  4. Check the Thanos changelog for renamed index cache config fields between versions.

Example fix

// before
index-cache:
  type: in-memory
  maxsize: 500000
// after
index-cache:
  type: in-memory
  config:
    max_size: 500000
Defensive patterns

Strategy: validation

Validate before calling

// Go: validate YAML before calling NewIndexCache
var probe map[string]interface{}
if err := yaml.UnmarshalStrict(confContentYaml, &probe); err != nil {
	return fmt.Errorf("invalid index cache config: %w", err)
}
if _, ok := probe["type"]; !ok {
	return errors.New("index cache config missing 'type'")
}

Try / catch

if _, err := storecache.NewIndexCache(logger, confYaml, reg); err != nil {
	if strings.Contains(err.Error(), "parsing config YAML file") {
		logger.Error("fix index-cache YAML", "err", err)
		os.Exit(1)
	}
	return err
}

Prevention

When it happens

Trigger: Calling NewIndexCache(logger, confContentYaml, reg) where confContentYaml contains invalid YAML syntax, or contains fields that do not exist on IndexCacheConfig (e.g. a typo like 'maxsize' instead of 'max_size', or backend-specific keys placed at the top level instead of nested under the backend's config field).

Common situations: Misindented cache config blocks in thanos.yml; renaming/retyping config fields after a Thanos version upgrade; pasting an in-memory cache block where a memcached one is expected; leftover deprecated fields like 'host'/'addresses' in the wrong nesting level.

Related errors


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

Appendix: source

Thrown at pkg/store/cache/factory.go:46

// IndexCacheConfig specifies the index cache config.
type IndexCacheConfig struct {
	Type   IndexCacheProvider `yaml:"type"`
	Config any                `yaml:"config"`

	// Available item types are Postings, Series and ExpandedPostings.
	EnabledItems []string `yaml:"enabled_items"`
	// TTL for storing items in remote cache. Not supported for inmemory cache.
	// Default value is 24h.
	TTL time.Duration `yaml:"ttl"`
}

// NewIndexCache initializes and returns new index cache.
func NewIndexCache(logger log.Logger, confContentYaml []byte, reg prometheus.Registerer) (IndexCache, error) {
	level.Info(logger).Log("msg", "loading index cache configuration")
	cacheConfig := &IndexCacheConfig{}
	cacheMetrics := NewCommonMetrics(reg)
	if err := yaml.UnmarshalStrict(confContentYaml, cacheConfig); err != nil {
		return nil, errors.Wrap(err, "parsing config YAML file")
	}

	backendConfig, err := yaml.Marshal(cacheConfig.Config)
	if err != nil {
		return nil, errors.Wrap(err, "marshal content of cache backend configuration")
	}

	if cacheConfig.TTL == 0 {
		cacheConfig.TTL = memcachedDefaultTTL
	}

	var cache IndexCache
	switch strings.ToUpper(string(cacheConfig.Type)) {
	case string(INMEMORY):
		cache, err = NewInMemoryIndexCache(logger, cacheMetrics, reg, backendConfig)
	case string(MEMCACHED):
		var memcached cacheutil.RemoteCacheClient
		memcached, err = cacheutil.NewMemcachedClient(logger, "index-cache", backendConfig, reg)

View on GitHub (pinned to 35b8b99117)