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

ping method analog #85

Closed
vtolstov opened this issue Sep 16, 2021 · 9 comments
Closed

ping method analog #85

vtolstov opened this issue Sep 16, 2021 · 9 comments

Comments

@vtolstov
Copy link
Contributor

database/sql has ping method to understand that driver connected to database instance
does it possible to force connect Client to broker and get some results ? Mostly for me this is needed to check that broker address properly set and broker available.

@twmb
Copy link
Owner

twmb commented Sep 16, 2021

Issue an ApiVersions request. Pinging goes against the client internally not connecting unless necessary.

@twmb twmb closed this as completed Sep 16, 2021
@vtolstov
Copy link
Contributor Author

thanks

@vtolstov
Copy link
Contributor Author

Wow, nice. Thank you

@twmb twmb reopened this Dec 17, 2021
@twmb
Copy link
Owner

twmb commented Dec 17, 2021

I'm thinking to add this, after a few more requests.

@weeco
Copy link
Contributor

weeco commented Dec 18, 2021

What would the ping method do? Just an ApiVersions request (which would also be valid without authentication) or also a metadata request for instance? Would that be part of the admin client or what's the idea?

@twmb
Copy link
Owner

twmb commented Dec 20, 2021

I'm thinking:

// Ping returns whether any broker is reachable, iterating over any discovered broker
// or seed broker until one returns a successful response to an ApiVersions request.
// Each request is retried up to 3 times depending on the how the request fails.
// If all requests fail, this returns final error.
func (cl *Client) Ping() error

type PingBrokerError struct {
        Broker BrokerMetadata
        Err    error
}
type PingBrokerErrors []PingBrokerError


// Any returns the first error, if any.
func (es PingBrokerErrors) Any() error

// PingAll iterates through all discovered brokers and issues an ApiVersions request
// to each to test broker connectivity. If there are currently no discovered brokers,
// this iterates through all seed brokers.
func (cl *Client) PingAll() PingBrokerErrors

I'm not yet settled on the API for PingAll: should always iterate over both seeds and non-seeds?

@vtolstov
Copy link
Contributor Author

I'm prefer to have Ping(context.Context) error method.
So i can set deadline on context

@twmb
Copy link
Owner

twmb commented Jan 6, 2022

I've added Ping(context.Context) error, good suggestion about deadlining. This has now been tagged in v1.3.0.

@twmb twmb closed this as completed Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants