Skip to content

Commit 68603f1

Browse files
sandeepsukhanigouthamve
authored andcommitted
added interfaces for store specific limits (#1602)
* added interfaces for store spceific limits NewStore method in pkg/storage uses Overrides type defined in Cortex itself. Added an interface to let consumers of that method pass any type which implements required methods This is done as part of way to let projects using Cortex, define their own limits Signed-off-by: Sandeep Sukhani <[email protected]> * renamed interface CompositeStoreLimits to StoreLimits Signed-off-by: Sandeep Sukhani <[email protected]>
1 parent 373cefb commit 68603f1

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

pkg/chunk/chunk_store.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ type store struct {
7878
index IndexClient
7979
chunks ObjectClient
8080
schema Schema
81-
limits *validation.Overrides
81+
limits StoreLimits
8282
*Fetcher
8383
}
8484

85-
func newStore(cfg StoreConfig, schema Schema, index IndexClient, chunks ObjectClient, limits *validation.Overrides) (Store, error) {
85+
func newStore(cfg StoreConfig, schema Schema, index IndexClient, chunks ObjectClient, limits StoreLimits) (Store, error) {
8686
fetcher, err := NewChunkFetcher(cfg.ChunkCacheConfig, cfg.chunkCacheStubs, chunks)
8787
if err != nil {
8888
return nil, err

pkg/chunk/composite_store.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ package chunk
33
import (
44
"context"
55
"sort"
6+
"time"
67

78
"github.com/prometheus/common/model"
89
"github.com/prometheus/prometheus/pkg/labels"
9-
10-
"github.com/cortexproject/cortex/pkg/util/validation"
1110
)
1211

12+
// StoreLimits helps get Limits specific to Queries for Stores
13+
type StoreLimits interface {
14+
MaxChunksPerQuery(userID string) int
15+
MaxQueryLength(userID string) time.Duration
16+
}
17+
1318
// Store for chunks.
1419
type Store interface {
1520
Put(ctx context.Context, chunks []Chunk) error
@@ -45,7 +50,7 @@ func NewCompositeStore() CompositeStore {
4550
}
4651

4752
// AddPeriod adds the configuration for a period of time to the CompositeStore
48-
func (c *CompositeStore) AddPeriod(storeCfg StoreConfig, cfg PeriodConfig, index IndexClient, chunks ObjectClient, limits *validation.Overrides) error {
53+
func (c *CompositeStore) AddPeriod(storeCfg StoreConfig, cfg PeriodConfig, index IndexClient, chunks ObjectClient, limits StoreLimits) error {
4954
schema := cfg.CreateSchema()
5055
var store Store
5156
var err error

pkg/chunk/series_store.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"github.com/cortexproject/cortex/pkg/chunk/cache"
1717
"github.com/cortexproject/cortex/pkg/util"
1818
"github.com/cortexproject/cortex/pkg/util/spanlogger"
19-
"github.com/cortexproject/cortex/pkg/util/validation"
2019
)
2120

2221
// CardinalityExceededError is returned when the user reads a row that
@@ -67,7 +66,7 @@ type seriesStore struct {
6766
writeDedupeCache cache.Cache
6867
}
6968

70-
func newSeriesStore(cfg StoreConfig, schema Schema, index IndexClient, chunks ObjectClient, limits *validation.Overrides) (Store, error) {
69+
func newSeriesStore(cfg StoreConfig, schema Schema, index IndexClient, chunks ObjectClient, limits StoreLimits) (Store, error) {
7170
fetcher, err := NewChunkFetcher(cfg.ChunkCacheConfig, cfg.chunkCacheStubs, chunks)
7271
if err != nil {
7372
return nil, err

pkg/chunk/storage/caching_index_client.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
chunk_util "github.com/cortexproject/cortex/pkg/chunk/util"
1717
"github.com/cortexproject/cortex/pkg/util"
1818
"github.com/cortexproject/cortex/pkg/util/spanlogger"
19-
"github.com/cortexproject/cortex/pkg/util/validation"
2019
)
2120

2221
var (
@@ -46,10 +45,10 @@ type cachingIndexClient struct {
4645
chunk.IndexClient
4746
cache cache.Cache
4847
validity time.Duration
49-
limits *validation.Overrides
48+
limits StoreLimits
5049
}
5150

52-
func newCachingIndexClient(client chunk.IndexClient, c cache.Cache, validity time.Duration, limits *validation.Overrides) chunk.IndexClient {
51+
func newCachingIndexClient(client chunk.IndexClient, c cache.Cache, validity time.Duration, limits StoreLimits) chunk.IndexClient {
5352
if c == nil {
5453
return client
5554
}

pkg/chunk/storage/factory.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ import (
1414
"github.com/cortexproject/cortex/pkg/chunk/gcp"
1515
"github.com/cortexproject/cortex/pkg/chunk/local"
1616
"github.com/cortexproject/cortex/pkg/util"
17-
"github.com/cortexproject/cortex/pkg/util/validation"
1817
"github.com/go-kit/kit/log/level"
1918
"github.com/pkg/errors"
2019
)
2120

21+
// StoreLimits helps get Limits specific to Queries for Stores
22+
type StoreLimits interface {
23+
CardinalityLimit(userID string) int
24+
MaxChunksPerQuery(userID string) int
25+
MaxQueryLength(userID string) time.Duration
26+
}
27+
2228
// Config chooses which storage client to use.
2329
type Config struct {
2430
AWSStorageConfig aws.StorageConfig `yaml:"aws"`
@@ -47,7 +53,7 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
4753
}
4854

4955
// NewStore makes the storage clients based on the configuration.
50-
func NewStore(cfg Config, storeCfg chunk.StoreConfig, schemaCfg chunk.SchemaConfig, limits *validation.Overrides) (chunk.Store, error) {
56+
func NewStore(cfg Config, storeCfg chunk.StoreConfig, schemaCfg chunk.SchemaConfig, limits StoreLimits) (chunk.Store, error) {
5157
tieredCache, err := cache.New(cfg.IndexQueriesCacheConfig)
5258
if err != nil {
5359
return nil, err

0 commit comments

Comments
 (0)