cmd/derper: count bootstrap dns unique lookups.

Updates https://github.com/tailscale/corp/issues/13979

Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
Denton Gentry 2023-08-17 04:11:32 -07:00 committed by Denton Gentry
parent 7e15c78a5a
commit e8d140654a
3 changed files with 23 additions and 1 deletions

View File

@ -25,6 +25,7 @@
dnsCache syncs.AtomicValue[dnsEntryMap] dnsCache syncs.AtomicValue[dnsEntryMap]
dnsCacheBytes syncs.AtomicValue[[]byte] // of JSON dnsCacheBytes syncs.AtomicValue[[]byte] // of JSON
unpublishedDNSCache syncs.AtomicValue[dnsEntryMap] unpublishedDNSCache syncs.AtomicValue[dnsEntryMap]
bootstrapLookupMap syncs.Map[string, bool]
) )
var ( var (
@ -35,6 +36,12 @@
unpublishedDNSMisses = expvar.NewInt("counter_bootstrap_dns_unpublished_misses") 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() { func refreshBootstrapDNSLoop() {
if *bootstrapDNS == "" && *unpublishedDNS == "" { if *bootstrapDNS == "" && *unpublishedDNS == "" {
return return
@ -107,6 +114,7 @@ func handleBootstrapDNS(w http.ResponseWriter, r *http.Request) {
// Try answering a query from our hidden map first // Try answering a query from our hidden map first
if q := r.URL.Query().Get("q"); q != "" { if q := r.URL.Query().Get("q"); q != "" {
bootstrapLookupMap.Store(q, true)
if ips, ok := unpublishedDNSCache.Load()[q]; ok && len(ips) > 0 { if ips, ok := unpublishedDNSCache.Load()[q]; ok && len(ips) > 0 {
unpublishedDNSHits.Add(1) unpublishedDNSHits.Add(1)

View File

@ -98,6 +98,7 @@ func resetMetrics() {
publishedDNSMisses.Set(0) publishedDNSMisses.Set(0)
unpublishedDNSHits.Set(0) unpublishedDNSHits.Set(0)
unpublishedDNSMisses.Set(0) unpublishedDNSMisses.Set(0)
bootstrapLookupMap.Clear()
} }
// Verify that we don't count an empty list in the unpublishedDNSCache as a // 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) 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())
}
} }

View File

@ -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/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/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/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+ golang.org/x/exp/slices from tailscale.com/net/tsaddr+
L golang.org/x/net/bpf from github.com/mdlayher/netlink+ L golang.org/x/net/bpf from github.com/mdlayher/netlink+
golang.org/x/net/dns/dnsmessage from net+ golang.org/x/net/dns/dnsmessage from net+