thanos-io/thanos · error
marshal content of cache backend configuration
Error message
marshal content of cache backend configuration
What it means
After extracting the generic cache backend blob, NewCacheConfig re-marshals cacheConfig.Config to YAML for backend-specific unmarshaling. Failure to re-marshal indicates the parsed raw config cannot be serialized, wrapped as 'marshal content of cache backend configuration'.
Solutions
- Ensure cacheConfig.Config holds a map or yaml-supported value; check the input YAML 'config' section is a mapping, not a scalar or list.
- Verify the Thanos version; older versions had limited Config types — upgrade if using a new backend.
- If constructing config in Go, populate Config with a yaml.Marshal-encodable type (map[string]interface{}).
Example fix
# before (config must be a mapping) type: REDIS config: redis://localhost # after type: REDIS config: endpoints: [localhost:6379]
Defensive patterns
Strategy: validation
Validate before calling
var p struct {
Type string `yaml:"type"`
Config interface{} `yaml:"config"`
}
if err := yaml.UnmarshalStrict(data, &p); err != nil { return err }
if _, ok := p.Config.(map[interface{}]interface{}); !ok {
return fmt.Errorf("cache config section must be a mapping")
} Try / catch
cfg, err := queryfrontend.NewCacheConfig(logger, yamlBytes)
if err != nil {
if strings.Contains(err.Error(), "marshal content of cache backend configuration") {
return fmt.Errorf("cache backend 'config' section must be a YAML mapping: %w", err)
}
return err
} Prevention
- Always write the backend config as a YAML mapping under 'config:'.
- Test cache config parsing at startup, not at first request.
- Avoid programmatic configs with non-encodable values.
When it happens
Trigger: yaml.Marshal(cacheConfig.Config) fails after a successful strict unmarshal of the provider config — typically a nil or yaml-incompatible value in the Config field.
Common situations: Custom or programmatically built cache provider configs holding types yaml.Marshal cannot encode; rarely hit via plain YAML files, more common when constructing config in code or tests.
Related errors
- parsing config YAML file
- initializing the query range cache config
- initializing the labels cache config
- response cache with type
- invalid ResultsCache config for labels tripperware
AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07).
Data as JSON: /api/errors/d4b1ca1299fcc11e.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/queryfrontend/config.go:97
}
// CacheProviderConfig is the initial CacheProviderConfig struct holder before parsing it into a specific cache provider.
// Based on the config type the config is then parsed into a specific cache provider.
type CacheProviderConfig struct {
Type ResponseCacheProvider `yaml:"type"`
Config any `yaml:"config"`
}
// NewCacheConfig is a parser that converts a Thanos cache config yaml into a cortex cache config struct.
func NewCacheConfig(logger log.Logger, confContentYaml []byte) (*cortexcache.Config, error) {
cacheConfig := &CacheProviderConfig{}
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")
}
switch strings.ToUpper(string(cacheConfig.Type)) {
case string(INMEMORY):
var config InMemoryResponseCacheConfig
if err := yaml.Unmarshal(backendConfig, &config); err != nil {
return nil, err
}
return &cortexcache.Config{
EnableFifoCache: true,
Fifocache: cortexcache.FifoCacheConfig{
MaxSizeBytes: config.MaxSize,
MaxSizeItems: config.MaxSizeItems,
Validity: config.Validity,
},
}, nil
case string(MEMCACHED):View on GitHub (pinned to 35b8b99117)