Skip to content

Commit

Permalink
grpcutil.Resolver.Resolve: Take a service parameter instead of hardco…
Browse files Browse the repository at this point in the history
…ding grpclb

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
  • Loading branch information
aknuds1 committed Dec 21, 2021
1 parent 1f49a70 commit 4d51420
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [CHANGE] spanlogger: Take interface implementation for extracting tenant ID. #59
* [CHANGE] The `status_code` label on gRPC client metrics has changed from '200' and '500' to '2xx', '5xx', '4xx', 'cancel' or 'error'. #68
* [CHANGE] Memberlist: changed probe interval from `1s` to `5s` and probe timeout from `500ms` to `2s`. #90
* [CHANGE] grpcutil.Resolver.Resolve: Take a service parameter.
* [ENHANCEMENT] Add middleware package. #38
* [ENHANCEMENT] Add the ring package #45
* [ENHANCEMENT] Add limiter package. #41
Expand Down
30 changes: 16 additions & 14 deletions grpcutil/dns_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func parseTarget(target string) (host, port string, err error) {
return "", "", fmt.Errorf("invalid target address %v", target)
}

// Resolve creates a watcher that watches the name resolution of the target.
func (r *dnsResolver) Resolve(target string) (Watcher, error) {
// Resolve creates a watcher that watches the SRV record resolution of the target.
func (r *dnsResolver) Resolve(target, service string) (Watcher, error) {
host, port, err := parseTarget(target)
if err != nil {
return nil, err
Expand All @@ -119,22 +119,24 @@ func (r *dnsResolver) Resolve(target string) (Watcher, error) {

ctx, cancel := context.WithCancel(context.Background())
return &dnsWatcher{
r: r,
logger: r.logger,
host: host,
port: port,
ctx: ctx,
cancel: cancel,
t: time.NewTimer(0),
r: r,
logger: r.logger,
host: host,
port: port,
service: service,
ctx: ctx,
cancel: cancel,
t: time.NewTimer(0),
}, nil
}

// dnsWatcher watches for the name resolution update for a specific target
type dnsWatcher struct {
r *dnsResolver
logger log.Logger
host string
port string
r *dnsResolver
logger log.Logger
host string
port string
service string
// The latest resolved address set
curAddrs map[string]*Update
ctx context.Context
Expand Down Expand Up @@ -204,7 +206,7 @@ func (w *dnsWatcher) compileUpdate(newAddrs map[string]*Update) []*Update {

func (w *dnsWatcher) lookupSRV() map[string]*Update {
newAddrs := make(map[string]*Update)
_, srvs, err := lookupSRV(w.ctx, "grpclb", "tcp", w.host)
_, srvs, err := lookupSRV(w.ctx, w.service, "tcp", w.host)
if err != nil {
level.Info(w.logger).Log("msg", "failed DNS SRV record lookup", "err", err)
return nil
Expand Down
6 changes: 3 additions & 3 deletions grpcutil/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type Update struct {

// Resolver creates a Watcher for a target to track its resolution changes.
type Resolver interface {
// Resolve creates a Watcher for target.
Resolve(target string) (Watcher, error)
// Resolve creates a Watcher for target/service.
Resolve(target, service string) (Watcher, error)
}

// Watcher watches for the updates on the specified target.
// Watcher watches for the SRV updates on the specified target.
type Watcher interface {
// Next blocks until an update or error happens. It may return one or more
// updates. The first call should get the full set of the results. It should
Expand Down

0 comments on commit 4d51420

Please sign in to comment.