From 49b874c5746a7a2fb5435977bfa36f54f0acfa9a Mon Sep 17 00:00:00 2001 From: Lukasz Antoniak Date: Tue, 2 Jul 2024 12:16:51 +0200 Subject: [PATCH] Apply review comments --- README.md | 20 +++++++++++++++++--- proxy/launch.go | 18 ++++++++++++++++++ proxy/main.go | 19 ++----------------- proxy/main_profiling.go | 5 +++-- proxy/pkg/config/config.go | 2 +- 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 3a243d2..e1ae8bf 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,10 @@ An overview of the proxy architecture and logical flow can be viewed [here](http ## Quick Start -In order to run the proxy, you'll need to set some environment variables to configure it properly. +In order to run the proxy, you'll need to set some environment variables or pass reference to YAML configuration file. Below you'll find a list with the most important variables along with their default values. -The required ones are marked with a comment. +The required ones are marked with a comment. Variable names for YAML configuration file do not have `ZDM_` prefix and +are lower-cased. ```shell ZDM_ORIGIN_CONTACT_POINTS=10.0.0.1 #required @@ -36,7 +37,7 @@ ZDM_READ_MODE=PRIMARY_ONLY ZDM_LOG_LEVEL=INFO ``` -The environment variables must be set and exported for the proxy to work. +The environment variables (or YAM configuration file) must be set for the proxy to work. In order to get started quickly, in your local environment, grab a copy of the binary distribution in the [Releases](https://github.com/datastax/zdm-proxy/releases) page. For the recommended installation in a production @@ -55,6 +56,19 @@ export ZDM_TARGET_PASSWORD=cassandra \ ./zdm-proxy-v2.0.0 # run the ZDM proxy executable ``` +If you prefer to use YAML configuration file, analogical setup would look like: + +```shell +$ cat zdm-config.yml +origin_contact_points: 10.0.0.1 +target_contact_points: 10.0.0.2 +origin_username: cassandra +origin_password: cassandra +target_username: cassandra +target_password: cassandra +$ ./zdm-proxy-v2.0.0 --config=./zdm-config.yml # run the ZDM proxy executable +``` + At this point, you should be able to connect some client such as [CQLSH](https://downloads.datastax.com/#cqlsh) to the proxy and write data to it and the proxy will take care of forwarding the requests to both clusters concurrently. diff --git a/proxy/launch.go b/proxy/launch.go index d769b11..36a0e09 100644 --- a/proxy/launch.go +++ b/proxy/launch.go @@ -2,6 +2,8 @@ package main import ( "context" + "flag" + "fmt" "github.com/datastax/zdm-proxy/proxy/pkg/config" "github.com/datastax/zdm-proxy/proxy/pkg/runner" log "github.com/sirupsen/logrus" @@ -10,6 +12,12 @@ import ( "syscall" ) +// TODO: to be managed externally +const ZdmVersionString = "2.2.0" + +var displayVersionOpt = flag.Bool("version", false, "display the ZDM proxy version and exit") +var configFileOpt = flag.String("config", "", "specify path to ZDM configuration file") + func runSignalListener(cancelFunc context.CancelFunc) { sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM) @@ -23,6 +31,16 @@ func runSignalListener(cancelFunc context.CancelFunc) { }() } +func displayVersion() { + if *displayVersionOpt { + fmt.Printf("ZDM proxy version %v\n", ZdmVersionString) + os.Exit(0) + } + + // Always record version information (very) early in the log + log.Infof("Starting ZDM proxy version %v", ZdmVersionString) +} + func launchProxy(profilingSupported bool, configFile string) { conf, err := config.New().LoadConfig(configFile) diff --git a/proxy/main.go b/proxy/main.go index bdf51ff..c219c82 100644 --- a/proxy/main.go +++ b/proxy/main.go @@ -7,28 +7,13 @@ package main import ( "flag" - "fmt" - "os" - - log "github.com/sirupsen/logrus" ) -// TODO: to be managed externally -const ZdmVersionString = "2.2.0" - -var displayVersion = flag.Bool("version", false, "display the ZDM proxy version and exit") -var configFile = flag.String("config", "", "specify path to ZDM configuration file") - func main() { flag.Parse() - if *displayVersion { - fmt.Printf("ZDM proxy version %v\n", ZdmVersionString) - os.Exit(0) - } - // Always record version information (very) early in the log - log.Infof("Starting ZDM proxy version %v", ZdmVersionString) + displayVersion() - launchProxy(false, *configFile) + launchProxy(false, *configFileOpt) } diff --git a/proxy/main_profiling.go b/proxy/main_profiling.go index 1e883bb..bb019d7 100644 --- a/proxy/main_profiling.go +++ b/proxy/main_profiling.go @@ -15,12 +15,13 @@ import ( var cpuProfile = flag.String("cpu_profile", "", "write cpu profile to the specified file") var memProfile = flag.String("mem_profile", "", "write memory profile to the specified file") -var configFile = flag.String("config", "", "specify path to ZDM configuration file") func main() { flag.Parse() + displayVersion() + // the cpu profiling is enabled at startup and is periodically collected while the proxy is running // if cpu profiling is requested, any error configuring or starting it will cause the proxy startup to fail if *cpuProfile != "" { @@ -62,5 +63,5 @@ func main() { }() } - launchProxy(true, configFile) + launchProxy(true, configFileOpt) } diff --git a/proxy/pkg/config/config.go b/proxy/pkg/config/config.go index b8019de..afd2f22 100644 --- a/proxy/pkg/config/config.go +++ b/proxy/pkg/config/config.go @@ -181,7 +181,7 @@ func (c *Config) LoadConfig(configFile string) (*Config, error) { log.Infof("Parsed configuration: %v", c) - return c, err + return c, nil } func lookupFirstIp4(host string) (net.IP, error) {