Skip to content
This repository has been archived by the owner on Aug 30, 2019. It is now read-only.

[profile] avoiding buffer to grow when normalizing tags #183

Merged
merged 1 commit into from
Jan 10, 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
6 changes: 3 additions & 3 deletions model/normalizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ func (s *Span) Normalize() error {
if len(k) > MaxMetaKeyLen {
log.Debugf("span.normalize: truncating `Meta` key (max %d chars): %s", MaxMetaKeyLen, k)
delete(s.Meta, k)
k = fmt.Sprintf("%s...", k[:MaxMetaKeyLen])
k = k[:MaxMetaKeyLen] + "..."
modified = true
}

if len(v) > MaxMetaValLen {
v = fmt.Sprintf("%s...", v[:MaxMetaValLen])
v = v[:MaxMetaValLen] + "..."
modified = true
}

Expand All @@ -125,7 +125,7 @@ func (s *Span) Normalize() error {
if len(k) > MaxMetricsKeyLen {
log.Debugf("span.normalize: truncating `Metrics` key (max %d chars): %s", MaxMetricsKeyLen, k)
delete(s.Metrics, k)
k = fmt.Sprintf("%s...", k[:MaxMetricsKeyLen])
k = k[:MaxMetricsKeyLen] + "..."

s.Metrics[k] = v
}
Expand Down
7 changes: 3 additions & 4 deletions model/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ func FilterTags(tags, groups []string) []string {
// taken from dd-go.model.NormalizeTag
func NormalizeTag(tag string) string {
// unless you just throw out unicode, this is already as fast as it gets
var buf bytes.Buffer

buf := bytes.NewBuffer(make([]byte, 0, 2*len(tag)))
lastWasUnderscore := false

for _, c := range tag {
Expand Down Expand Up @@ -283,12 +283,11 @@ func NormalizeTag(tag string) string {
}
}

b := buf.Bytes()

// strip trailing underscores
if lastWasUnderscore {
b := buf.Bytes()
return string(b[:len(b)-1])
}

return string(b)
return buf.String()
}