Skip to content

Commit

Permalink
refactor(analysis): Graphite query - proper naming and regexp usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mdsjip committed May 6, 2023
1 parent 489053e commit e97d01c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions metricproviders/graphite/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e97d01c

Please sign in to comment.