Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update zipkin plugin to use hexadecimal ids and lowercase names #3488

Merged
merged 1 commit into from
Nov 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions plugins/inputs/zipkin/cmd/stress_test_write/stress_test_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ var (
const usage = `./stress_test_write -batch_size=<batch_size> -max_backlog=<max_span_buffer_backlog> -batch_interval=<batch_interval_in_seconds> -span_count<number_of_spans_to_write> -zipkin_host=<zipkin_service_hostname>`

func init() {
flag.IntVar(&BatchSize, "batch_size", 10000, usage)
flag.IntVar(&MaxBackLog, "max_backlog", 100000, usage)
flag.IntVar(&BatchTimeInterval, "batch_interval", 1, usage)
flag.IntVar(&SpanCount, "span_count", 100000, usage)
flag.StringVar(&ZipkinServerHost, "zipkin_host", "localhost", usage)
flag.IntVar(&BatchSize, "batch_size", 10000, "")
flag.IntVar(&MaxBackLog, "max_backlog", 100000, "")
flag.IntVar(&BatchTimeInterval, "batch_interval", 1, "")
flag.IntVar(&SpanCount, "span_count", 100000, "")
flag.StringVar(&ZipkinServerHost, "zipkin_host", "localhost", "")
}

func main() {
Expand All @@ -59,7 +59,7 @@ func main() {
}

tracer, err := zipkin.NewTracer(
zipkin.NewRecorder(collector, false, "127.0.0.1:0", "trivial"))
zipkin.NewRecorder(collector, false, "127.0.0.1:0", "Trivial"))

if err != nil {
log.Fatalf("Error: %v\n", err)
Expand Down
4 changes: 2 additions & 2 deletions plugins/inputs/zipkin/codec/jsonV1/jsonV1.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func TraceIDFromString(s string) (string, error) {
return fmt.Sprintf("%x%016x", hi, lo), nil
}

// IDFromString creates a decimal id from a hexadecimal string
// IDFromString validates the ID and returns it in hexadecimal format.
func IDFromString(s string) (string, error) {
if len(s) > 16 {
return "", fmt.Errorf("ID cannot be longer than 16 hex characters: %s", s)
Expand All @@ -248,5 +248,5 @@ func IDFromString(s string) (string, error) {
if err != nil {
return "", err
}
return strconv.FormatUint(id, 10), nil
return strconv.FormatUint(id, 16), nil
}
16 changes: 8 additions & 8 deletions plugins/inputs/zipkin/codec/jsonV1/jsonV1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,14 +526,14 @@ func Test_span_SpanID(t *testing.T) {
wantErr: true,
},
{
name: "converts known id correctly",
name: "validates known id correctly",
ID: "b26412d1ac16767d",
want: "12854419928166856317",
want: "b26412d1ac16767d",
},
{
name: "converts hex string correctly",
name: "validates hex string correctly",
ID: "deadbeef",
want: "3735928559",
want: "deadbeef",
},
{
name: "errors when string isn't hex",
Expand Down Expand Up @@ -576,9 +576,9 @@ func Test_span_Parent(t *testing.T) {
want: "",
},
{
name: "converts hex string correctly",
name: "validates hex string correctly",
ParentID: "deadbeef",
want: "3735928559",
want: "deadbeef",
},
{
name: "errors when string isn't hex",
Expand Down Expand Up @@ -890,9 +890,9 @@ func TestIDFromString(t *testing.T) {
wantErr bool
}{
{
name: "Convert hex string id",
name: "validates hex string id",
s: "6b221d5bc9e6496c",
want: "7719764991332993388",
want: "6b221d5bc9e6496c",
},
{
name: "error : id too long",
Expand Down
2 changes: 1 addition & 1 deletion plugins/inputs/zipkin/codec/thrift/thrift.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,5 @@ func (s *span) Duration() time.Duration {
}

func formatID(id int64) string {
return strconv.FormatInt(id, 10)
return strconv.FormatInt(id, 16)
}
22 changes: 16 additions & 6 deletions plugins/inputs/zipkin/convert.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package zipkin

import (
"strings"

"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs/zipkin/trace"
)
Expand Down Expand Up @@ -28,12 +30,13 @@ func (l *LineProtocolConverter) Record(t trace.Trace) error {
fields := map[string]interface{}{
"duration_ns": s.Duration.Nanoseconds(),
}

tags := map[string]string{
"id": s.ID,
"parent_id": s.ParentID,
"trace_id": s.TraceID,
"name": s.Name,
"service_name": s.ServiceName,
"name": formatName(s.Name),
"service_name": formatName(s.ServiceName),
}
l.acc.AddFields("zipkin", fields, tags, s.Timestamp)

Expand All @@ -42,8 +45,8 @@ func (l *LineProtocolConverter) Record(t trace.Trace) error {
"id": s.ID,
"parent_id": s.ParentID,
"trace_id": s.TraceID,
"name": s.Name,
"service_name": a.ServiceName,
"name": formatName(s.Name),
"service_name": formatName(a.ServiceName),
"annotation": a.Value,
"endpoint_host": a.Host,
}
Expand All @@ -55,8 +58,8 @@ func (l *LineProtocolConverter) Record(t trace.Trace) error {
"id": s.ID,
"parent_id": s.ParentID,
"trace_id": s.TraceID,
"name": s.Name,
"service_name": b.ServiceName,
"name": formatName(s.Name),
"service_name": formatName(b.ServiceName),
"annotation": b.Value,
"endpoint_host": b.Host,
"annotation_key": b.Key,
Expand All @@ -71,3 +74,10 @@ func (l *LineProtocolConverter) Record(t trace.Trace) error {
func (l *LineProtocolConverter) Error(err error) {
l.acc.AddError(err)
}

// formatName formats name and service name
// Zipkin forces span and service names to be lowercase:
// https://github.com/openzipkin/zipkin/pull/805
func formatName(name string) string {
return strings.ToLower(name)
}
18 changes: 9 additions & 9 deletions plugins/inputs/zipkin/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestLineProtocolConverter_Record(t *testing.T) {
"parent_id": "22964302721410078",
"trace_id": "2505404965370368069",
"service_name": "trivial",
"name": "Child",
"name": "child",
},
Fields: map[string]interface{}{
"duration_ns": (time.Duration(53106) * time.Microsecond).Nanoseconds(),
Expand All @@ -128,7 +128,7 @@ func TestLineProtocolConverter_Record(t *testing.T) {
"id": "8090652509916334619",
"parent_id": "22964302721410078",
"trace_id": "2505404965370368069",
"name": "Child",
"name": "child",
"service_name": "trivial",
"annotation": "dHJpdmlhbA==",
"endpoint_host": "2130706433:0",
Expand All @@ -146,7 +146,7 @@ func TestLineProtocolConverter_Record(t *testing.T) {
"parent_id": "22964302721410078",
"trace_id": "2505404965370368069",
"service_name": "trivial",
"name": "Child",
"name": "child",
},
Fields: map[string]interface{}{
"duration_ns": (time.Duration(50410) * time.Microsecond).Nanoseconds(),
Expand All @@ -159,7 +159,7 @@ func TestLineProtocolConverter_Record(t *testing.T) {
"id": "103618986556047333",
"parent_id": "22964302721410078",
"trace_id": "2505404965370368069",
"name": "Child",
"name": "child",
"service_name": "trivial",
"annotation": "dHJpdmlhbA==",
"endpoint_host": "2130706433:0",
Expand All @@ -177,7 +177,7 @@ func TestLineProtocolConverter_Record(t *testing.T) {
"parent_id": "22964302721410078",
"trace_id": "2505404965370368069",
"service_name": "trivial",
"name": "Parent",
"name": "parent",
},
Fields: map[string]interface{}{
"duration_ns": (time.Duration(103680) * time.Microsecond).Nanoseconds(),
Expand All @@ -193,7 +193,7 @@ func TestLineProtocolConverter_Record(t *testing.T) {
"id": "22964302721410078",
"parent_id": "22964302721410078",
"trace_id": "2505404965370368069",
"name": "Parent",
"name": "parent",
},
Fields: map[string]interface{}{
"duration_ns": (time.Duration(103680) * time.Microsecond).Nanoseconds(),
Expand All @@ -209,7 +209,7 @@ func TestLineProtocolConverter_Record(t *testing.T) {
"id": "22964302721410078",
"parent_id": "22964302721410078",
"trace_id": "2505404965370368069",
"name": "Parent",
"name": "parent",
},
Fields: map[string]interface{}{
"duration_ns": (time.Duration(103680) * time.Microsecond).Nanoseconds(),
Expand All @@ -221,7 +221,7 @@ func TestLineProtocolConverter_Record(t *testing.T) {
Tags: map[string]string{
"parent_id": "22964302721410078",
"trace_id": "2505404965370368069",
"name": "Parent",
"name": "parent",
"service_name": "trivial",
"annotation": "A Log",
"endpoint_host": "2130706433:0",
Expand All @@ -241,7 +241,7 @@ func TestLineProtocolConverter_Record(t *testing.T) {
"annotation_key": "lc",
"id": "22964302721410078",
"parent_id": "22964302721410078",
"name": "Parent",
"name": "parent",
"endpoint_host": "2130706433:0",
},
Fields: map[string]interface{}{
Expand Down
10 changes: 5 additions & 5 deletions plugins/inputs/zipkin/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func TestSpanHandler(t *testing.T) {

got := mockRecorder.Data

parentID := strconv.FormatInt(22964302721410078, 10)
parentID := strconv.FormatInt(22964302721410078, 16)
want := trace.Trace{
{
Name: "Child",
ID: "8090652509916334619",
ID: "7047c59776af8a1b",
TraceID: "22c4fc8ab3669045",
ParentID: parentID,
Timestamp: time.Unix(0, 1498688360851331*int64(time.Microsecond)).UTC(),
Expand All @@ -74,7 +74,7 @@ func TestSpanHandler(t *testing.T) {
},
{
Name: "Child",
ID: "103618986556047333",
ID: "17020eb55a8bfe5",
TraceID: "22c4fc8ab3669045",
ParentID: parentID,
Timestamp: time.Unix(0, 1498688360904552*int64(time.Microsecond)).UTC(),
Expand All @@ -92,9 +92,9 @@ func TestSpanHandler(t *testing.T) {
},
{
Name: "Parent",
ID: "22964302721410078",
ID: "5195e96239641e",
TraceID: "22c4fc8ab3669045",
ParentID: "22964302721410078",
ParentID: parentID,
Timestamp: time.Unix(0, 1498688360851318*int64(time.Microsecond)).UTC(),
Duration: time.Duration(103680) * time.Microsecond,
ServiceName: "trivial",
Expand Down
Loading