Skip to content

Commit

Permalink
Add DNS duration and start time
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Sep 4, 2024
1 parent d7ed47d commit 089afc6
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions x/examples/test-connectivity/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ type testReport struct {
}

type dnsReport struct {
QueryName string `json:"query_name"`
AnswerIPs []string `json:"answer_ips"`
Error string `json:"error"`
QueryName string `json:"query_name"`
Time time.Time `json:"time"`
DurationMs int64 `json:"duration_ms"`
AnswerIPs []string `json:"answer_ips"`
Error string `json:"error"`
}

type tcpReport struct {
Expand Down Expand Up @@ -198,10 +200,16 @@ func main() {
if err != nil {
return nil, err
}
var dnsStart time.Time
ctx = httptrace.WithClientTrace(ctx, &httptrace.ClientTrace{
DNSStart: func(di httptrace.DNSStartInfo) {
dnsStart = time.Now()
},
DNSDone: func(di httptrace.DNSDoneInfo) {
report := dnsReport{
QueryName: hostname,
QueryName: hostname,
Time: dnsStart.UTC().Truncate(time.Second),
DurationMs: time.Since(dnsStart).Milliseconds(),
}
if di.Err != nil {
report.Error = di.Err.Error()
Expand Down Expand Up @@ -242,10 +250,16 @@ func main() {
if err != nil {
return nil, err
}
var dnsStart time.Time
ctx = httptrace.WithClientTrace(ctx, &httptrace.ClientTrace{
DNSStart: func(di httptrace.DNSStartInfo) {
dnsStart = time.Now()
},
DNSDone: func(di httptrace.DNSDoneInfo) {
report := dnsReport{
QueryName: hostname,
QueryName: hostname,
Time: dnsStart.UTC().Truncate(time.Second),
DurationMs: time.Since(dnsStart).Milliseconds(),
}
if di.Err != nil {
report.Error = di.Err.Error()
Expand Down

0 comments on commit 089afc6

Please sign in to comment.