datastax/cql-proxy

Improve warning when initial connection is to host with rpc_address of 0.0.0.0

Opened this issue · 1 comments

This case leads to the following error message:

{"level":"error","ts":1674158444.9508557,"caller":"proxycore/cluster.go:357","msg":"unable to create new endpoint","error":"ignoring host because its `peer` is not set or is invalid","stacktrace":
"github.com/datastax/cql-proxy/proxycore.(*Cluster).addHosts\n\t/go/src/cql-proxy/proxycore/cluster.go:357
github.com/datastax/cql-proxy/proxycore.(*Cluster).queryHosts\n\t/go/src/cql-proxy/proxycore/cluster.go:300
github.com/datastax/cql-proxy/proxycore.(*Cluster).connect\n\t/go/src/cql-proxy/proxycore/cluster.go:223
github.com/datatax/cql-proxy/proxycore.ConnectCluster\n\t/go/src/cql-proxy/proxycore/cluster.go:163
github.com/datastax/cql-proxy/proxy.(*Proxy).Connect\n\t/go/src/cql-proxy/proxy/proxy.go:167
github.com/datastax/cql-proxy/proxy.(*runConfig).listenAndServe\n\t/go/src/cql-proxy/proxy/run.go:274
github.com/datastax/cql-proxy/proxy.Run\n\t/go/src/cql-proxy/proxy/run.go:195
main.main\n\t/go/src/cql-proxy/proxy.go:29
runtime.main\n\t/usr/local/go/src/runtime/proc.go:225"}                                                                          
panic: runtime error: index out of range [0] with length 0

Relevant code is NewEndpoint. This code starts with "rpc_address" and falls back to "peer" if that's set to 0.0.0.0. This doesn't work for system.local, though, where "peer" is not a defined column. Thus we wind up with the error message above which doesn't really communicate what's going on.

It would be nice if we could provide a more informative error to the user, at least something indicating that 0.0.0.0 rpc_addresses will introduce this behaviour.

Some of our Cassandra clusters have "rpc_address" column with an "unspecified" address of 0.0.0.0 in their system.local table. I would be glad if we could use cql-proxy with those clusters.

I found that the ZDM proxy seems to use broadcast_address or listen_address if rpc_address is 0.0.0.0.

https://github.com/datastax/zdm-proxy/blob/main/proxy/pkg/zdmproxy/host.go#L188

Is it possible to use the same logic in cql-proxy?