Skip to content

Commit

Permalink
cache/caching_bucket: add path to hash (#7158)
Browse files Browse the repository at this point in the history
Add path to the hash. This allows identifying difference instances by
different config paths.

Signed-off-by: Giedrius Statkevičius <giedrius.statkevicius@vinted.com>
  • Loading branch information
GiedriusS authored Feb 23, 2024
1 parent 508d82e commit 75152c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/thanos/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func runStore(
r := route.New()

if len(cachingBucketConfigYaml) > 0 {
insBkt, err = storecache.NewCachingBucketFromYaml(cachingBucketConfigYaml, insBkt, logger, reg, r)
insBkt, err = storecache.NewCachingBucketFromYaml(cachingBucketConfigYaml, insBkt, logger, reg, r, conf.cachingBucketConfig.Path())
if err != nil {
return errors.Wrap(err, "create caching bucket")
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/store/cache/caching_bucket_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (cfg *CachingWithBackendConfig) Defaults() {
}

// NewCachingBucketFromYaml uses YAML configuration to create new caching bucket.
func NewCachingBucketFromYaml(yamlContent []byte, bucket objstore.Bucket, logger log.Logger, reg prometheus.Registerer, r *route.Router) (objstore.InstrumentedBucket, error) {
func NewCachingBucketFromYaml(yamlContent []byte, bucket objstore.Bucket, logger log.Logger, reg prometheus.Registerer, r *route.Router, configPath string) (objstore.InstrumentedBucket, error) {
level.Info(logger).Log("msg", "loading caching bucket configuration")

config := &CachingWithBackendConfig{}
Expand All @@ -84,7 +84,11 @@ func NewCachingBucketFromYaml(yamlContent []byte, bucket objstore.Bucket, logger
return nil, errors.Wrap(err, "parsing config YAML file")
}

cfgHash := string(fmt.Sprintf("%d", xxhash.Sum64(yamlContent)))
// Append the config path to the YAML content. This allows
// using identical config with multiple instances.
// TODO(GiedriusS): in the long-term add some kind of "name"
// identifier for each instance.
cfgHash := string(fmt.Sprintf("%d", xxhash.Sum64(append(yamlContent, []byte(configPath)...))))

backendConfig, err := yaml.Marshal(config.BackendConfig)
if err != nil {
Expand Down

0 comments on commit 75152c4

Please sign in to comment.