Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend --trace or add a --debug flag to see server connections #941

Open
philpennock opened this issue Dec 27, 2023 · 2 comments
Open

Extend --trace or add a --debug flag to see server connections #941

philpennock opened this issue Dec 27, 2023 · 2 comments
Labels
proposal Enhancement idea or proposal

Comments

@philpennock
Copy link
Member

Proposed change

At present, if there is a cluster of hosts and the natscli connects but the TLS cert fails to verify, it appears that it will use the pre-TLS INFO line to look at alternative host IPs reported and try them in turn, until one connects.

But that happens without diagnostic feedback. Which is great for self-healing resiliency, but not for cluster administrators trying to carefully watch the rollout of a change.

Use case

If doing upgrades and trying to see TLS change impact, it's good to know which server is actually being talked to. Having --debug report connection attempts would make it clearer when silent reconnections are happening. Having a --no-reconnect might help too.

Contribution

Sure

@philpennock philpennock added the proposal Enhancement idea or proposal label Dec 27, 2023
@ripienaar
Copy link
Collaborator

Its more that nats.go is doing those things opaquely. So dont think I can do much on the CLI side.

Best I can probably do is add the missing handlers like this - but this wont tell you what you want, we'll have to expand nats.go

+               nats.ConnectHandler(func(conn *nats.Conn) {
+                       if opts.Trace {
+                               log.Printf(">>> Connected to %s", conn.ConnectedUrlRedacted())
+                       }
+               }),
+               nats.DiscoveredServersHandler(func(conn *nats.Conn) {
+                       if opts.Trace {
+                               log.Printf(">>> Discovered new servers, known servers are now %s", strings.Join(conn.Servers(), ", "))
+                       }
+               }),

@philpennock
Copy link
Member Author

I have a chatbot which talks to NATS and it has

	opts = append(opts,
		nats.ConnectHandler(func(nc *nats.Conn) {
			s.
				WithField("cluster", nc.ConnectedClusterName()).
				WithField("server-id", nc.ConnectedServerId()).
				WithField("server-name", nc.ConnectedServerName()).
				WithField("addr", nc.ConnectedAddr()).
				Info("connected")
		}),
		nats.ReconnectHandler(func(nc *nats.Conn) {
			s.
				WithField("cluster", nc.ConnectedClusterName()).
				WithField("server-id", nc.ConnectedServerId()).
				WithField("server-name", nc.ConnectedServerName()).
				WithField("addr", nc.ConnectedAddr()).
				Info("reconnected")
		}),
		nats.DisconnectErrHandler(func(nc *nats.Conn, err error) {
			s.WithError(err).Warn("disconnected")
		}),
/* ... */

That's comprehensive enough for my diagnostics logging and about what I'm after here, I think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Enhancement idea or proposal
Projects
None yet
Development

No branches or pull requests

2 participants