From e97d01cb5244317ac482a515a8aca4578a4909a9 Mon Sep 17 00:00:00 2001 From: mdsjip <2284562+mdsjip@users.noreply.github.com> Date: Sun, 30 Apr 2023 19:18:21 +0200 Subject: [PATCH] refactor(analysis): Graphite query - proper naming and regexp usage --- metricproviders/graphite/api.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/metricproviders/graphite/api.go b/metricproviders/graphite/api.go index 03a0d22243..06833ac028 100644 --- a/metricproviders/graphite/api.go +++ b/metricproviders/graphite/api.go @@ -27,9 +27,11 @@ type APIClient struct { logCTX log.Entry } +var spaceRegex = regexp.MustCompile(`\s+`) + // Query performs a Graphite API query with the query it's passed func (api APIClient) Query(quer string) ([]dataPoint, error) { - query := api.trimQuery(quer) + query := api.sanitizeQuery(quer) u, err := url.Parse(fmt.Sprintf("./render?%s", query)) if err != nil { return []dataPoint{}, err @@ -75,9 +77,8 @@ func (api APIClient) Query(quer string) ([]dataPoint, error) { return result[0].DataPoints, nil } -func (api APIClient) trimQuery(q string) string { - space := regexp.MustCompile(`\s+`) - return space.ReplaceAllString(q, "") +func (api APIClient) sanitizeQuery(q string) string { + return spaceRegex.ReplaceAllLiteralString(q, "") } type dataPoint struct {