From 5856611291297d017765caca1f239c2f85b0beee Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Mon, 18 Jan 2021 17:30:09 +0200 Subject: [PATCH] app/vmselect/graphite: extract getCanonicalPath() function from loop body inside getCanonicalPaths() --- app/vmselect/graphite/tags_api.go | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/app/vmselect/graphite/tags_api.go b/app/vmselect/graphite/tags_api.go index f41a2041f8..521785cb01 100644 --- a/app/vmselect/graphite/tags_api.go +++ b/app/vmselect/graphite/tags_api.go @@ -366,26 +366,29 @@ func TagsFindSeriesHandler(startTime time.Time, at *auth.Token, w http.ResponseW func getCanonicalPaths(mns []storage.MetricName) []string { paths := make([]string, 0, len(mns)) - var b []byte - var tags []storage.Tag for _, mn := range mns { - b = append(b[:0], mn.MetricGroup...) - tags = append(tags[:0], mn.Tags...) - sort.Slice(tags, func(i, j int) bool { - return string(tags[i].Key) < string(tags[j].Key) - }) - for _, tag := range tags { - b = append(b, ';') - b = append(b, tag.Key...) - b = append(b, '=') - b = append(b, tag.Value...) - } - paths = append(paths, string(b)) + path := getCanonicalPath(&mn) + paths = append(paths, path) } sort.Strings(paths) return paths } +func getCanonicalPath(mn *storage.MetricName) string { + b := append([]byte{}, mn.MetricGroup...) + tags := append([]storage.Tag{}, mn.Tags...) + sort.Slice(tags, func(i, j int) bool { + return string(tags[i].Key) < string(tags[j].Key) + }) + for _, tag := range tags { + b = append(b, ';') + b = append(b, tag.Key...) + b = append(b, '=') + b = append(b, tag.Value...) + } + return string(b) +} + var tagsFindSeriesDuration = metrics.NewSummary(`vm_request_duration_seconds{path="/tags/findSeries"}`) // TagValuesHandler implements /tags/ endpoint from Graphite Tags API.