mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -04:00
core: remove HostAddresses() (#1728)
* core: remove HostAddresses() config.HostAddresses() is a weird function that gathers some data from the server and returns a string. It is *only* used the trace plugin, to figure out what server starts the trace. Looks to be better to fit in the with metrics.WithServer label on the trace itself to show which server handled the trace. Remove HostAddresses() and cleanup trace a small bit.:w * lint
This commit is contained in:
@@ -3,7 +3,6 @@ package dnsserver
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
|
||||||
@@ -53,22 +52,6 @@ type Config struct {
|
|||||||
registry map[string]plugin.Handler
|
registry map[string]plugin.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
//HostAddresses builds a representation of the addresses of this Config
|
|
||||||
//after server is started ONLY, can be used as a Key for identifing that config
|
|
||||||
// :53 or 127.0.0.1:53 or 127.0.0.1:53/::1:53
|
|
||||||
func (c *Config) HostAddresses() string {
|
|
||||||
all := ""
|
|
||||||
for _, h := range c.ListenHosts {
|
|
||||||
addr := net.JoinHostPort(h, c.Port)
|
|
||||||
if all == "" {
|
|
||||||
all = addr
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
all = all + "/" + addr
|
|
||||||
}
|
|
||||||
return all
|
|
||||||
}
|
|
||||||
|
|
||||||
// keyForConfig build a key for identifying the configs during setup time
|
// keyForConfig build a key for identifying the configs during setup time
|
||||||
func keyForConfig(blocIndex int, blocKeyIndex int) string {
|
func keyForConfig(blocIndex int, blocKeyIndex int) string {
|
||||||
return fmt.Sprintf("%d:%d", blocIndex, blocKeyIndex)
|
return fmt.Sprintf("%d:%d", blocIndex, blocKeyIndex)
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ func traceParse(c *caddy.Controller) (*trace, error) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
cfg := dnsserver.GetConfig(c)
|
cfg := dnsserver.GetConfig(c)
|
||||||
tr.ServiceEndpoint = cfg.HostAddresses()
|
tr.serviceEndpoint = cfg.ListenHosts[0] + ":" + cfg.Port
|
||||||
|
|
||||||
for c.Next() { // trace
|
for c.Next() { // trace
|
||||||
var err error
|
var err error
|
||||||
args := c.RemainingArgs()
|
args := c.RemainingArgs()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin"
|
"github.com/coredns/coredns/plugin"
|
||||||
|
"github.com/coredns/coredns/plugin/metrics"
|
||||||
// Plugin the trace package.
|
// Plugin the trace package.
|
||||||
_ "github.com/coredns/coredns/plugin/pkg/trace"
|
_ "github.com/coredns/coredns/plugin/pkg/trace"
|
||||||
|
|
||||||
@@ -20,10 +21,10 @@ import (
|
|||||||
|
|
||||||
type trace struct {
|
type trace struct {
|
||||||
Next plugin.Handler
|
Next plugin.Handler
|
||||||
ServiceEndpoint string
|
|
||||||
Endpoint string
|
Endpoint string
|
||||||
EndpointType string
|
EndpointType string
|
||||||
tracer ot.Tracer
|
tracer ot.Tracer
|
||||||
|
serviceEndpoint string
|
||||||
serviceName string
|
serviceName string
|
||||||
clientServer bool
|
clientServer bool
|
||||||
every uint64
|
every uint64
|
||||||
@@ -58,7 +59,7 @@ func (t *trace) setupZipkin() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
recorder := zipkin.NewRecorder(collector, false, t.ServiceEndpoint, t.serviceName)
|
recorder := zipkin.NewRecorder(collector, false, t.serviceEndpoint, t.serviceName)
|
||||||
t.tracer, err = zipkin.NewTracer(recorder, zipkin.ClientServerSameSpan(t.clientServer))
|
t.tracer, err = zipkin.NewTracer(recorder, zipkin.ClientServerSameSpan(t.clientServer))
|
||||||
|
|
||||||
return err
|
return err
|
||||||
@@ -81,9 +82,7 @@ func (t *trace) setupDatadog() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Name implements the Handler interface.
|
// Name implements the Handler interface.
|
||||||
func (t *trace) Name() string {
|
func (t *trace) Name() string { return "trace" }
|
||||||
return "trace"
|
|
||||||
}
|
|
||||||
|
|
||||||
// ServeDNS implements the plugin.Handle interface.
|
// ServeDNS implements the plugin.Handle interface.
|
||||||
func (t *trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
func (t *trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||||
@@ -96,7 +95,7 @@ func (t *trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if span := ot.SpanFromContext(ctx); span == nil && trace {
|
if span := ot.SpanFromContext(ctx); span == nil && trace {
|
||||||
span := t.Tracer().StartSpan("servedns")
|
span := t.Tracer().StartSpan("servedns:" + metrics.WithServer(ctx))
|
||||||
defer span.Finish()
|
defer span.Finish()
|
||||||
ctx = ot.ContextWithSpan(ctx, span)
|
ctx = ot.ContextWithSpan(ctx, span)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user