From 593e775440d7e6f2e2df7b6112a8231954677ba9 Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Wed, 8 May 2024 08:51:31 -0300 Subject: [PATCH 1/4] Make it impossible to run both new and old configs. --- pkg/loki/config_wrapper.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/pkg/loki/config_wrapper.go b/pkg/loki/config_wrapper.go index 2a4789fb9e60..ddb7a9626203 100644 --- a/pkg/loki/config_wrapper.go +++ b/pkg/loki/config_wrapper.go @@ -689,21 +689,12 @@ func applyChunkRetain(cfg, defaults *ConfigWrapper) { } func applyCommonQuerierWorkerGRPCConfig(cfg, defaults *ConfigWrapper) error { - if !reflect.DeepEqual(cfg.Worker.OldQueryFrontendGRPCClientConfig, defaults.Worker.OldQueryFrontendGRPCClientConfig) { - // User is using the old grpc configuration. - - if reflect.DeepEqual(cfg.Worker.NewQueryFrontendGRPCClientConfig, defaults.Worker.NewQueryFrontendGRPCClientConfig) { - // User is using the old grpc configuration only, we can just copy it to the new grpc client struct. - cfg.Worker.NewQueryFrontendGRPCClientConfig = cfg.Worker.OldQueryFrontendGRPCClientConfig - } else { - // User is using both, old and new way of configuring the grpc client, so we throw an error. - return fmt.Errorf("both `grpc_client_config` and `query_frontend_grpc_client` are set at the same time. Please use only one of them") - } + usingNewFrontendCfg := !reflect.DeepEqual(cfg.Worker.NewQueryFrontendGRPCClientConfig, defaults.Worker.NewQueryFrontendGRPCClientConfig) + usingNewSchedulerCfg := !reflect.DeepEqual(cfg.Worker.QuerySchedulerGRPCClientConfig, defaults.Worker.QuerySchedulerGRPCClientConfig) + usingOldFrontendCfg := !reflect.DeepEqual(cfg.Worker.OldQueryFrontendGRPCClientConfig, defaults.Worker.OldQueryFrontendGRPCClientConfig) - if reflect.DeepEqual(cfg.Worker.QuerySchedulerGRPCClientConfig, defaults.Worker.QuerySchedulerGRPCClientConfig) { - // Since the scheduler grpc client is not set, we can just copy the old query frontend grpc client to the scheduler grpc client. - cfg.Worker.QuerySchedulerGRPCClientConfig = cfg.Worker.OldQueryFrontendGRPCClientConfig - } + if usingOldFrontendCfg && (usingNewFrontendCfg || usingNewSchedulerCfg) { + return fmt.Errorf("both `grpc_client_config` and (`query_frontend_grpc_client` or `query_scheduler_grpc_client`) are set at the same time. Please use only `query_frontend_grpc_client` and `query_scheduler_grpc_client`") } return nil } From a2dd324f7bfb7d3b8b6982ead26b831dcc00f529 Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Wed, 8 May 2024 09:12:20 -0300 Subject: [PATCH 2/4] update docs --- docs/sources/shared/configuration.md | 8 ++++---- pkg/querier/worker/worker.go | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/sources/shared/configuration.md b/docs/sources/shared/configuration.md index df40267e9ae8..4d8c18130f5d 100644 --- a/docs/sources/shared/configuration.md +++ b/docs/sources/shared/configuration.md @@ -2237,19 +2237,19 @@ The `frontend_worker` configures the worker - running within the Loki querier - [id: | default = ""] # Configures the querier gRPC client used to communicate with the -# query-frontend. Shouldn't be used in conjunction with 'grpc_client_config'. +# query-frontend. Can't be used in conjunction with 'grpc_client_config'. # The CLI flags prefix for this block configuration is: # querier.frontend-grpc-client [query_frontend_grpc_client: ] # Configures the querier gRPC client used to communicate with the query-frontend -# and with the query-scheduler if 'query_scheduler_grpc_client' isn't defined. -# This shouldn't be used if 'query_frontend_grpc_client' is defined. +# and with the query-scheduler. Can't be used in conjunction with +# 'query_frontend_grpc_client' or 'query_scheduler_grpc_client'. # The CLI flags prefix for this block configuration is: querier.frontend-client [grpc_client_config: ] # Configures the querier gRPC client used to communicate with the -# query-scheduler. If not defined, 'grpc_client_config' is used instead. +# query-scheduler. Can't be used in conjunction with 'grpc_client_config'. # The CLI flags prefix for this block configuration is: # querier.scheduler-grpc-client [query_scheduler_grpc_client: ] diff --git a/pkg/querier/worker/worker.go b/pkg/querier/worker/worker.go index 7d7b46dc814f..927f487beba2 100644 --- a/pkg/querier/worker/worker.go +++ b/pkg/querier/worker/worker.go @@ -30,10 +30,10 @@ type Config struct { QuerierID string `yaml:"id"` - NewQueryFrontendGRPCClientConfig grpcclient.Config `yaml:"query_frontend_grpc_client" doc:"description=Configures the querier gRPC client used to communicate with the query-frontend. Shouldn't be used in conjunction with 'grpc_client_config'."` - OldQueryFrontendGRPCClientConfig grpcclient.Config `yaml:"grpc_client_config" doc:"description=Configures the querier gRPC client used to communicate with the query-frontend and with the query-scheduler if 'query_scheduler_grpc_client' isn't defined. This shouldn't be used if 'query_frontend_grpc_client' is defined."` + NewQueryFrontendGRPCClientConfig grpcclient.Config `yaml:"query_frontend_grpc_client" doc:"description=Configures the querier gRPC client used to communicate with the query-frontend. Can't be used in conjunction with 'grpc_client_config'."` + OldQueryFrontendGRPCClientConfig grpcclient.Config `yaml:"grpc_client_config" doc:"description=Configures the querier gRPC client used to communicate with the query-frontend and with the query-scheduler. Can't be used in conjunction with 'query_frontend_grpc_client' or 'query_scheduler_grpc_client'."` - QuerySchedulerGRPCClientConfig grpcclient.Config `yaml:"query_scheduler_grpc_client" doc:"description=Configures the querier gRPC client used to communicate with the query-scheduler. If not defined, 'grpc_client_config' is used instead."` + QuerySchedulerGRPCClientConfig grpcclient.Config `yaml:"query_scheduler_grpc_client" doc:"description=Configures the querier gRPC client used to communicate with the query-scheduler. Can't be used in conjunction with 'grpc_client_config'."` } func (cfg *Config) RegisterFlags(f *flag.FlagSet) { From 6da8111a561b25a7a72482834e42ae81b094057e Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Wed, 8 May 2024 15:21:45 -0300 Subject: [PATCH 3/4] address michel suggestion --- docs/sources/shared/configuration.md | 6 +++--- pkg/querier/worker/worker.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/sources/shared/configuration.md b/docs/sources/shared/configuration.md index 4d8c18130f5d..5cd5ec255e9b 100644 --- a/docs/sources/shared/configuration.md +++ b/docs/sources/shared/configuration.md @@ -2237,19 +2237,19 @@ The `frontend_worker` configures the worker - running within the Loki querier - [id: | default = ""] # Configures the querier gRPC client used to communicate with the -# query-frontend. Can't be used in conjunction with 'grpc_client_config'. +# query-frontend. This can't be used in conjunction with 'grpc_client_config'. # The CLI flags prefix for this block configuration is: # querier.frontend-grpc-client [query_frontend_grpc_client: ] # Configures the querier gRPC client used to communicate with the query-frontend -# and with the query-scheduler. Can't be used in conjunction with +# and with the query-scheduler. This can't be used in conjunction with # 'query_frontend_grpc_client' or 'query_scheduler_grpc_client'. # The CLI flags prefix for this block configuration is: querier.frontend-client [grpc_client_config: ] # Configures the querier gRPC client used to communicate with the -# query-scheduler. Can't be used in conjunction with 'grpc_client_config'. +# query-scheduler. This can't be used in conjunction with 'grpc_client_config'. # The CLI flags prefix for this block configuration is: # querier.scheduler-grpc-client [query_scheduler_grpc_client: ] diff --git a/pkg/querier/worker/worker.go b/pkg/querier/worker/worker.go index 927f487beba2..0c13bdd6df9d 100644 --- a/pkg/querier/worker/worker.go +++ b/pkg/querier/worker/worker.go @@ -30,10 +30,10 @@ type Config struct { QuerierID string `yaml:"id"` - NewQueryFrontendGRPCClientConfig grpcclient.Config `yaml:"query_frontend_grpc_client" doc:"description=Configures the querier gRPC client used to communicate with the query-frontend. Can't be used in conjunction with 'grpc_client_config'."` - OldQueryFrontendGRPCClientConfig grpcclient.Config `yaml:"grpc_client_config" doc:"description=Configures the querier gRPC client used to communicate with the query-frontend and with the query-scheduler. Can't be used in conjunction with 'query_frontend_grpc_client' or 'query_scheduler_grpc_client'."` + NewQueryFrontendGRPCClientConfig grpcclient.Config `yaml:"query_frontend_grpc_client" doc:"description=Configures the querier gRPC client used to communicate with the query-frontend. This can't be used in conjunction with 'grpc_client_config'."` + OldQueryFrontendGRPCClientConfig grpcclient.Config `yaml:"grpc_client_config" doc:"description=Configures the querier gRPC client used to communicate with the query-frontend and with the query-scheduler. This can't be used in conjunction with 'query_frontend_grpc_client' or 'query_scheduler_grpc_client'."` - QuerySchedulerGRPCClientConfig grpcclient.Config `yaml:"query_scheduler_grpc_client" doc:"description=Configures the querier gRPC client used to communicate with the query-scheduler. Can't be used in conjunction with 'grpc_client_config'."` + QuerySchedulerGRPCClientConfig grpcclient.Config `yaml:"query_scheduler_grpc_client" doc:"description=Configures the querier gRPC client used to communicate with the query-scheduler. This can't be used in conjunction with 'grpc_client_config'."` } func (cfg *Config) RegisterFlags(f *flag.FlagSet) { From ba06c4ed643d0478741cadffb540ad0d597caad5 Mon Sep 17 00:00:00 2001 From: DylanGuedes Date: Wed, 8 May 2024 15:47:24 -0300 Subject: [PATCH 4/4] keep behavior --- pkg/loki/config_wrapper.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/loki/config_wrapper.go b/pkg/loki/config_wrapper.go index ddb7a9626203..4c8da5de23ae 100644 --- a/pkg/loki/config_wrapper.go +++ b/pkg/loki/config_wrapper.go @@ -693,8 +693,13 @@ func applyCommonQuerierWorkerGRPCConfig(cfg, defaults *ConfigWrapper) error { usingNewSchedulerCfg := !reflect.DeepEqual(cfg.Worker.QuerySchedulerGRPCClientConfig, defaults.Worker.QuerySchedulerGRPCClientConfig) usingOldFrontendCfg := !reflect.DeepEqual(cfg.Worker.OldQueryFrontendGRPCClientConfig, defaults.Worker.OldQueryFrontendGRPCClientConfig) - if usingOldFrontendCfg && (usingNewFrontendCfg || usingNewSchedulerCfg) { - return fmt.Errorf("both `grpc_client_config` and (`query_frontend_grpc_client` or `query_scheduler_grpc_client`) are set at the same time. Please use only `query_frontend_grpc_client` and `query_scheduler_grpc_client`") + if usingOldFrontendCfg { + if usingNewFrontendCfg || usingNewSchedulerCfg { + return fmt.Errorf("both `grpc_client_config` and (`query_frontend_grpc_client` or `query_scheduler_grpc_client`) are set at the same time. Please use only `query_frontend_grpc_client` and `query_scheduler_grpc_client`") + } + cfg.Worker.NewQueryFrontendGRPCClientConfig = cfg.Worker.OldQueryFrontendGRPCClientConfig + cfg.Worker.QuerySchedulerGRPCClientConfig = cfg.Worker.OldQueryFrontendGRPCClientConfig } + return nil }