From 231444ce1d42a433eebeef5f2a26f0c777b04d6f Mon Sep 17 00:00:00 2001 From: "Christian Mauduit (DataDog)" Date: Mon, 9 Jan 2017 18:34:56 -0500 Subject: [PATCH] [profile] avoiding buffer to grow when normalizing tags --- model/normalizer.go | 6 +++--- model/tags.go | 7 +++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/model/normalizer.go b/model/normalizer.go index 4e1ac4305..acb475d06 100644 --- a/model/normalizer.go +++ b/model/normalizer.go @@ -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 } @@ -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 } diff --git a/model/tags.go b/model/tags.go index 26dc043ce..c73aaa862 100644 --- a/model/tags.go +++ b/model/tags.go @@ -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 { @@ -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() }