[#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
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.
``` corefile
fs.neo.org. {
healthchecker http 1000 1s @ ^cdn\.fs\.neo\.org
file db.example.org fs.neo.org
frostfs.info. {
healthchecker http 1000 1s @ ^cdn\.frostfs\.info
file db.example.org frostfs.info
}
```
The same as above but port and timeout for HTTP client are set.
``` corefile
fs.neo.org. {
healthchecker http 1000 1s @ ^cdn\.fs\.neo\.org {
frostfs.info. {
healthchecker http 1000 1s @ ^cdn\.frostfs\.info {
port 80
timeout 3s
}
file db.example.org fs.neo.org
file db.example.org frostfs.info
}
```
Default ICMP checker:
```
fs.neo.org. {
healthchecker icmp 1000 1s @ ^cdn\.fs\.neo\.org
file db.example.org fs.neo.org
frostfs.info. {
healthchecker icmp 1000 1s @ ^cdn\.frostfs\.info
file db.example.org frostfs.info
}
```
Privileged ICMP checker and custom timeout:
```
fs.neo.org. {
healthchecker icmp 1000 1s @ ^cdn\.fs\.neo\.org {
frostfs.info. {
healthchecker icmp 1000 1s @ ^cdn\.frostfs\.info {
privileged
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"
)
type HttpChecker struct {
type HTTPChecker struct {
logger log.P
client *http.Client
port string
@ -68,7 +68,7 @@ func ParseHTTPParams(c *caddy.Controller) (*HTTPCheckerParams, error) {
}
// 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 {
prm.Timeout = defaultHTTPTimeout
}
@ -88,7 +88,7 @@ func NewHttpChecker(logger log.P, prm *HTTPCheckerParams) (*HttpChecker, error)
Timeout: prm.Timeout,
}
return &HttpChecker{
return &HTTPChecker{
logger: logger,
client: client,
port: prm.Port,
@ -96,7 +96,7 @@ func NewHttpChecker(logger log.P, prm *HTTPCheckerParams) (*HttpChecker, error)
}, 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))
if err != nil {
h.logger.Debugf(err.Error())

View file

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

View file

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

View file

@ -7,8 +7,8 @@ import (
)
func TestFilter(t *testing.T) {
f, err := NewRegexpFilter(".*\\.fs\\.neo\\.org")
f, err := NewRegexpFilter(".*\\.frostfs\\.info")
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"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/miekg/dns"
)

View file

@ -73,7 +73,7 @@ func filterParamsParse(c *caddy.Controller) (*HealthCheckFilter, error) {
}
origin := URL.Hostname()
//parsing cache size
// parsing cache size
size, err := strconv.Atoi(args[1])
if err != nil || size <= 0 {
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 1000", 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
{args: "http 100 1s fs.neo.org. @", valid: true},
{args: `http 100 1s fs.neo.org. {
// http method params check, 100, 3s, frostfs.info. are valid cache size, check interval and origin
{args: "http 100 1s frostfs.info. @", valid: true},
{args: `http 100 1s frostfs.info. {
port asdf
}`, valid: false},
{args: `http 100 1s fs.neo.org. {
{args: `http 100 1s frostfs.info. {
port 0
}`, valid: false},
{args: `http 100 1s fs.neo.org. {
{args: `http 100 1s frostfs.info. {
port -1
}`, valid: false},
{args: `http 100 1s fs.neo.org. {
{args: `http 100 1s frostfs.info. {
port 80
}`, valid: true},
{args: `http 100 1s fs.neo.org. {
{args: `http 100 1s frostfs.info. {
port 80 80
}`, valid: false},
{args: `http 100 1s fs.neo.org. {
{args: `http 100 1s frostfs.info. {
port 80
timeout 3s
}`, valid: true},
{args: `http 100 1s fs.neo.org. {
{args: `http 100 1s frostfs.info. {
port 80
timeout 3s 3s
}`, valid: false},
{args: `http 100 1s fs.neo.org. {
{args: `http 100 1s frostfs.info. {
port 80
timeout 0
}`, valid: false},
{args: `http 100 1s fs.neo.org. {
{args: `http 100 1s frostfs.info. {
port 80
timeout seconds
}`, valid: false},
// icmp method params check
{args: "icmp 100 1s fs.neo.org. @", valid: true},
{args: `icmp 100 1s fs.neo.org. {
{args: "icmp 100 1s frostfs.info. @", valid: true},
{args: `icmp 100 1s frostfs.info. {
timeout 3s
}`, valid: true},
{args: `icmp 100 1s fs.neo.org. {
{args: `icmp 100 1s frostfs.info. {
timeout 3s 3s
}`, valid: false},
{args: `icmp 100 1s fs.neo.org. {
{args: `icmp 100 1s frostfs.info. {
timeout 0
}`, valid: false},
{args: `icmp 100 1s fs.neo.org. {
{args: `icmp 100 1s frostfs.info. {
timeout seconds
}`, valid: false},
{args: `icmp 100 1s fs.neo.org. {
{args: `icmp 100 1s frostfs.info. {
privileged
}`, valid: true},
{args: `icmp 100 1s fs.neo.org. {
{args: `icmp 100 1s frostfs.info. {
privileged
timeout 3s
}`, valid: true},
{args: `icmp 100 1s fs.neo.org. {
{args: `icmp 100 1s frostfs.info. {
privileged true
}`, valid: false},
// cache size
{args: "http -1 1s fs.neo.org.", valid: false},
{args: "http 100a 1s fs.neo.org.", valid: false},
{args: "http 0 1s fs.neo.org.", valid: false},
{args: "icmp -1 1s fs.neo.org.", valid: false},
{args: "icmp 100a 1s fs.neo.org.", valid: false},
{args: "icmp 0 1s fs.neo.org.", valid: false},
{args: "http -1 1s frostfs.info.", valid: false},
{args: "http 100a 1s frostfs.info.", valid: false},
{args: "http 0 1s frostfs.info.", valid: false},
{args: "icmp -1 1s frostfs.info.", valid: false},
{args: "icmp 100a 1s frostfs.info.", valid: false},
{args: "icmp 0 1s frostfs.info.", valid: false},
// check interval, test with a valid value is above
{args: "http 100 0h fs.neo.org.", valid: false},
{args: "http 100 100 fs.neo.org.", valid: false},
{args: "http 100 3000a fs.neo.org.", valid: false},
{args: "http 100 -1m fs.neo.org.", valid: false},
{args: "icmp 100 0h fs.neo.org.", valid: false},
{args: "icmp 100 100 fs.neo.org.", valid: false},
{args: "icmp 100 3000a fs.neo.org.", valid: false},
{args: "icmp 100 -1m fs.neo.org.", valid: false},
{args: "http 100 0h frostfs.info.", valid: false},
{args: "http 100 100 frostfs.info.", valid: false},
{args: "http 100 3000a frostfs.info.", valid: false},
{args: "http 100 -1m frostfs.info.", valid: false},
{args: "icmp 100 0h frostfs.info.", valid: false},
{args: "icmp 100 100 frostfs.info.", valid: false},
{args: "icmp 100 3000a frostfs.info.", valid: false},
{args: "icmp 100 -1m frostfs.info.", valid: false},
// origin, test with a valid value is above
{args: "http 100 3000 fs.neo.org", valid: false},
{args: "icmp 100 3000 fs.neo.org", valid: false},
{args: "http 100 3000 frostfs.info", valid: false},
{args: "icmp 100 3000 frostfs.info", valid: false},
// names
{args: "http 100 3m fs.neo.org. @ kimchi", valid: true},
{args: "http 100 3m fs.neo.org. ^cdn\\.fs\\.\\neo\\.org", valid: true},
{args: "http 100 3m frostfs.info. @ kimchi", valid: true},
{args: "http 100 3m frostfs.info. ^cdn\\.\\frostfs\\.info", valid: true},
{args: "http 100 3m \\uFFFD", valid: false},
{args: "icmp 100 3m fs.neo.org. @ kimchi", valid: true},
{args: "icmp 100 3m fs.neo.org. ^cdn\\.fs\\.\\neo\\.org", valid: true},
{args: "icmp 100 3m frostfs.info. @ kimchi", valid: true},
{args: "icmp 100 3m frostfs.info. ^cdn\\.\\frostfs\\.info", valid: true},
{args: "icmp 100 3m \\uFFFD", valid: false},
} {
c := caddy.NewTestController("dns", "healthchecker "+tc.args)