Skip to content

Commit bbcb79f

Browse files
committed
basic dns probing support
Signed-off-by: Kyle Quest <[email protected]>
1 parent 1a3f9aa commit bbcb79f

File tree

333 files changed

+35790
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

333 files changed

+35790
-150
lines changed

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ require (
134134
github.com/mattn/go-isatty v0.0.20 // indirect
135135
github.com/mattn/go-shellwords v1.0.12 // indirect
136136
github.com/mattn/go-sqlite3 v1.14.22 // indirect
137+
github.com/miekg/dns v1.1.59 // indirect
137138
github.com/miekg/pkcs11 v1.1.1 // indirect
138139
github.com/mistifyio/go-zfs/v3 v3.0.1 // indirect
139140
github.com/mitchellh/go-homedir v1.1.0 // indirect
@@ -187,13 +188,13 @@ require (
187188
go.opentelemetry.io/otel/trace v1.22.0 // indirect
188189
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
189190
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
190-
golang.org/x/mod v0.15.0 // indirect
191+
golang.org/x/mod v0.16.0 // indirect
191192
golang.org/x/oauth2 v0.18.0 // indirect
192193
golang.org/x/sync v0.6.0 // indirect
193194
golang.org/x/term v0.18.0 // indirect
194195
golang.org/x/text v0.14.0 // indirect
195196
golang.org/x/time v0.3.0 // indirect
196-
golang.org/x/tools v0.18.0 // indirect
197+
golang.org/x/tools v0.19.0 // indirect
197198
google.golang.org/appengine v1.6.8 // indirect
198199
google.golang.org/genproto v0.0.0-20231211222908-989df2bf70f3 // indirect
199200
google.golang.org/genproto/googleapis/rpc v0.0.0-20231212172506-995d672761c0 // indirect

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvr
457457
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
458458
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
459459
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
460+
github.com/miekg/dns v1.1.59 h1:C9EXc/UToRwKLhK5wKU/I4QVsBUc8kE6MkHBkeypWZs=
461+
github.com/miekg/dns v1.1.59/go.mod h1:nZpewl5p6IvctfgrckopVx2OlSEHPRO/U4SYkRklrEk=
460462
github.com/miekg/pkcs11 v1.1.1 h1:Ugu9pdy6vAYku5DEpVWVFPYnzV+bxB+iRdbuFSu7TvU=
461463
github.com/miekg/pkcs11 v1.1.1/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs=
462464
github.com/mistifyio/go-zfs/v3 v3.0.1 h1:YaoXgBePoMA12+S1u/ddkv+QqxcfiZK4prI6HPnkFiU=
@@ -734,6 +736,8 @@ golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91
734736
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
735737
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
736738
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
739+
golang.org/x/mod v0.16.0 h1:QX4fJ0Rr5cPQCF7O9lh9Se4pmwfwskqZfq5moyldzic=
740+
golang.org/x/mod v0.16.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
737741
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
738742
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
739743
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -866,6 +870,8 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
866870
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
867871
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
868872
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
873+
golang.org/x/tools v0.19.0 h1:tfGCXNR1OsFG+sVdLAitlpjAvD/I6dHDKnYrpEZUHkw=
874+
golang.org/x/tools v0.19.0/go.mod h1:qoJWxmGSIBmAeriMx19ogtrEPrGtDbPK634QFIcLAhc=
869875
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
870876
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
871877
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

pkg/app/master/probe/http/custom_probe.go

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ const (
2727
defaultHTTPPortStr = "80"
2828
defaultHTTPSPortStr = "443"
2929
defaultFastCGIPortStr = "9000"
30-
31-
//other protocols (todo: refactor)
32-
defaultRedisPortStr = "6379"
3330
)
3431

3532
type ovars = app.OutVars
@@ -392,7 +389,56 @@ func (p *CustomProbe) Start() {
392389

393390
time.Sleep(1 * time.Second)
394391
}
395-
continue
392+
393+
if p.OkCount > 0 {
394+
continue
395+
}
396+
} else if (found && dstPort == defaultDNSPortStr) || port == defaultDNSPortStr {
397+
//NOTE: a hacky way to support the DNS protocol
398+
//TODO: refactor and have a flag to disable this port-based behavior
399+
maxRetryCount := probeRetryCount
400+
if p.opts.RetryCount > 0 {
401+
maxRetryCount = p.opts.RetryCount
402+
}
403+
404+
for i := 0; i < maxRetryCount; i++ {
405+
//NOTE: use 'tcp', but later add support for 'udp' when probes support UDP
406+
output, err := dnsPing(context.Background(), p.targetHost, port, true)
407+
p.CallCount++
408+
409+
statusCode := "error"
410+
callErrorStr := "none"
411+
if err == nil {
412+
statusCode = "ok"
413+
} else {
414+
callErrorStr = err.Error()
415+
}
416+
417+
if p.printState {
418+
p.xc.Out.Info("dns.probe.call",
419+
ovars{
420+
"status": statusCode,
421+
"output": output,
422+
"port": port,
423+
"attempt": i + 1,
424+
"error": callErrorStr,
425+
"time": time.Now().UTC().Format(time.RFC3339),
426+
})
427+
}
428+
429+
if err == nil {
430+
p.OkCount++
431+
break
432+
} else {
433+
p.ErrCount++
434+
}
435+
436+
time.Sleep(1 * time.Second)
437+
}
438+
439+
if p.OkCount > 0 {
440+
continue
441+
}
396442
}
397443

398444
//If it's ok stop after the first successful probe pass

pkg/app/master/probe/http/dns.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package http
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/miekg/dns"
8+
9+
"github.com/mintoolkit/mint/pkg/util/jsonutil"
10+
)
11+
12+
const (
13+
defaultDNSPortStr = "53"
14+
)
15+
16+
var dnsReqBindVersion = &dns.Msg{
17+
MsgHdr: dns.MsgHdr{
18+
Id: dns.Id(),
19+
RecursionDesired: true,
20+
},
21+
Question: []dns.Question{
22+
{
23+
Name: dns.Fqdn("version.bind"),
24+
Qtype: dns.TypeTXT,
25+
Qclass: dns.ClassCHAOS,
26+
},
27+
},
28+
}
29+
30+
var dnsReqWhoami = &dns.Msg{
31+
MsgHdr: dns.MsgHdr{
32+
Id: dns.Id(),
33+
RecursionDesired: true,
34+
},
35+
Question: []dns.Question{
36+
{
37+
Name: dns.Fqdn("whoami.example.org"),
38+
Qtype: dns.TypeA,
39+
Qclass: dns.ClassINET,
40+
},
41+
},
42+
}
43+
44+
// all DNS servers should respond to the NS query for the root zone
45+
var dnsReqRootNS = &dns.Msg{
46+
MsgHdr: dns.MsgHdr{
47+
Id: dns.Id(),
48+
RecursionDesired: true,
49+
},
50+
Question: []dns.Question{
51+
{
52+
Name: dns.Fqdn("."),
53+
Qtype: dns.TypeNS,
54+
Qclass: dns.ClassINET,
55+
},
56+
},
57+
}
58+
59+
func dnsPing(ctx context.Context, targetHost string, port string, useTCP bool) (string, error) {
60+
addr := fmt.Sprintf("%s:%s", targetHost, port)
61+
client := &dns.Client{}
62+
63+
if useTCP {
64+
client.Net = "tcp"
65+
}
66+
67+
resp, _, err := client.ExchangeContext(ctx, dnsReqRootNS, addr)
68+
if err != nil {
69+
return "", err
70+
}
71+
72+
return jsonutil.ToString(resp), nil
73+
}

pkg/app/master/probe/http/redis.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import (
66
"net"
77
)
88

9-
const redisPingReq = "*1\r\n$4\r\nPING\r\n"
9+
const (
10+
defaultRedisPortStr = "6379"
11+
redisPingReq = "*1\r\n$4\r\nPING\r\n"
12+
)
1013

1114
func redisPing(targetHost string, port string) (string, error) {
1215
addr := fmt.Sprintf("%s:%s", targetHost, port)

vendor/github.com/miekg/dns/.codecov.yml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/miekg/dns/.gitignore

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/miekg/dns/AUTHORS

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/miekg/dns/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/miekg/dns/CONTRIBUTORS

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)