Skip to content

Commit 1bed2a8

Browse files
Add DNS lookup latency to the response (#559)
1 parent 6486184 commit 1bed2a8

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

services/dns/dns.pb.go

Lines changed: 20 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/dns/dns.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,5 @@ message LookupRequest {
3535
// LookupReply describes the result of a DNS query
3636
message LookupReply {
3737
repeated string result = 1;
38+
int64 lookup_latency_ns = 2;
3839
}

services/dns/server/dns.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package server
2020
import (
2121
"context"
2222
"net"
23+
"time"
2324

2425
"github.com/go-logr/logr"
2526
"google.golang.org/grpc"
@@ -51,14 +52,18 @@ func (s *server) Lookup(ctx context.Context, req *pb.LookupRequest) (*pb.LookupR
5152
hostname := req.GetHostname()
5253

5354
logger.Info("dns request", "hostname", hostname)
55+
timeStart := time.Now()
5456
// TODO(elsesiy): We only care about ipv4 for now but we could allow clients to explicitly specify opts such as network, prefer go resolver, etc.
5557
ips, err := resolver(ctx, "ip4", hostname)
58+
duration := time.Since(timeStart)
5659
if err != nil {
5760
recorder.CounterOrLog(ctx, dnsLookupFailureCounter, 1)
5861
return nil, status.Errorf(codes.Internal, "failed to lookup %q", hostname)
5962
}
6063

61-
reply := &pb.LookupReply{}
64+
reply := &pb.LookupReply{
65+
LookupLatencyNs: duration.Nanoseconds(),
66+
}
6267
for _, ip := range ips {
6368
reply.Result = append(reply.Result, ip.String())
6469
}

0 commit comments

Comments
 (0)