thanos-io/thanos · error

create index cache

Error message

create %s index cache

What it means

Once the concrete index cache backend is constructed, any error from that construction (memcached/redis client creation, in-memory size validation, remote index cache init) is wrapped with 'create %s index cache' naming the chosen type. It identifies which backend failed during its own setup, not which specific sub-error occurred.

Solutions

  1. Read the wrapped cause below this message to find the backend-specific failure.
  2. Fix the backend config block (addresses, timeouts, sizes) for the cache type named in the message.
  3. For in-memory, ensure config.max_item_size <= config.max_size.
  4. Verify connectivity to remote cache endpoints (DNS, ports, auth).

Example fix

// before
index-cache:
  type: memcached
  config:
    addresses: "memcached:11211"
// after
index-cache:
  type: memcached
  config:
    addresses: ["memcached:11211"]
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate backend config block shape before init
var cfg struct {
	Type   string                 `yaml:"type"`
	Config map[string]interface{} `yaml:"config"`
}
if err := yaml.Unmarshal(confYaml, &cfg); err != nil { return err }
if cfg.Type == "memcached" {
	if v, ok := cfg.Config["addresses"]; ok {
		if _, ok := v.([]interface{}); !ok {
			return errors.New("memcached addresses must be a list")
		}
	}
}

Try / catch

if _, err := storecache.NewIndexCache(logger, confYaml, reg); err != nil {
	if strings.Contains(err.Error(), "index cache") {
		logger.Error("cache backend init failed", "err", err) // unwrap cause for backend-specific fix
	}
	return err
}

Prevention

When it happens

Trigger: Calling NewIndexCache with a valid type but failing backend config, e.g. memcached with unparseable addresses, redis with a bad address/timeout value, or in-memory config where max_item_size > max_size.

Common situations: Redis/memcached endpoint typos; invalid duration or size strings in backend config; in-memory cache sized incorrectly; network-unreachable addresses passed but only detected lazily.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


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

Appendix: source

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

	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)
		if err == nil {
			cache, err = NewRemoteIndexCache(logger, memcached, cacheMetrics, reg, cacheConfig.TTL)
		}
	case string(REDIS):
		var redisCache cacheutil.RemoteCacheClient
		redisCache, err = cacheutil.NewRedisClient(logger, "index-cache", backendConfig, reg)
		if err == nil {
			cache, err = NewRemoteIndexCache(logger, redisCache, cacheMetrics, reg, cacheConfig.TTL)
		}
	default:
		return nil, errors.Errorf("index cache with type %s is not supported", cacheConfig.Type)
	}
	if err != nil {
		return nil, errors.Wrap(err, fmt.Sprintf("create %s index cache", cacheConfig.Type))
	}

	cache = NewTracingIndexCache(string(cacheConfig.Type), cache)
	if len(cacheConfig.EnabledItems) > 0 {
		if err = ValidateEnabledItems(cacheConfig.EnabledItems); err != nil {
			return nil, err
		}
		cache = NewFilteredIndexCache(cache, cacheConfig.EnabledItems)
	}

	return cache, nil
}

View on GitHub (pinned to 35b8b99117)