From 1bd49fe925f73bbff94477b9b847252885729b92 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Sun, 2 Apr 2023 12:25:49 +0200 Subject: Output deadline error metrics --- internal/qna/qna.go | 31 +++++++++++++++++++++---------- scripts/test.sh | 3 ++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/internal/qna/qna.go b/internal/qna/qna.go index 809df15..aa27d07 100644 --- a/internal/qna/qna.go +++ b/internal/qna/qna.go @@ -1,6 +1,8 @@ package qna import ( + "context" + "errors" "fmt" "net" "net/url" @@ -38,6 +40,9 @@ type Progress struct { NumOK int // got response NumOnion int // found onion in response + // More details about deadline errors while sending request + NumDeadline int + // More details about DNS errors while sending request NumDNSNotFound int NumDNSTimeout int @@ -48,6 +53,7 @@ func (p Progress) String() string { str := fmt.Sprintf(" Processed: %d\n", p.NumAnswer()) str += fmt.Sprintf(" Success: %d (Onion-Location:%d)\n", p.NumOK, p.NumOnion) str += fmt.Sprintf(" Failure: %d (Req:%d Do:%d)\n", p.NumError(), p.NumReqErr, p.NumDoErr) + str += fmt.Sprintf(" CTX: %d (Deadline exceeded)\n", p.NumDeadline) str += fmt.Sprintf(" DNS: %d (NotFound:%d Timeout:%d Other:%d)", p.NumDNSErr(), p.NumDNSNotFound, p.NumDNSTimeout, p.NumDNSOther) return str @@ -72,17 +78,17 @@ func (p *Progress) AddAnswer(a Answer) { } if a.DoErr != nil { p.NumDoErr += 1 - err := dnsError(a.DoErr) - if err == nil { - return + if isDeadlineError(a.DoErr) { + p.NumDeadline += 1 } - - if err.IsTimeout { - p.NumDNSTimeout += 1 - } else if err.IsNotFound { - p.NumDNSNotFound += 1 - } else { - p.NumDNSOther += 1 + if err := dnsError(a.DoErr); err != nil { + if err.IsTimeout { + p.NumDNSTimeout += 1 + } else if err.IsNotFound { + p.NumDNSNotFound += 1 + } else { + p.NumDNSOther += 1 + } } return } @@ -117,3 +123,8 @@ func dnsError(err error) *net.DNSError { return dnsErr } + +func isDeadlineError(err error) bool { + urlErr, ok := err.(*url.Error) + return ok && errors.Is(urlErr.Err, context.DeadlineExceeded) +} diff --git a/scripts/test.sh b/scripts/test.sh index de7462c..57e319e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -100,9 +100,10 @@ function main() { processed=$(grep 'Processed:' "$stderr_file" | tail -n1 | xargs | cut -d' ' -f2) success=$(grep 'Success:' "$stderr_file" | tail -n1 | xargs | cut -d' ' -f2) failure=$(grep 'Failure:' "$stderr_file" | tail -n1 | xargs | cut -d' ' -f2) + failure_ctx=$(grep 'CTX:' "$stderr_file" | tail -n1 | xargs | cut -d' ' -f2) failure_dns=$(grep 'DNS:' "$stderr_file" | tail -n1 | xargs | cut -d' ' -f2) failure_dns_detailed=$(grep 'DNS:' "$stderr_file" | tail -n1 | xargs | cut -d' ' -f3-) - info "relay:$relay limit:$limit/s avg-rate:$avg_rate onions:$num_onion connected:$success/$processed dns-error:$failure_dns/$failure $failure_dns_detailed" + info "relay:$relay limit:$limit/s avg-rate:$avg_rate onions:$num_onion connected:$success/$processed deadline-error:$failure_ctx/$failure dns-error:$failure_dns/$failure $failure_dns_detailed" output_file=$out_dir/$relay-l$limit.txt mv "$stdout_file" "$output_file" -- cgit v1.2.3