mirror of
https://github.com/hanzoai/dns.git
synced 2026-10-30 18:40:55 +00:00
The mechanical migration (9b8e9a14b) left the tree uncompilable: it used
luxfi/metric as a prometheus drop-in, but several symbols were missing and a
few types were misused. Finish it against luxfi/metric v1.8.2 (which adds the
prometheus-compat surface):
- pin luxfi/metric v1.8.2 (native-histogram HistogramOpts fields, package
MustRegister/Unregister, AlreadyRegisteredError, With/AutoFactory,
GoCollectorOption/MetricsAll, Vec.Delete, no-op collector registration)
- use metric.Registry / metric.{Histogram,Counter}Vec as INTERFACES, not
concrete pointers (plugin/metrics, plugin/kubernetes)
- build with -tags metrics so luxfi/metric's collecting registry is active
(the default is a //go:build metrics no-op stub); wire it into Makefile
GOTAGS, the GHCR image build, and the CI test matrix
- test harness: select a metric-name validation scheme for the exposition
parser (client_golang used to set the global default; CoreDNS no longer
imports it)
go build ./... + go test -tags metrics ./plugin/metrics/... /kubernetes /reload
are green.
101 lines
2.3 KiB
Go
101 lines
2.3 KiB
Go
package vars
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/coredns/coredns/plugin/test"
|
|
"github.com/coredns/coredns/request"
|
|
|
|
"github.com/miekg/dns"
|
|
)
|
|
|
|
func TestReportWithOptions(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
question string
|
|
qtype uint16
|
|
edns0 bool
|
|
do bool
|
|
originalSize int
|
|
useOriginal bool
|
|
}{
|
|
{
|
|
name: "A record without DO bit",
|
|
question: "example.org.",
|
|
qtype: dns.TypeA,
|
|
edns0: true,
|
|
do: false,
|
|
originalSize: 0,
|
|
useOriginal: false,
|
|
},
|
|
{
|
|
name: "A record with DO bit",
|
|
question: "example.org.",
|
|
qtype: dns.TypeA,
|
|
edns0: true,
|
|
do: true,
|
|
originalSize: 0,
|
|
useOriginal: false,
|
|
},
|
|
{
|
|
name: "A record with original size",
|
|
question: "example.org.",
|
|
qtype: dns.TypeA,
|
|
edns0: false,
|
|
do: false,
|
|
originalSize: 42,
|
|
useOriginal: true,
|
|
},
|
|
{
|
|
name: "A record bogus qtype",
|
|
question: "example.org.",
|
|
qtype: 0, // does not exist
|
|
edns0: false,
|
|
do: false,
|
|
originalSize: 42,
|
|
useOriginal: true,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
m := new(dns.Msg)
|
|
m.SetQuestion(tc.question, tc.qtype)
|
|
if tc.edns0 {
|
|
m.SetEdns0(4096, tc.do)
|
|
}
|
|
|
|
w := &test.ResponseWriter{}
|
|
state := request.Request{W: w, Req: m}
|
|
|
|
if state.Do() != tc.do {
|
|
t.Errorf("DO bit detection failed, got %v, want %v", state.Do(), tc.do)
|
|
}
|
|
|
|
qType := qTypeString(tc.qtype)
|
|
expectedType := dns.Type(tc.qtype).String()
|
|
if qType != expectedType && qType != "other" {
|
|
t.Errorf("qTypeString(%d) = %s, want %s or 'other'", tc.qtype, qType, expectedType)
|
|
}
|
|
|
|
var opts []ReportOption
|
|
if tc.useOriginal {
|
|
opts = append(opts, WithOriginalReqSize(tc.originalSize))
|
|
}
|
|
|
|
net := state.Proto()
|
|
fam := "1"
|
|
|
|
countBefore := RequestCount.WithLabelValues("dns://:53", "example.org.", "", net, fam, qType).Get()
|
|
|
|
Report("dns://:53", state, "example.org.", "", "NOERROR", "test", 100, time.Now(), opts...)
|
|
|
|
countAfter := RequestCount.WithLabelValues("dns://:53", "example.org.", "", net, fam, qType).Get()
|
|
if countAfter <= countBefore {
|
|
t.Errorf("RequestCount was not incremented. Before: %f, After: %f", countBefore, countAfter)
|
|
}
|
|
})
|
|
}
|
|
}
|