[#2] healthchecker: Update readme and log
All checks were successful
/ DCO (pull_request) Successful in 30s
/ Builds (pull_request) Successful in 2m6s
/ Lint (pull_request) Successful in 4m0s
/ Tests (pull_request) Successful in 2m38s
/ Builds (push) Successful in 1m51s
/ Lint (push) Successful in 3m24s
/ Tests (push) Successful in 2m23s

Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
Denis Kirillov 2025-04-04 11:06:50 +03:00
parent 2ccaa23f7c
commit a6e9398f78
8 changed files with 62 additions and 61 deletions

View file

@ -65,41 +65,41 @@ Make sure you run Coredns as root.
In this configuration, we will filter `A` and `AAAA` records, store maximum 1000 records in cache, and start recheck of In this configuration, we will filter `A` and `AAAA` records, store maximum 1000 records in cache, and start recheck of
each record in cache for every 3 seconds via http client. The plugin will check records with name each record in cache for every 3 seconds via http client. The plugin will check records with name
fs.neo.org (`@` in config) or cdn.fs.neo.org (`^cdn\.fs\.neo\.org` in config). frostfs.info (`@` in config) or cdn.frostfs.info (`^cdn\.frostfs\.info` in config).
HTTP requests to check and update statuses of IPs will use default 80 port and wait for default 2 seconds. HTTP requests to check and update statuses of IPs will use default 80 port and wait for default 2 seconds.
``` corefile ``` corefile
fs.neo.org. { frostfs.info. {
healthchecker http 1000 1s @ ^cdn\.fs\.neo\.org healthchecker http 1000 1s @ ^cdn\.frostfs\.info
file db.example.org fs.neo.org file db.example.org frostfs.info
} }
``` ```
The same as above but port and timeout for HTTP client are set. The same as above but port and timeout for HTTP client are set.
``` corefile ``` corefile
fs.neo.org. { frostfs.info. {
healthchecker http 1000 1s @ ^cdn\.fs\.neo\.org { healthchecker http 1000 1s @ ^cdn\.frostfs\.info {
port 80 port 80
timeout 3s timeout 3s
} }
file db.example.org fs.neo.org file db.example.org frostfs.info
} }
``` ```
Default ICMP checker: Default ICMP checker:
``` ```
fs.neo.org. { frostfs.info. {
healthchecker icmp 1000 1s @ ^cdn\.fs\.neo\.org healthchecker icmp 1000 1s @ ^cdn\.frostfs\.info
file db.example.org fs.neo.org file db.example.org frostfs.info
} }
``` ```
Privileged ICMP checker and custom timeout: Privileged ICMP checker and custom timeout:
``` ```
fs.neo.org. { frostfs.info. {
healthchecker icmp 1000 1s @ ^cdn\.fs\.neo\.org { healthchecker icmp 1000 1s @ ^cdn\.frostfs\.info {
privileged privileged
timeout 3s timeout 3s
} }
file db.example.org fs.neo.org file db.example.org frostfs.info
} }
``` ```

View file

@ -11,7 +11,7 @@ import (
"github.com/coredns/coredns/plugin/pkg/log" "github.com/coredns/coredns/plugin/pkg/log"
) )
type HttpChecker struct { type HTTPChecker struct {
logger log.P logger log.P
client *http.Client client *http.Client
port string port string
@ -68,7 +68,7 @@ func ParseHTTPParams(c *caddy.Controller) (*HTTPCheckerParams, error) {
} }
// NewHttpChecker creates http checker. // NewHttpChecker creates http checker.
func NewHttpChecker(logger log.P, prm *HTTPCheckerParams) (*HttpChecker, error) { func NewHttpChecker(logger log.P, prm *HTTPCheckerParams) (*HTTPChecker, error) {
if prm.Timeout <= 0 { if prm.Timeout <= 0 {
prm.Timeout = defaultHTTPTimeout prm.Timeout = defaultHTTPTimeout
} }
@ -88,7 +88,7 @@ func NewHttpChecker(logger log.P, prm *HTTPCheckerParams) (*HttpChecker, error)
Timeout: prm.Timeout, Timeout: prm.Timeout,
} }
return &HttpChecker{ return &HTTPChecker{
logger: logger, logger: logger,
client: client, client: client,
port: prm.Port, port: prm.Port,
@ -96,7 +96,7 @@ func NewHttpChecker(logger log.P, prm *HTTPCheckerParams) (*HttpChecker, error)
}, nil }, nil
} }
func (h HttpChecker) Check(endpoint string) bool { func (h HTTPChecker) Check(endpoint string) bool {
response, err := h.client.Get(h.scheme + "://" + net.JoinHostPort(endpoint, h.port)) response, err := h.client.Get(h.scheme + "://" + net.JoinHostPort(endpoint, h.port))
if err != nil { if err != nil {
h.logger.Debugf(err.Error()) h.logger.Debugf(err.Error())

View file

@ -8,6 +8,7 @@ import (
"github.com/coredns/caddy" "github.com/coredns/caddy"
"github.com/coredns/coredns/plugin/pkg/log" "github.com/coredns/coredns/plugin/pkg/log"
"golang.org/x/net/icmp" "golang.org/x/net/icmp"
"golang.org/x/net/ipv4" "golang.org/x/net/ipv4"
"golang.org/x/net/ipv6" "golang.org/x/net/ipv6"

View file

@ -15,7 +15,6 @@ type (
cache *lru.Cache cache *lru.Cache
checker Checker checker Checker
interval time.Duration interval time.Duration
names map[string]struct{}
filters []Filter filters []Filter
} }
@ -84,7 +83,7 @@ func (p *HealthCheckFilter) FilterRecords(records []dns.RR) []dns.RR {
if matchFilters(p.filters, r.Header().Name) { if matchFilters(p.filters, r.Header().Name) {
endpoint, err := getEndpoint(r) endpoint, err := getEndpoint(r)
if err != nil { if err != nil {
log.Warningf("record will be ignored: %s", err.Error()) log.Debugf("record will be ignored: %s", err.Error())
continue continue
} }
e := p.get(endpoint) e := p.get(endpoint)

View file

@ -7,8 +7,8 @@ import (
) )
func TestFilter(t *testing.T) { func TestFilter(t *testing.T) {
f, err := NewRegexpFilter(".*\\.fs\\.neo\\.org") f, err := NewRegexpFilter(".*\\.frostfs\\.info")
require.NoError(t, err) require.NoError(t, err)
require.True(t, f.Match("cdn.fs.neo.org")) require.True(t, f.Match("cdn.frostfs.info"))
} }

View file

@ -5,6 +5,7 @@ import (
"github.com/coredns/coredns/plugin" "github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log" clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/miekg/dns" "github.com/miekg/dns"
) )

View file

@ -73,7 +73,7 @@ func filterParamsParse(c *caddy.Controller) (*HealthCheckFilter, error) {
} }
origin := URL.Hostname() origin := URL.Hostname()
//parsing cache size // parsing cache size
size, err := strconv.Atoi(args[1]) size, err := strconv.Atoi(args[1])
if err != nil || size <= 0 { if err != nil || size <= 0 {
return nil, plugin.Error(pluginName, fmt.Errorf("invalid cache size: %s", args[1])) return nil, plugin.Error(pluginName, fmt.Errorf("invalid cache size: %s", args[1]))

View file

@ -18,88 +18,88 @@ func TestSetup(t *testing.T) {
{args: "http", valid: false}, {args: "http", valid: false},
{args: "http 1000", valid: false}, {args: "http 1000", valid: false},
{args: "http 1000 1s", valid: false}, {args: "http 1000 1s", valid: false},
// http method params check, 100, 3s, fs.neo.org. are valid cache size, check interval and origin // http method params check, 100, 3s, frostfs.info. are valid cache size, check interval and origin
{args: "http 100 1s fs.neo.org. @", valid: true}, {args: "http 100 1s frostfs.info. @", valid: true},
{args: `http 100 1s fs.neo.org. { {args: `http 100 1s frostfs.info. {
port asdf port asdf
}`, valid: false}, }`, valid: false},
{args: `http 100 1s fs.neo.org. { {args: `http 100 1s frostfs.info. {
port 0 port 0
}`, valid: false}, }`, valid: false},
{args: `http 100 1s fs.neo.org. { {args: `http 100 1s frostfs.info. {
port -1 port -1
}`, valid: false}, }`, valid: false},
{args: `http 100 1s fs.neo.org. { {args: `http 100 1s frostfs.info. {
port 80 port 80
}`, valid: true}, }`, valid: true},
{args: `http 100 1s fs.neo.org. { {args: `http 100 1s frostfs.info. {
port 80 80 port 80 80
}`, valid: false}, }`, valid: false},
{args: `http 100 1s fs.neo.org. { {args: `http 100 1s frostfs.info. {
port 80 port 80
timeout 3s timeout 3s
}`, valid: true}, }`, valid: true},
{args: `http 100 1s fs.neo.org. { {args: `http 100 1s frostfs.info. {
port 80 port 80
timeout 3s 3s timeout 3s 3s
}`, valid: false}, }`, valid: false},
{args: `http 100 1s fs.neo.org. { {args: `http 100 1s frostfs.info. {
port 80 port 80
timeout 0 timeout 0
}`, valid: false}, }`, valid: false},
{args: `http 100 1s fs.neo.org. { {args: `http 100 1s frostfs.info. {
port 80 port 80
timeout seconds timeout seconds
}`, valid: false}, }`, valid: false},
// icmp method params check // icmp method params check
{args: "icmp 100 1s fs.neo.org. @", valid: true}, {args: "icmp 100 1s frostfs.info. @", valid: true},
{args: `icmp 100 1s fs.neo.org. { {args: `icmp 100 1s frostfs.info. {
timeout 3s timeout 3s
}`, valid: true}, }`, valid: true},
{args: `icmp 100 1s fs.neo.org. { {args: `icmp 100 1s frostfs.info. {
timeout 3s 3s timeout 3s 3s
}`, valid: false}, }`, valid: false},
{args: `icmp 100 1s fs.neo.org. { {args: `icmp 100 1s frostfs.info. {
timeout 0 timeout 0
}`, valid: false}, }`, valid: false},
{args: `icmp 100 1s fs.neo.org. { {args: `icmp 100 1s frostfs.info. {
timeout seconds timeout seconds
}`, valid: false}, }`, valid: false},
{args: `icmp 100 1s fs.neo.org. { {args: `icmp 100 1s frostfs.info. {
privileged privileged
}`, valid: true}, }`, valid: true},
{args: `icmp 100 1s fs.neo.org. { {args: `icmp 100 1s frostfs.info. {
privileged privileged
timeout 3s timeout 3s
}`, valid: true}, }`, valid: true},
{args: `icmp 100 1s fs.neo.org. { {args: `icmp 100 1s frostfs.info. {
privileged true privileged true
}`, valid: false}, }`, valid: false},
// cache size // cache size
{args: "http -1 1s fs.neo.org.", valid: false}, {args: "http -1 1s frostfs.info.", valid: false},
{args: "http 100a 1s fs.neo.org.", valid: false}, {args: "http 100a 1s frostfs.info.", valid: false},
{args: "http 0 1s fs.neo.org.", valid: false}, {args: "http 0 1s frostfs.info.", valid: false},
{args: "icmp -1 1s fs.neo.org.", valid: false}, {args: "icmp -1 1s frostfs.info.", valid: false},
{args: "icmp 100a 1s fs.neo.org.", valid: false}, {args: "icmp 100a 1s frostfs.info.", valid: false},
{args: "icmp 0 1s fs.neo.org.", valid: false}, {args: "icmp 0 1s frostfs.info.", valid: false},
// check interval, test with a valid value is above // check interval, test with a valid value is above
{args: "http 100 0h fs.neo.org.", valid: false}, {args: "http 100 0h frostfs.info.", valid: false},
{args: "http 100 100 fs.neo.org.", valid: false}, {args: "http 100 100 frostfs.info.", valid: false},
{args: "http 100 3000a fs.neo.org.", valid: false}, {args: "http 100 3000a frostfs.info.", valid: false},
{args: "http 100 -1m fs.neo.org.", valid: false}, {args: "http 100 -1m frostfs.info.", valid: false},
{args: "icmp 100 0h fs.neo.org.", valid: false}, {args: "icmp 100 0h frostfs.info.", valid: false},
{args: "icmp 100 100 fs.neo.org.", valid: false}, {args: "icmp 100 100 frostfs.info.", valid: false},
{args: "icmp 100 3000a fs.neo.org.", valid: false}, {args: "icmp 100 3000a frostfs.info.", valid: false},
{args: "icmp 100 -1m fs.neo.org.", valid: false}, {args: "icmp 100 -1m frostfs.info.", valid: false},
// origin, test with a valid value is above // origin, test with a valid value is above
{args: "http 100 3000 fs.neo.org", valid: false}, {args: "http 100 3000 frostfs.info", valid: false},
{args: "icmp 100 3000 fs.neo.org", valid: false}, {args: "icmp 100 3000 frostfs.info", valid: false},
// names // names
{args: "http 100 3m fs.neo.org. @ kimchi", valid: true}, {args: "http 100 3m frostfs.info. @ kimchi", valid: true},
{args: "http 100 3m fs.neo.org. ^cdn\\.fs\\.\\neo\\.org", valid: true}, {args: "http 100 3m frostfs.info. ^cdn\\.\\frostfs\\.info", valid: true},
{args: "http 100 3m \\uFFFD", valid: false}, {args: "http 100 3m \\uFFFD", valid: false},
{args: "icmp 100 3m fs.neo.org. @ kimchi", valid: true}, {args: "icmp 100 3m frostfs.info. @ kimchi", valid: true},
{args: "icmp 100 3m fs.neo.org. ^cdn\\.fs\\.\\neo\\.org", valid: true}, {args: "icmp 100 3m frostfs.info. ^cdn\\.\\frostfs\\.info", valid: true},
{args: "icmp 100 3m \\uFFFD", valid: false}, {args: "icmp 100 3m \\uFFFD", valid: false},
} { } {
c := caddy.NewTestController("dns", "healthchecker "+tc.args) c := caddy.NewTestController("dns", "healthchecker "+tc.args)