mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	* Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * Fix linter errors * More linting fixes * More docs and making members private that dont need to be public * More lint fixes This leaves: ~~~ middleware/kubernetes/nametemplate/nametemplate.go:64:6: exported type NameTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:71:1: exported method NameTemplate.SetTemplate should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:108:1: exported method NameTemplate.GetZoneFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:116:1: exported method NameTemplate.GetNamespaceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:120:1: exported method NameTemplate.GetServiceFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:124:1: exported method NameTemplate.GetTypeFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:135:1: exported method NameTemplate.GetSymbolFromSegmentArray should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:167:1: exported method NameTemplate.IsValid should have comment or be unexported middleware/kubernetes/nametemplate/nametemplate.go:182:6: exported type NameValues should have comment or be unexported middleware/kubernetes/util/util.go:1:1: package comment should be of the form "Package util ..." middleware/kubernetes/util/util.go:27:2: exported const WildcardStar should have comment (or a comment on this block) or be unexported middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported ~~~ I plan on reworking the proxy anyway, so I'll leave that be.
		
			
				
	
	
		
			97 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			97 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package metrics
 | 
						|
 | 
						|
import (
 | 
						|
	"time"
 | 
						|
 | 
						|
	"github.com/miekg/coredns/middleware"
 | 
						|
	"github.com/miekg/coredns/middleware/pkg/dnsrecorder"
 | 
						|
	"github.com/miekg/coredns/middleware/pkg/rcode"
 | 
						|
	"github.com/miekg/coredns/request"
 | 
						|
 | 
						|
	"github.com/miekg/dns"
 | 
						|
	"golang.org/x/net/context"
 | 
						|
)
 | 
						|
 | 
						|
// ServeDNS implements the Handler interface.
 | 
						|
func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
 | 
						|
	state := request.Request{W: w, Req: r}
 | 
						|
 | 
						|
	qname := state.QName()
 | 
						|
	zone := middleware.Zones(m.ZoneNames).Matches(qname)
 | 
						|
	if zone == "" {
 | 
						|
		zone = "."
 | 
						|
	}
 | 
						|
 | 
						|
	// Record response to get status code and size of the reply.
 | 
						|
	rw := dnsrecorder.New(w)
 | 
						|
	status, err := m.Next.ServeDNS(ctx, rw, r)
 | 
						|
 | 
						|
	Report(state, zone, rcode.ToString(rw.Rcode), rw.Size, rw.Start)
 | 
						|
 | 
						|
	return status, err
 | 
						|
}
 | 
						|
 | 
						|
// Report is a plain reporting function that the server can use for REFUSED and other
 | 
						|
// queries that are turned down because they don't match any middleware.
 | 
						|
func Report(req request.Request, zone, rcode string, size int, start time.Time) {
 | 
						|
	if requestCount == nil {
 | 
						|
		// no metrics are enabled
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	// Proto and Family
 | 
						|
	net := req.Proto()
 | 
						|
	fam := "1"
 | 
						|
	if req.Family() == 2 {
 | 
						|
		fam = "2"
 | 
						|
	}
 | 
						|
 | 
						|
	typ := req.QType()
 | 
						|
 | 
						|
	requestCount.WithLabelValues(zone, net, fam).Inc()
 | 
						|
	requestDuration.WithLabelValues(zone).Observe(float64(time.Since(start) / time.Millisecond))
 | 
						|
 | 
						|
	if req.Do() {
 | 
						|
		requestDo.WithLabelValues(zone).Inc()
 | 
						|
	}
 | 
						|
 | 
						|
	if _, known := monitorType[typ]; known {
 | 
						|
		requestType.WithLabelValues(zone, dns.Type(typ).String()).Inc()
 | 
						|
	} else {
 | 
						|
		requestType.WithLabelValues(zone, other).Inc()
 | 
						|
	}
 | 
						|
 | 
						|
	if typ == dns.TypeIXFR || typ == dns.TypeAXFR {
 | 
						|
		responseTransferSize.WithLabelValues(zone, net).Observe(float64(size))
 | 
						|
		requestTransferSize.WithLabelValues(zone, net).Observe(float64(req.Size()))
 | 
						|
	} else {
 | 
						|
		responseSize.WithLabelValues(zone, net).Observe(float64(size))
 | 
						|
		requestSize.WithLabelValues(zone, net).Observe(float64(req.Size()))
 | 
						|
	}
 | 
						|
 | 
						|
	responseRcode.WithLabelValues(zone, rcode).Inc()
 | 
						|
}
 | 
						|
 | 
						|
var monitorType = map[uint16]bool{
 | 
						|
	dns.TypeAAAA:   true,
 | 
						|
	dns.TypeA:      true,
 | 
						|
	dns.TypeCNAME:  true,
 | 
						|
	dns.TypeDNSKEY: true,
 | 
						|
	dns.TypeDS:     true,
 | 
						|
	dns.TypeMX:     true,
 | 
						|
	dns.TypeNSEC3:  true,
 | 
						|
	dns.TypeNSEC:   true,
 | 
						|
	dns.TypeNS:     true,
 | 
						|
	dns.TypePTR:    true,
 | 
						|
	dns.TypeRRSIG:  true,
 | 
						|
	dns.TypeSOA:    true,
 | 
						|
	dns.TypeSRV:    true,
 | 
						|
	dns.TypeTXT:    true,
 | 
						|
	// Meta Qtypes
 | 
						|
	dns.TypeIXFR: true,
 | 
						|
	dns.TypeAXFR: true,
 | 
						|
	dns.TypeANY:  true,
 | 
						|
}
 | 
						|
 | 
						|
const other = "other"
 |