Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
0835f5bb
Commit
0835f5bb
authored
Oct 12, 2020
by
Bob
Committed by
GitHub
Oct 12, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[plugin][trace] - Have a consistent spanName (#4171)
Automatically submitted.
parent
5f5cc318
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
27 deletions
+61
-27
plugin/trace/README.md
plugin/trace/README.md
+12
-3
plugin/trace/setup.go
plugin/trace/setup.go
+15
-0
plugin/trace/setup_test.go
plugin/trace/setup_test.go
+2
-0
plugin/trace/trace.go
plugin/trace/trace.go
+29
-22
plugin/trace/trace_test.go
plugin/trace/trace_test.go
+3
-2
No files found.
plugin/trace/README.md
View file @
0835f5bb
...
...
@@ -28,9 +28,16 @@ Additional features can be enabled with this syntax:
~~~
trace [ENDPOINT-TYPE] [ENDPOINT] {
every AMOUNT
service NAME
client_server
every AMOUNT
service NAME
client_server
}
~~~
~~~
trace datadog {
every AMOUNT
service NAME
datadog_analytics_rate RATE
}
~~~
...
...
@@ -39,6 +46,8 @@ trace [ENDPOINT-TYPE] [ENDPOINT] {
*
`service`
**NAME**
allows you to specify the service name reported to the tracing server.
Default is
`coredns`
.
*
`client_server`
will enable the
`ClientServerSameSpan`
OpenTracing feature.
*
`datadog_analytics_rate`
**RATE**
will enable
[
trace analytics
](
https://docs.datadoghq.com/tracing/app_analytics
)
on the traces sent
from
*0*
to
*1*
,
*1*
being every trace sent will be analyzed. This is a datadog only feature.
## Zipkin
You can run Zipkin on a Docker host like this:
...
...
plugin/trace/setup.go
View file @
0835f5bb
...
...
@@ -83,6 +83,21 @@ func traceParse(c *caddy.Controller) (*trace, error) {
if
err
!=
nil
{
return
nil
,
err
}
case
"datadog_analytics_rate"
:
args
:=
c
.
RemainingArgs
()
if
len
(
args
)
>
1
{
return
nil
,
c
.
ArgErr
()
}
tr
.
datadogAnalyticsRate
=
0
if
len
(
args
)
==
1
{
tr
.
datadogAnalyticsRate
,
err
=
strconv
.
ParseFloat
(
args
[
0
],
64
)
}
if
err
!=
nil
{
return
nil
,
err
}
if
tr
.
datadogAnalyticsRate
>
1
||
tr
.
datadogAnalyticsRate
<
0
{
return
nil
,
fmt
.
Errorf
(
"datadog analytics rate must be between 0 and 1, '%f' is not supported"
,
tr
.
datadogAnalyticsRate
)
}
}
}
}
...
...
plugin/trace/setup_test.go
View file @
0835f5bb
...
...
@@ -22,6 +22,7 @@ func TestTraceParse(t *testing.T) {
{
`trace zipkin localhost:1234`
,
false
,
"http://localhost:1234/api/v1/spans"
,
1
,
`coredns`
,
false
},
{
`trace datadog localhost`
,
false
,
"localhost"
,
1
,
`coredns`
,
false
},
{
`trace datadog http://localhost:8127`
,
false
,
"http://localhost:8127"
,
1
,
`coredns`
,
false
},
{
"trace datadog localhost {
\n
datadog_analytics_rate 0.1
\n
}"
,
false
,
"localhost"
,
1
,
`coredns`
,
false
},
{
"trace {
\n
every 100
\n
}"
,
false
,
"http://localhost:9411/api/v1/spans"
,
100
,
`coredns`
,
false
},
{
"trace {
\n
every 100
\n
service foobar
\n
client_server
\n
}"
,
false
,
"http://localhost:9411/api/v1/spans"
,
100
,
`foobar`
,
true
},
{
"trace {
\n
every 2
\n
client_server true
\n
}"
,
false
,
"http://localhost:9411/api/v1/spans"
,
2
,
`coredns`
,
true
},
...
...
@@ -29,6 +30,7 @@ func TestTraceParse(t *testing.T) {
// fails
{
`trace footype localhost:4321`
,
true
,
""
,
1
,
""
,
false
},
{
"trace {
\n
every 2
\n
client_server junk
\n
}"
,
true
,
""
,
1
,
""
,
false
},
{
"trace datadog localhost {
\n
datadog_analytics_rate 2
\n
}"
,
true
,
""
,
1
,
""
,
false
},
}
for
i
,
test
:=
range
tests
{
c
:=
caddy
.
NewTestController
(
"dns"
,
test
.
input
)
...
...
plugin/trace/trace.go
View file @
0835f5bb
...
...
@@ -8,7 +8,6 @@ import (
"sync/atomic"
"github.com/coredns/coredns/plugin"
"github.com/coredns/coredns/plugin/metrics"
"github.com/coredns/coredns/plugin/pkg/dnstest"
"github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/plugin/pkg/rcode"
...
...
@@ -20,30 +19,33 @@ import (
zipkinot
"github.com/openzipkin-contrib/zipkin-go-opentracing"
"github.com/openzipkin/zipkin-go"
zipkinhttp
"github.com/openzipkin/zipkin-go/reporter/http"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
)
const
(
tagName
=
"coredns.io/name"
tagType
=
"coredns.io/type"
tagRcode
=
"coredns.io/rcode"
tagProto
=
"coredns.io/proto"
tagRemote
=
"coredns.io/remote"
tagName
=
"coredns.io/name"
tagType
=
"coredns.io/type"
tagRcode
=
"coredns.io/rcode"
tagProto
=
"coredns.io/proto"
tagRemote
=
"coredns.io/remote"
defaultTopLevelSpanName
=
"servedns"
)
type
trace
struct
{
count
uint64
// as per Go spec, needs to be first element in a struct
Next
plugin
.
Handler
Endpoint
string
EndpointType
string
tracer
ot
.
Tracer
serviceEndpoint
string
serviceName
string
clientServer
bool
every
uint64
Once
sync
.
Once
Next
plugin
.
Handler
Endpoint
string
EndpointType
string
tracer
ot
.
Tracer
serviceEndpoint
string
serviceName
string
clientServer
bool
every
uint64
datadogAnalyticsRate
float64
Once
sync
.
Once
}
func
(
t
*
trace
)
Tracer
()
ot
.
Tracer
{
...
...
@@ -58,7 +60,13 @@ func (t *trace) OnStartup() error {
case
"zipkin"
:
err
=
t
.
setupZipkin
()
case
"datadog"
:
tracer
:=
opentracer
.
New
(
tracer
.
WithAgentAddr
(
t
.
Endpoint
),
tracer
.
WithServiceName
(
t
.
serviceName
),
tracer
.
WithDebugMode
(
log
.
D
.
Value
()))
tracer
:=
opentracer
.
New
(
tracer
.
WithAgentAddr
(
t
.
Endpoint
),
tracer
.
WithDebugMode
(
log
.
D
.
Value
()),
tracer
.
WithGlobalTag
(
ext
.
SpanTypeDNS
,
true
),
tracer
.
WithServiceName
(
t
.
serviceName
),
tracer
.
WithAnalyticsRate
(
t
.
datadogAnalyticsRate
),
)
t
.
tracer
=
tracer
default
:
err
=
fmt
.
Errorf
(
"unknown endpoint type: %s"
,
t
.
EndpointType
)
...
...
@@ -73,7 +81,10 @@ func (t *trace) setupZipkin() error {
if
err
!=
nil
{
log
.
Warningf
(
"build Zipkin endpoint found err: %v"
,
err
)
}
tracer
,
err
:=
zipkin
.
NewTracer
(
reporter
,
zipkin
.
WithLocalEndpoint
(
recorder
))
tracer
,
err
:=
zipkin
.
NewTracer
(
reporter
,
zipkin
.
WithLocalEndpoint
(
recorder
),
)
if
err
!=
nil
{
return
err
}
...
...
@@ -100,7 +111,7 @@ func (t *trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
}
req
:=
request
.
Request
{
W
:
w
,
Req
:
r
}
span
=
t
.
Tracer
()
.
StartSpan
(
spanName
(
ctx
,
req
)
)
span
=
t
.
Tracer
()
.
StartSpan
(
defaultTopLevelSpanName
)
defer
span
.
Finish
()
rw
:=
dnstest
.
NewRecorder
(
w
)
...
...
@@ -115,7 +126,3 @@ func (t *trace) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
return
status
,
err
}
func
spanName
(
ctx
context
.
Context
,
req
request
.
Request
)
string
{
return
"servedns:"
+
metrics
.
WithServer
(
ctx
)
+
" "
+
req
.
Name
()
}
\ No newline at end of file
plugin/trace/trace_test.go
View file @
0835f5bb
...
...
@@ -79,9 +79,10 @@ func TestTrace(t *testing.T) {
rootSpan
:=
fs
[
1
]
req
:=
request
.
Request
{
W
:
w
,
Req
:
tc
.
question
}
if
rootSpan
.
OperationName
!=
spanName
(
ctx
,
req
)
{
t
.
Errorf
(
"Unexpected span name: rootSpan.Name: want %v, got %v"
,
spanName
(
ctx
,
req
)
,
rootSpan
.
OperationName
)
if
rootSpan
.
OperationName
!=
defaultTopLevelSpanName
{
t
.
Errorf
(
"Unexpected span name: rootSpan.Name: want %v, got %v"
,
defaultTopLevelSpanName
,
rootSpan
.
OperationName
)
}
if
rootSpan
.
Tag
(
tagName
)
!=
req
.
Name
()
{
t
.
Errorf
(
"Unexpected span tag: rootSpan.Tag(%v): want %v, got %v"
,
tagName
,
req
.
Name
(),
rootSpan
.
Tag
(
tagName
))
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment