feat(everything): did a massive dnssec refactor to improve robustness
This commit is contained in:
+24
-13
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/afonsofrancof/sdns-proxy/client"
|
||||
"github.com/afonsofrancof/sdns-proxy/common/dnssec"
|
||||
"github.com/afonsofrancof/sdns-proxy/internal/qol/capture"
|
||||
"github.com/afonsofrancof/sdns-proxy/internal/qol/results"
|
||||
"github.com/afonsofrancof/sdns-proxy/internal/qol/stats"
|
||||
@@ -202,34 +203,44 @@ func (r *MeasurementRunner) performQuery(dnsClient client.DNSClient, domain, ups
|
||||
msg.RecursionDesired = true
|
||||
msg.SetQuestion(dns.Fqdn(domain), qType)
|
||||
|
||||
packed, err := msg.Pack()
|
||||
if err != nil {
|
||||
metric.ResponseCode = "ERROR"
|
||||
metric.Error = fmt.Sprintf("pack request: %v", err)
|
||||
return metric
|
||||
}
|
||||
metric.RequestSize = len(packed)
|
||||
|
||||
start := time.Now()
|
||||
metric.Timestamp = start
|
||||
resp, err := dnsClient.Query(msg)
|
||||
sent, resp, err := dnsClient.Query(msg)
|
||||
metric.Duration = time.Since(start).Nanoseconds()
|
||||
metric.DurationMs = float64(metric.Duration) / 1e6
|
||||
|
||||
if sent != nil {
|
||||
if b, perr := sent.Pack(); perr == nil {
|
||||
metric.RequestSize = len(b)
|
||||
}
|
||||
} else if b, perr := msg.Pack(); perr == nil {
|
||||
metric.RequestSize = len(b)
|
||||
}
|
||||
|
||||
if reporter, ok := dnsClient.(interface {
|
||||
LastValidation() dnssec.ValidationStats
|
||||
}); ok {
|
||||
st := reporter.LastValidation()
|
||||
metric.DNSSECValidated = st.Validated
|
||||
metric.DNSSECQueries = st.Queries
|
||||
metric.RequestSize += st.BytesSent
|
||||
metric.ResponseSize += st.BytesReceived
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
metric.ResponseCode = "ERROR"
|
||||
metric.Error = err.Error()
|
||||
return metric
|
||||
}
|
||||
|
||||
respBytes, err := resp.Pack()
|
||||
if err != nil {
|
||||
if b, perr := resp.Pack(); perr == nil {
|
||||
metric.ResponseSize += len(b)
|
||||
} else {
|
||||
metric.ResponseCode = "ERROR"
|
||||
metric.Error = fmt.Sprintf("pack response: %v", err)
|
||||
metric.Error = fmt.Sprintf("pack response: %v", perr)
|
||||
return metric
|
||||
}
|
||||
|
||||
metric.ResponseSize = len(respBytes)
|
||||
metric.ResponseCode = dns.RcodeToString[resp.Rcode]
|
||||
return metric
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ type DNSMetric struct {
|
||||
QueryType string `json:"query_type"`
|
||||
Protocol string `json:"protocol"`
|
||||
DNSSEC bool `json:"dnssec"`
|
||||
DNSSECValidated bool `json:"dnssec_validated"`
|
||||
DNSSECQueries int `json:"dnssec_queries"`
|
||||
AuthoritativeDNSSEC bool `json:"auth_dnssec"`
|
||||
KeepAlive bool `json:"keep_alive"`
|
||||
DNSServer string `json:"dns_server"`
|
||||
@@ -48,8 +50,8 @@ func NewMetricsWriter(path string) (*MetricsWriter, error) {
|
||||
// Only write header if file is new
|
||||
if !fileExists {
|
||||
header := []string{
|
||||
"domain", "query_type", "protocol", "dnssec", "auth_dnssec", "keep_alive",
|
||||
"dns_server", "timestamp", "duration_ns", "duration_ms",
|
||||
"domain", "query_type", "protocol", "dnssec", "dnssec_validated", "dnssec_queries",
|
||||
"auth_dnssec", "keep_alive", "dns_server", "timestamp", "duration_ns", "duration_ms",
|
||||
"request_size_bytes", "response_size_bytes", "response_code", "error",
|
||||
}
|
||||
|
||||
@@ -72,6 +74,8 @@ func (mw *MetricsWriter) WriteMetric(metric DNSMetric) error {
|
||||
metric.QueryType,
|
||||
metric.Protocol,
|
||||
strconv.FormatBool(metric.DNSSEC),
|
||||
strconv.FormatBool(metric.DNSSECValidated),
|
||||
strconv.Itoa(metric.DNSSECQueries),
|
||||
strconv.FormatBool(metric.AuthoritativeDNSSEC),
|
||||
strconv.FormatBool(metric.KeepAlive),
|
||||
metric.DNSServer,
|
||||
|
||||
@@ -3,6 +3,7 @@ package stats
|
||||
import (
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"golang.org/x/sys/unix"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
@@ -15,6 +16,7 @@ type RuntimeStats struct {
|
||||
AllocDelta uint64
|
||||
MallocsDelta uint64
|
||||
GCDelta uint32
|
||||
PeakRSSKB int64
|
||||
}
|
||||
|
||||
type RuntimeCollector struct {
|
||||
@@ -43,6 +45,7 @@ func (rc *RuntimeCollector) Collect() RuntimeStats {
|
||||
AllocDelta: current.TotalAlloc - rc.startStats.TotalAlloc,
|
||||
MallocsDelta: current.Mallocs - rc.startStats.Mallocs,
|
||||
GCDelta: current.NumGC - rc.startStats.NumGC,
|
||||
PeakRSSKB: peakRSSKB(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +72,7 @@ func (rc *RuntimeCollector) WriteStats() error {
|
||||
if !fileExists {
|
||||
header := []string{
|
||||
"timestamp", "total_alloc_bytes", "mallocs", "gc_cycles",
|
||||
"alloc_delta", "mallocs_delta", "gc_delta",
|
||||
"alloc_delta", "mallocs_delta", "gc_delta", "peak_rss_kb",
|
||||
}
|
||||
if err := writer.Write(header); err != nil {
|
||||
return fmt.Errorf("failed to write mem.csv header: %w", err)
|
||||
@@ -85,6 +88,7 @@ func (rc *RuntimeCollector) WriteStats() error {
|
||||
fmt.Sprintf("%d", stats.AllocDelta),
|
||||
fmt.Sprintf("%d", stats.MallocsDelta),
|
||||
fmt.Sprintf("%d", stats.GCDelta),
|
||||
fmt.Sprintf("%d", stats.PeakRSSKB),
|
||||
}
|
||||
if err := writer.Write(row); err != nil {
|
||||
return fmt.Errorf("failed to write mem.csv row: %w", err)
|
||||
@@ -93,3 +97,11 @@ func (rc *RuntimeCollector) WriteStats() error {
|
||||
writer.Flush()
|
||||
return writer.Error()
|
||||
}
|
||||
|
||||
func peakRSSKB() int64 {
|
||||
var ru unix.Rusage
|
||||
if err := unix.Getrusage(unix.RUSAGE_SELF, &ru); err != nil {
|
||||
return 0
|
||||
}
|
||||
return int64(ru.Maxrss)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user