plugin/forward: configurable domain support for healthcheck (#5281)

* plugin/forward: configurable domain support for healthcheck

Signed-off-by: hansedong <admin@yinxiaoluo.com>
This commit is contained in:
hansedong
2022-04-13 00:39:48 +08:00
committed by GitHub
parent e60c179194
commit 0622a6c66c
7 changed files with 113 additions and 35 deletions

View File

@@ -242,3 +242,42 @@ func TestHealthNoMaxFails(t *testing.T) {
t.Errorf("Expected number of health checks to be %d, got %d", 0, i1)
}
}
func TestHealthDomain(t *testing.T) {
hcReadTimeout = 10 * time.Millisecond
readTimeout = 10 * time.Millisecond
defaultTimeout = 10 * time.Millisecond
hcWriteTimeout = 10 * time.Millisecond
hcDomain := "example.org."
i := uint32(0)
q := uint32(0)
s := dnstest.NewServer(func(w dns.ResponseWriter, r *dns.Msg) {
if atomic.LoadUint32(&q) == 0 { //drop the first query to trigger health-checking
atomic.AddUint32(&q, 1)
return
}
if r.Question[0].Name == hcDomain && r.RecursionDesired == true {
atomic.AddUint32(&i, 1)
}
ret := new(dns.Msg)
ret.SetReply(r)
w.WriteMsg(ret)
})
defer s.Close()
p := NewProxy(s.Addr, transport.DNS)
p.health.SetDomain(hcDomain)
f := New()
f.SetProxy(p)
defer f.OnShutdown()
req := new(dns.Msg)
req.SetQuestion(".", dns.TypeNS)
f.ServeDNS(context.TODO(), &test.ResponseWriter{}, req)
time.Sleep(20 * time.Millisecond)
i1 := atomic.LoadUint32(&i)
if i1 != 1 {
t.Errorf("Expected number of health checks with Domain==%s to be %d, got %d", hcDomain, 1, i1)
}
}