-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ben Ye <yb532204897@gmail.com>
- Loading branch information
Showing
10 changed files
with
169 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package cache | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/cortexproject/cortex/pkg/querier/queryrange" | ||
"github.com/pkg/errors" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type ResponseCacheProvider string | ||
|
||
// TODO: add other cache providers when available. | ||
const ( | ||
INMEMORY ResponseCacheProvider = "IN-MEMORY" | ||
) | ||
|
||
// ResponseCacheConfig specifies the response cache config. | ||
type ResponseCacheConfig struct { | ||
Type ResponseCacheProvider `yaml:"type"` | ||
Config interface{} `yaml:"config"` | ||
} | ||
|
||
func NewResponseCacheConfig(confContentYaml []byte) (*queryrange.ResultsCacheConfig, error) { | ||
cacheConfig := &ResponseCacheConfig{} | ||
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") | ||
} | ||
|
||
var resultsCacheConf *queryrange.ResultsCacheConfig | ||
switch strings.ToUpper(string(cacheConfig.Type)) { | ||
case string(INMEMORY): | ||
resultsCacheConf, err = newInMemoryResponseCacheConfig(backendConfig) | ||
default: | ||
return nil, errors.Errorf("response cache with type %s is not supported", cacheConfig.Type) | ||
} | ||
|
||
if err != nil { | ||
return nil, errors.Wrap(err, fmt.Sprintf("create %s response cache", cacheConfig.Type)) | ||
} | ||
|
||
return resultsCacheConf, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) The Thanos Authors. | ||
// Licensed under the Apache License 2.0. | ||
|
||
package cache | ||
|
||
import ( | ||
"time" | ||
|
||
cortexcache "github.com/cortexproject/cortex/pkg/chunk/cache" | ||
"github.com/cortexproject/cortex/pkg/querier/queryrange" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
type InMemoryResponseCacheConfig struct { | ||
// MaxSize represents overall maximum number of bytes cache can contain. | ||
MaxSize string `yaml:"max_size"` | ||
// MaxSizeItems represents the maximum number of entries in the cache. | ||
MaxSizeItems int `yaml:"max_size_items"` | ||
// Validity represents the expiry duration for the cache. | ||
Validity time.Duration `yaml:"validity"` | ||
} | ||
|
||
// newInMemoryResponseCacheConfig is an adapter function | ||
// to creates Cortex fifo results cache config. | ||
func newInMemoryResponseCacheConfig(conf []byte) (*queryrange.ResultsCacheConfig, error) { | ||
var config InMemoryResponseCacheConfig | ||
if err := yaml.Unmarshal(conf, &config); err != nil { | ||
return nil, err | ||
} | ||
return &queryrange.ResultsCacheConfig{ | ||
CacheConfig: cortexcache.Config{ | ||
EnableFifoCache: true, | ||
Fifocache: cortexcache.FifoCacheConfig{ | ||
MaxSizeBytes: config.MaxSize, | ||
MaxSizeItems: config.MaxSizeItems, | ||
Validity: config.Validity, | ||
}, | ||
}, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.