From cdad32d34a479fa1101aa3caf64c677b9191dd86 Mon Sep 17 00:00:00 2001 From: Salva Corts Date: Tue, 5 Dec 2023 11:36:40 +0100 Subject: [PATCH] Validate config --- pkg/bloomgateway/client.go | 18 ++++++++++++++---- pkg/storage/chunk/cache/resultscache/config.go | 4 ++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/bloomgateway/client.go b/pkg/bloomgateway/client.go index 9e88dedf5a51..45c7d8b9e22f 100644 --- a/pkg/bloomgateway/client.go +++ b/pkg/bloomgateway/client.go @@ -120,6 +120,20 @@ func (i *ClientConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { f.BoolVar(&i.LogGatewayRequests, prefix+"log-gateway-requests", false, "Flag to control whether requests sent to the gateway should be logged or not.") } +func (i *ClientConfig) Validate() error { + if err := i.GRPCClientConfig.Validate(); err != nil { + return errors.Wrap(err, "grpc client config") + } + + if i.CacheResults { + if err := i.Cache.Validate(); err != nil { + return errors.Wrap(err, "cache config") + } + } + + return nil +} + type Client interface { FilterChunks(ctx context.Context, tenant string, from, through model.Time, groups []*logproto.GroupedChunkRefs, filters ...*logproto.LineFilterExpression) ([]*logproto.GroupedChunkRefs, error) } @@ -156,10 +170,6 @@ func NewGatewayClient( var c cache.Cache if cfg.CacheResults { - if !cache.IsCacheConfigured(cfg.Cache.CacheConfig) { - return nil, errors.New("cache is not configured") - } - c, err = cache.New(cfg.Cache.CacheConfig, registerer, logger, stats.BloomFilterCache, constants.Loki) if err != nil { return nil, errors.Wrap(err, "new bloom gateway cache") diff --git a/pkg/storage/chunk/cache/resultscache/config.go b/pkg/storage/chunk/cache/resultscache/config.go index 54088639b831..5a329168e837 100644 --- a/pkg/storage/chunk/cache/resultscache/config.go +++ b/pkg/storage/chunk/cache/resultscache/config.go @@ -33,6 +33,10 @@ func (cfg *Config) Validate() error { return errors.Errorf("unsupported compression type: %s", cfg.Compression) } + if !cache.IsCacheConfigured(cfg.CacheConfig) { + return errors.New("no cache configured") + } + return nil }