MCPcopy Index your code
hub / github.com/AdguardTeam/dnsproxy / collectQueryStats

Function collectQueryStats

proxy/stats.go:95–141  ·  view source on GitHub ↗

collectQueryStats gathers the statistics from the wrapped upstreams. resolver is an upstream DNS resolver that successfully resolved the request, if any. Provided upstreams must be of type [*upstreamWithStats]. unwrapped is the unwrapped resolver, see [upstreamWithStats.upstream]. The returned st

(
	mode UpstreamMode,
	resolver upstream.Upstream,
	upstreams []upstream.Upstream,
	fallbacks []upstream.Upstream,
)

Source from the content-addressed store, hash-verified

93// statistics depend on whether the DNS request was successfully resolved and
94// the upstream mode, see [DNSContext.QueryStatistics].
95func collectQueryStats(
96 mode UpstreamMode,
97 resolver upstream.Upstream,
98 upstreams []upstream.Upstream,
99 fallbacks []upstream.Upstream,
100) (unwrapped upstream.Upstream, stats *QueryStatistics) {
101 var wrapped *upstreamWithStats
102 if resolver != nil {
103 var ok bool
104 wrapped, ok = resolver.(*upstreamWithStats)
105 if !ok {
106 // Should never happen.
107 panic(fmt.Errorf("unexpected type %T", resolver))
108 }
109
110 unwrapped = wrapped.upstream
111 }
112
113 // The DNS query was not resolved.
114 if wrapped == nil {
115 return nil, &QueryStatistics{
116 main: collectUpstreamStats(upstreams...),
117 fallback: collectUpstreamStats(fallbacks...),
118 }
119 }
120
121 // The DNS query was successfully resolved by main resolver and the upstream
122 // mode is [UpstreamModeFastestAddr].
123 if mode == UpstreamModeFastestAddr && len(fallbacks) == 0 {
124 return unwrapped, &QueryStatistics{
125 main: collectUpstreamStats(upstreams...),
126 }
127 }
128
129 // The DNS query was resolved by fallback resolver.
130 if len(fallbacks) > 0 {
131 return unwrapped, &QueryStatistics{
132 main: collectUpstreamStats(upstreams...),
133 fallback: collectUpstreamStats(wrapped),
134 }
135 }
136
137 // The DNS query was successfully resolved by main resolver.
138 return unwrapped, &QueryStatistics{
139 main: collectUpstreamStats(wrapped),
140 }
141}
142
143// UpstreamStatistics contains the DNS query statistics.
144type UpstreamStatistics struct {

Callers 1

replyFromUpstreamMethod · 0.85

Calls 1

collectUpstreamStatsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…