Skip to content

Commit

Permalink
Apply review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-antoniak committed Jul 2, 2024
1 parent 186f920 commit 49b874c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 23 deletions.
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.

Expand Down
18 changes: 18 additions & 0 deletions proxy/launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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)

Expand Down
19 changes: 2 additions & 17 deletions proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
5 changes: 3 additions & 2 deletions proxy/main_profiling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -62,5 +63,5 @@ func main() {
}()
}

launchProxy(true, configFile)
launchProxy(true, configFileOpt)
}
2 changes: 1 addition & 1 deletion proxy/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 49b874c

Please sign in to comment.