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

refactor discoverer client #1056

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions internal/client/v1/client/discoverer/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package discoverer

import (
"context"
"fmt"
"reflect"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -139,7 +138,7 @@ func (c *client) Start(ctx context.Context) (<-chan error, error) {
err = c.discover(ctx, ech)
}
if err != nil {
log.Error(err)
log.Warn(err)
select {
case <-ctx.Done():
return finalize()
Expand Down Expand Up @@ -202,7 +201,7 @@ func (c *client) dnsDiscovery(ctx context.Context, ech chan<- error) (addrs []st
}
addrs = make([]string, 0, len(ips))
for _, ip := range ips {
addr := fmt.Sprintf("%s:%d", ip.String(), c.port)
addr := net.JoinHostPort(ip.String(), uint16(c.port))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
File is not gofmt-ed with -s (gofmt)

if err = c.connect(ctx, addr); err != nil {
ech <- err
} else {
Expand Down Expand Up @@ -254,10 +253,10 @@ func (c *client) discover(ctx context.Context, ech chan<- error) (err error) {
if node != nil && node.GetPods() != nil {
pods := node.GetPods().GetPods()
if i < len(pods) {
addr := fmt.Sprintf("%s:%d", pods[i].GetIp(), c.port)
addr := net.JoinHostPort(pods[i].GetIp(), uint16(c.port))
if err = c.connect(ctx, addr); err != nil {
err = errors.ErrAddrCouldNotDiscover(err, addr)
log.Debugf("could not discover %s: %v", addr, err)
log.Debugf("could not discover addr:%s\terror: %v", addr, err)
select {
case <-ictx.Done():
return nil, ictx.Err()
Expand Down
7 changes: 1 addition & 6 deletions internal/net/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,12 +573,7 @@ func (g *gRPCClient) Connect(ctx context.Context, addr string, dopts ...DialOpti
g.atomicAddrs.Add(addr)
return conn, nil
}
log.Warnf("failed to reconnect unhealthy pool addr= %s\terror= %s\t trying to disconnect", addr, func() string {
if err != nil {
return err.Error()
}
return "connection response is nil or pool is nil"
}())
log.Warnf("failed to reconnect unhealthy pool addr= %s\tconn= %v\terror= %v\t trying to disconnect", addr, conn, err)
err = g.Disconnect(ctx, addr)
if err != nil {
log.Warnf("failed to disconnect unhealthy pool addr= %s\terror= %s", addr, err.Error())
Expand Down