Skip to content

Commit

Permalink
MaxDimAssociator: compile AmazonMQ broker suffix regex once
Browse files Browse the repository at this point in the history
Performance improvement authored by @kgeckhart
  • Loading branch information
cristiangreco committed Aug 2, 2023
1 parent 646b50e commit 3dd9fae
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/job/maxdimassociator/associator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/nerdswords/yet-another-cloudwatch-exporter/pkg/model"
)

var amazonMQBrokerSuffix = regexp.MustCompile("-[0-9]+$")

// Associator implements a "best effort" algorithm to automatically map the output
// of the ListMetrics API to the list of resources retrieved from the Tagging API.
// The core logic is based on a manually maintained list of regexes that extract
Expand Down Expand Up @@ -202,9 +204,8 @@ func buildLabelsMap(cwMetric *model.Metric, regexpMapping *dimensionsRegexpMappi
// the value of the "Broker" dimension contains a number suffix
// that is not part of the resource ARN
if cwMetric.Namespace == "AWS/AmazonMQ" && name == "Broker" {
brokerSuffix := regexp.MustCompile("-[0-9]+$")
if brokerSuffix.MatchString(value) {
value = brokerSuffix.ReplaceAllString(value, "")
if amazonMQBrokerSuffix.MatchString(value) {
value = amazonMQBrokerSuffix.ReplaceAllString(value, "")
}
}

Expand Down

0 comments on commit 3dd9fae

Please sign in to comment.