Skip to content

Commit dcc893d

Browse files
committed
cache prometheusize
1 parent 5bbba9e commit dcc893d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

exporter/metrics.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,17 @@ var (
164164
dollarRe = regexp.MustCompile(`\_$`)
165165
)
166166

167+
var prometheusizeCache = make(map[string]string)
168+
167169
// prometheusize renames metrics by replacing some prefixes with shorter names
168170
// replace special chars to follow Prometheus metric naming rules and adds the
169171
// exporter name prefix.
170172
func prometheusize(s string) string {
173+
if renamed, exists := prometheusizeCache[s]; exists {
174+
return renamed
175+
}
176+
back := strings.Clone(s)
177+
171178
for _, pair := range prefixes {
172179
if strings.HasPrefix(s, pair[0]+".") {
173180
s = pair[1] + strings.TrimPrefix(s, pair[0])
@@ -180,6 +187,8 @@ func prometheusize(s string) string {
180187
s = repeatedUnderscoresRe.ReplaceAllString(s, "_")
181188
s = strings.TrimPrefix(s, "_")
182189

190+
prometheusizeCache[back] = strings.Clone(s)
191+
183192
return exporterPrefix + s
184193
}
185194

0 commit comments

Comments
 (0)