Skip to content

Commit

Permalink
Merge pull request stripe#181 from stripe/ransford-dns-query-time-metric
Browse files Browse the repository at this point in the history
Add timing metric for DNS resolution
  • Loading branch information
ransford-stripe authored Dec 1, 2022
2 parents f4fbd78 + f98f253 commit 4835f35
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/smokescreen/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var metrics = []string{
"resolver.deny.not_global_unicast",
"resolver.deny.private_range",
"resolver.deny.user_configured",
"resolver.lookup_time", // DNS lookup time in ms, not tagged
"resolver.errors_total",
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/smokescreen/smokescreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,15 @@ func resolveTCPAddr(config *Config, network, addr string) (*net.TCPAddr, error)

func safeResolve(config *Config, network, addr string) (*net.TCPAddr, string, error) {
config.MetricsClient.Incr("resolver.attempts_total", 1)

resolveStart := time.Now()
resolved, err := resolveTCPAddr(config, network, addr)
resolveDuration := time.Since(resolveStart)
if err != nil {
config.MetricsClient.Incr("resolver.errors_total", 1)
return nil, "", err
}
config.MetricsClient.Timing("resolver.lookup_time", resolveDuration, 0.5)

classification := classifyAddr(config, resolved)
config.MetricsClient.Incr(classification.statsdString(), 1)
Expand Down
30 changes: 29 additions & 1 deletion pkg/smokescreen/smokescreen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,22 @@ func TestProxyProtocols(t *testing.T) {
client.Do(req)
clientCh <- true
}()

<-clientCh

// Metrics should show one successful connection and a corresponding successful
// DNS request along with its timing metric.
tmc, ok := cfg.MetricsClient.(*metrics.MockMetricsClient)
r.True(ok)
i, err := tmc.GetCount("cn.atpt.total", "success:true")
r.NoError(err)
r.Equal(i, uint64(1))
lookups, err := tmc.GetCount("resolver.attempts_total")
r.NoError(err)
r.Equal(lookups, uint64(1))
ltime, err := tmc.GetCount("resolver.lookup_time")
r.NoError(err)
r.Equal(ltime, uint64(1))

entry := findCanonicalProxyDecision(logHook.AllEntries())
r.NotNil(entry)

Expand Down Expand Up @@ -611,6 +625,20 @@ func TestProxyProtocols(t *testing.T) {
serverCh <- true
<-clientCh

// Metrics should show one successful connection and a corresponding successful
// DNS request along with its timing metric.
tmc, ok := cfg.MetricsClient.(*metrics.MockMetricsClient)
r.True(ok)
i, err := tmc.GetCount("cn.atpt.total", "success:true")
r.NoError(err)
r.Equal(i, uint64(1))
lookups, err := tmc.GetCount("resolver.attempts_total")
r.NoError(err)
r.Equal(lookups, uint64(1))
ltime, err := tmc.GetCount("resolver.lookup_time")
r.NoError(err)
r.Equal(ltime, uint64(1))

entry := findCanonicalProxyDecision(logHook.AllEntries())
r.NotNil(entry)
r.Contains(entry.Data, "proxy_type")
Expand Down

0 comments on commit 4835f35

Please sign in to comment.