diff --git a/cmd/derper/bootstrap_dns.go b/cmd/derper/bootstrap_dns.go index e7d96f466..ee33899f6 100644 --- a/cmd/derper/bootstrap_dns.go +++ b/cmd/derper/bootstrap_dns.go @@ -25,6 +25,7 @@ var ( dnsCache syncs.AtomicValue[dnsEntryMap] dnsCacheBytes syncs.AtomicValue[[]byte] // of JSON unpublishedDNSCache syncs.AtomicValue[dnsEntryMap] + bootstrapLookupMap syncs.Map[string, bool] ) var ( @@ -35,6 +36,12 @@ var ( unpublishedDNSMisses = expvar.NewInt("counter_bootstrap_dns_unpublished_misses") ) +func init() { + expvar.Publish("counter_bootstrap_dns_queried_domains", expvar.Func(func() any { + return bootstrapLookupMap.Len() + })) +} + func refreshBootstrapDNSLoop() { if *bootstrapDNS == "" && *unpublishedDNS == "" { return @@ -107,6 +114,7 @@ func handleBootstrapDNS(w http.ResponseWriter, r *http.Request) { // Try answering a query from our hidden map first if q := r.URL.Query().Get("q"); q != "" { + bootstrapLookupMap.Store(q, true) if ips, ok := unpublishedDNSCache.Load()[q]; ok && len(ips) > 0 { unpublishedDNSHits.Add(1) diff --git a/cmd/derper/bootstrap_dns_test.go b/cmd/derper/bootstrap_dns_test.go index cbede8587..bd6786558 100644 --- a/cmd/derper/bootstrap_dns_test.go +++ b/cmd/derper/bootstrap_dns_test.go @@ -98,6 +98,7 @@ func resetMetrics() { publishedDNSMisses.Set(0) unpublishedDNSHits.Set(0) unpublishedDNSMisses.Set(0) + bootstrapLookupMap.Clear() } // Verify that we don't count an empty list in the unpublishedDNSCache as a @@ -148,4 +149,17 @@ func TestUnpublishedDNSEmptyList(t *testing.T) { t.Errorf("got misses=%d; want 0", v) } }) + +} + +func TestLookupMetric(t *testing.T) { + d := []string{"a.io", "b.io", "c.io", "d.io", "e.io", "e.io", "e.io", "a.io"} + resetMetrics() + for _, q := range d { + _ = getBootstrapDNS(t, q) + } + // {"a.io": true, "b.io": true, "c.io": true, "d.io": true, "e.io": true} + if bootstrapLookupMap.Len() != 5 { + t.Errorf("bootstrapLookupMap.Len() want=5, got %v", bootstrapLookupMap.Len()) + } } diff --git a/cmd/derper/depaware.txt b/cmd/derper/depaware.txt index 3e99538eb..427323d89 100644 --- a/cmd/derper/depaware.txt +++ b/cmd/derper/depaware.txt @@ -169,7 +169,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa golang.org/x/crypto/nacl/secretbox from golang.org/x/crypto/nacl/box golang.org/x/crypto/salsa20/salsa from golang.org/x/crypto/nacl/box+ golang.org/x/exp/constraints from golang.org/x/exp/slices - golang.org/x/exp/maps from tailscale.com/types/views + golang.org/x/exp/maps from tailscale.com/types/views+ golang.org/x/exp/slices from tailscale.com/net/tsaddr+ L golang.org/x/net/bpf from github.com/mdlayher/netlink+ golang.org/x/net/dns/dnsmessage from net+