Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Commit

Permalink
Debug host resolution part.
Browse files Browse the repository at this point in the history
Signed-off-by: Bartek Plotka <[email protected]>
  • Loading branch information
bwplotka committed Nov 28, 2018
1 parent 769c819 commit cf4b364
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkg/kedge/http/lbtransport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package lbtransport

import (
"context"
"fmt"
"net"
"net/http"
"os"
"sync"

"github.com/improbable-eng/go-httpwares/tags"
Expand Down Expand Up @@ -56,12 +58,14 @@ func New(ctx context.Context, targetAddr string, parent http.RoundTripper, resol
currentTargets: []*Target{},
}

fmt.Fprintln(os.Stderr, "New watcher for target ", targetAddr)
watcher, err := resolver.Resolve(targetAddr)
if err != nil {
return nil, errors.Wrapf(err, "tripper: failed to do initial resolve for target %s", targetAddr)
}
go func() {
<-ctx.Done()
fmt.Fprintln(os.Stderr, "Closing watcher for target ", targetAddr)
watcher.Close()
}()
go s.run(ctx, watcher)
Expand All @@ -71,15 +75,18 @@ func New(ctx context.Context, targetAddr string, parent http.RoundTripper, resol
func (s *tripper) run(ctx context.Context, watcher naming.Watcher) {
var localCurrentTargets []*Target
for ctx.Err() == nil {
fmt.Fprintln(os.Stderr, "Waiting for Next ", s.targetName)
updates, err := watcher.Next() // blocking call until new updates are there
if err != nil {
fmt.Fprintln(os.Stderr, "err ", err)
// Watcher next errors are irrecoverable.
s.mu.Lock()
s.irrecoverableErr = err
s.currentTargets = []*Target{}
s.mu.Unlock()
return
}
fmt.Fprintln(os.Stderr, "After next ", len(updates))

for _, u := range updates {
if u.Op == naming.Add {
Expand Down
33 changes: 33 additions & 0 deletions pkg/resolvers/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package hostresolver

import (
"fmt"
"github.com/prometheus/client_golang/prometheus"
"net"
"os"
"time"

"github.com/improbable-eng/go-srvlb/grpc"
"github.com/improbable-eng/go-srvlb/srv"
Expand All @@ -16,6 +19,32 @@ var (
ParentHostResolver hostResolverFn = net.LookupHost
)

var (
res = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "kedge",
Subsystem: "dns_host",
Name: "resolutions",
Help: "debug.",
},
[]string{"target"},
)
resHist = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Namespace: "kedge",
Subsystem: "dns_host",
Name: "resolutions_hist",
Help: "debug.",
},
[]string{"target"},
)
)

func init() {
prometheus.MustRegister(res)
prometheus.MustRegister(resHist)
}

func NewFromConfig(conf *pb.HostResolver) (target string, namer naming.Resolver, err error) {
parent := ParentHostResolver
return conf.GetDnsName(), grpcsrvlb.New(newHostResolver(conf.Port, parent)), nil
Expand All @@ -35,8 +64,12 @@ func newHostResolver(port uint32, hostResolverFn hostResolverFn) srv.Resolver {
}

func (r *hostResolver) Lookup(domainName string) ([]*srv.Target, error) {
res.WithLabelValues(domainName).Inc()
start := time.Now()
ips, err := r.hostResolverFn(domainName)
resHist.WithLabelValues(domainName).Observe(float64(time.Since(start)))
if err != nil {
fmt.Fprintln(os.Stderr, "Error", err)
return nil, err
}

Expand Down

0 comments on commit cf4b364

Please sign in to comment.