Skip to content

Commit

Permalink
Add probe_dns_target_reachable metric
Browse files Browse the repository at this point in the history
Currently, one may not be able to differentiate between a query refusal
by the target and the target not responding to a query. These two cases
can have very different ramifications.

This patch adds the probe_dns_target_reachable gauge which is 1 if and
only if the DNS query was executed correctly, i.e., that the target
host is reachable and has sent a response, and 0 otherwise.

Resolves #474

Signed-off-by: Daniel Teunis <[email protected]>
  • Loading branch information
danteu committed Nov 25, 2022
1 parent 7554eef commit 409239b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
6 changes: 6 additions & 0 deletions prober/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry
Name: "probe_dns_additional_rrs",
Help: "Returns number of entries in the additional resource record list",
})
probeDNSTargetReachable := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_dns_target_reachable",
Help: "Displays whether or not the connection to the target was established",
})

for _, lv := range []string{"resolve", "connect", "request"} {
probeDNSDurationGaugeVec.WithLabelValues(lv)
Expand All @@ -151,6 +155,7 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry
registry.MustRegister(probeDNSAnswerRRSGauge)
registry.MustRegister(probeDNSAuthorityRRSGauge)
registry.MustRegister(probeDNSAdditionalRRSGauge)
registry.MustRegister(probeDNSTargetReachable)

qc := uint16(dns.ClassINET)
if module.DNS.QueryClass != "" {
Expand Down Expand Up @@ -274,6 +279,7 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry
probeDNSAnswerRRSGauge.Set(float64(len(response.Answer)))
probeDNSAuthorityRRSGauge.Set(float64(len(response.Ns)))
probeDNSAdditionalRRSGauge.Set(float64(len(response.Extra)))
probeDNSTargetReachable.Set(1)

if qt == dns.TypeSOA {
probeDNSSOAGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Expand Down
34 changes: 22 additions & 12 deletions prober/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ func TestRecursiveDNSResponse(t *testing.T) {
t.Fatal(err)
}
expectedResults := map[string]float64{
"probe_dns_answer_rrs": 2,
"probe_dns_authority_rrs": 0,
"probe_dns_additional_rrs": 0,
"probe_dns_answer_rrs": 2,
"probe_dns_authority_rrs": 0,
"probe_dns_additional_rrs": 0,
"probe_dns_target_reachable": 1,
}
if !test.Probe.Recursion {
expectedResults["probe_dns_answer_rrs"] = 0
Expand Down Expand Up @@ -382,9 +383,10 @@ func TestAuthoritativeDNSResponse(t *testing.T) {
t.Fatal(err)
}
expectedResults := map[string]float64{
"probe_dns_answer_rrs": 1,
"probe_dns_authority_rrs": 2,
"probe_dns_additional_rrs": 3,
"probe_dns_answer_rrs": 1,
"probe_dns_authority_rrs": 2,
"probe_dns_additional_rrs": 3,
"probe_dns_target_reachable": 1,
}
if test.Probe.QueryType == "SOA" {
expectedResults["probe_dns_serial"] = 1000
Expand Down Expand Up @@ -456,10 +458,17 @@ func TestServfailDNSResponse(t *testing.T) {
t.Fatal(err)
}
expectedResults := map[string]float64{
"probe_dns_answer_rrs": 0,
"probe_dns_authority_rrs": 0,
"probe_dns_additional_rrs": 0,
"probe_dns_answer_rrs": 0,
"probe_dns_authority_rrs": 0,
"probe_dns_additional_rrs": 0,
"probe_dns_target_reachable": 1,
}

// Handle case where ProbeDNS fails before executing the query because of an invalid query type
if test.Probe.QueryType == "NOT_A_VALID_QUERY_TYPE" {
expectedResults["probe_dns_target_reachable"] = 0
}

checkRegistryResults(expectedResults, mfs, t)
}
}
Expand Down Expand Up @@ -638,9 +647,10 @@ func TestDNSMetrics(t *testing.T) {
"request": {},
},
},
"probe_dns_answer_rrs": nil,
"probe_dns_authority_rrs": nil,
"probe_dns_additional_rrs": nil,
"probe_dns_answer_rrs": nil,
"probe_dns_authority_rrs": nil,
"probe_dns_additional_rrs": nil,
"probe_dns_target_reachable": nil,
}

checkMetrics(expectedMetrics, mfs, t)
Expand Down

0 comments on commit 409239b

Please sign in to comment.