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

Do not use KeyValue fields directly and use KeyValues as decorator only #810

Merged
merged 2 commits into from May 7, 2018
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Prev

Use KeyValues as decorator only

Signed-off-by: Yuri Shkuro <ys@uber.com>
  • Loading branch information...
yurishkuro committed May 7, 2018
commit f1604a6966f30b33f67f1c99829b3ec2b663d546
@@ -121,7 +121,7 @@ func TestUTF8Sanitizer_SanitizeProcessTags(t *testing.T) {
},
},
)
_, exists := actual.Process.Tags.FindByKey(invalidTagKey)
_, exists := model.KeyValues(actual.Process.Tags).FindByKey(invalidTagKey)
assert.True(t, exists)

}
@@ -133,7 +133,7 @@ func TestUTF8Sanitizer_SanitizeTags(t *testing.T) {
Process: &model.Process{},
},
)
_, exists := actual.Tags.FindByKey(invalidTagKey)
_, exists := model.KeyValues(actual.Tags).FindByKey(invalidTagKey)
assert.True(t, exists)

}
@@ -75,7 +75,7 @@ type node struct {
//
// TODO convert process tags to a canonical format somewhere else
func hostKey(span *model.Span) string {
if tag, ok := span.Process.Tags.FindByKey("ip"); ok {
if tag, ok := model.KeyValues(span.Process.Tags).FindByKey("ip"); ok {
if tag.VType == model.StringType {
return tag.VStr
}
@@ -57,7 +57,7 @@ func IPTagAdjuster() Adjuster {
for _, span := range trace.Spans {
adjustTags(span.Tags)
adjustTags(span.Process.Tags)
span.Process.Tags.Sort()
model.KeyValues(span.Process.Tags).Sort()
}
return trace, nil
})
@@ -53,12 +53,12 @@ func TestIPTagAdjuster(t *testing.T) {
model.String("peer.ipv4", "not integer"),
model.String("peer.ipv4", "1.2.3.4"),
}
assert.Equal(t, expectedSpanTags, trace.Spans[0].Tags)
assert.Equal(t, expectedSpanTags, model.KeyValues(trace.Spans[0].Tags))

expectedProcessTags := model.KeyValues{
model.Int64("a", 42),
model.String("ip", "1.2.3.4"), // sorted
model.String("ip", "not integer"),
}
assert.Equal(t, expectedProcessTags, trace.Spans[0].Process.Tags)
assert.Equal(t, expectedProcessTags, model.KeyValues(trace.Spans[0].Process.Tags))
}
@@ -119,11 +119,11 @@ func TestToDomainMultipleSpanKinds(t *testing.T) {
require.Nil(t, err)

assert.Equal(t, 2, len(trace.Spans))
assert.Equal(t, 1, trace.Spans[0].Tags.Len())
assert.Equal(t, 1, len(trace.Spans[0].Tags))
assert.Equal(t, test.tagFirst.Key, trace.Spans[0].Tags[0].Key)
assert.Equal(t, string(test.tagFirst.Value.(ext.SpanKindEnum)), trace.Spans[0].Tags[0].VStr)

assert.Equal(t, 1, trace.Spans[1].Tags.Len())
assert.Equal(t, 1, len(trace.Spans[1].Tags))
assert.Equal(t, test.tagSecond.Key, trace.Spans[1].Tags[0].Key)
assert.Equal(t, time.Duration(1000), trace.Spans[1].Duration)
assert.Equal(t, string(test.tagSecond.Value.(ext.SpanKindEnum)), trace.Spans[1].Tags[0].VStr)
@@ -131,3 +131,15 @@ func BenchmarkKeyValuesSort(b *testing.B) {
list.Sort()
}
}

// No memory allocations from wrapping sliceinto model.KeyValues()
// 0.53 ns/op 0 B/op 0 allocs/op
func BenchmarkKeyValuesWrapping(b *testing.B) {
kv := []model.KeyValue{
model.String("x", "y"),
model.Int64("n", 42),
}
for i := 0; i < b.N; i++ {
model.KeyValues(kv).Len()
}
}
@@ -18,8 +18,8 @@ import "io"

// Process describes an instance of an application or service that emits tracing data.
type Process struct {
ServiceName string `json:"serviceName"`
Tags KeyValues `json:"tags,omitempty"`
ServiceName string `json:"serviceName"`
Tags []KeyValue `json:"tags,omitempty"`
}

// NewProcess creates a new Process for given serviceName and tags.
@@ -37,13 +37,13 @@ func (p *Process) Equal(other *Process) bool {
if p.ServiceName != other.ServiceName {
return false
}
return p.Tags.Equal(other.Tags)
return KeyValues(p.Tags).Equal(other.Tags)
}

// Hash implements Hash from Hashable.
func (p *Process) Hash(w io.Writer) (err error) {
if _, err := w.Write([]byte(p.ServiceName)); err != nil {
return err
}
return p.Tags.Hash(w)
return KeyValues(p.Tags).Hash(w)
}
@@ -53,7 +53,7 @@ type Span struct {
Flags Flags `json:"flags,omitempty"`
StartTime time.Time `json:"startTime"`
Duration time.Duration `json:"duration"`
Tags KeyValues `json:"tags,omitempty"`
Tags []KeyValue `json:"tags,omitempty"`
Logs []Log `json:"logs,omitempty"`
Process *Process `json:"process"`
Warnings []string `json:"warnings,omitempty"`
@@ -69,7 +69,7 @@ func (s *Span) Hash(w io.Writer) (err error) {

// HasSpanKind returns true if the span has a `span.kind` tag set to `kind`.
func (s *Span) HasSpanKind(kind ext.SpanKindEnum) bool {
if tag, ok := s.Tags.FindByKey(string(ext.SpanKind)); ok {
if tag, ok := KeyValues(s.Tags).FindByKey(string(ext.SpanKind)); ok {
return tag.AsString() == string(kind)
}
return false
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.