Skip to content

Commit e8d1406

Browse files
committed
cmd/derper: count bootstrap dns unique lookups.
Updates https://github.com/tailscale/corp/issues/13979 Signed-off-by: Denton Gentry <[email protected]>
1 parent 7e15c78 commit e8d1406

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

cmd/derper/bootstrap_dns.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ var (
2525
dnsCache syncs.AtomicValue[dnsEntryMap]
2626
dnsCacheBytes syncs.AtomicValue[[]byte] // of JSON
2727
unpublishedDNSCache syncs.AtomicValue[dnsEntryMap]
28+
bootstrapLookupMap syncs.Map[string, bool]
2829
)
2930

3031
var (
@@ -35,6 +36,12 @@ var (
3536
unpublishedDNSMisses = expvar.NewInt("counter_bootstrap_dns_unpublished_misses")
3637
)
3738

39+
func init() {
40+
expvar.Publish("counter_bootstrap_dns_queried_domains", expvar.Func(func() any {
41+
return bootstrapLookupMap.Len()
42+
}))
43+
}
44+
3845
func refreshBootstrapDNSLoop() {
3946
if *bootstrapDNS == "" && *unpublishedDNS == "" {
4047
return
@@ -107,6 +114,7 @@ func handleBootstrapDNS(w http.ResponseWriter, r *http.Request) {
107114

108115
// Try answering a query from our hidden map first
109116
if q := r.URL.Query().Get("q"); q != "" {
117+
bootstrapLookupMap.Store(q, true)
110118
if ips, ok := unpublishedDNSCache.Load()[q]; ok && len(ips) > 0 {
111119
unpublishedDNSHits.Add(1)
112120

cmd/derper/bootstrap_dns_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func resetMetrics() {
9898
publishedDNSMisses.Set(0)
9999
unpublishedDNSHits.Set(0)
100100
unpublishedDNSMisses.Set(0)
101+
bootstrapLookupMap.Clear()
101102
}
102103

103104
// Verify that we don't count an empty list in the unpublishedDNSCache as a
@@ -148,4 +149,17 @@ func TestUnpublishedDNSEmptyList(t *testing.T) {
148149
t.Errorf("got misses=%d; want 0", v)
149150
}
150151
})
152+
153+
}
154+
155+
func TestLookupMetric(t *testing.T) {
156+
d := []string{"a.io", "b.io", "c.io", "d.io", "e.io", "e.io", "e.io", "a.io"}
157+
resetMetrics()
158+
for _, q := range d {
159+
_ = getBootstrapDNS(t, q)
160+
}
161+
// {"a.io": true, "b.io": true, "c.io": true, "d.io": true, "e.io": true}
162+
if bootstrapLookupMap.Len() != 5 {
163+
t.Errorf("bootstrapLookupMap.Len() want=5, got %v", bootstrapLookupMap.Len())
164+
}
151165
}

cmd/derper/depaware.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa
169169
golang.org/x/crypto/nacl/secretbox from golang.org/x/crypto/nacl/box
170170
golang.org/x/crypto/salsa20/salsa from golang.org/x/crypto/nacl/box+
171171
golang.org/x/exp/constraints from golang.org/x/exp/slices
172-
golang.org/x/exp/maps from tailscale.com/types/views
172+
golang.org/x/exp/maps from tailscale.com/types/views+
173173
golang.org/x/exp/slices from tailscale.com/net/tsaddr+
174174
L golang.org/x/net/bpf from github.com/mdlayher/netlink+
175175
golang.org/x/net/dns/dnsmessage from net+

0 commit comments

Comments
 (0)