File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff 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.
170172func 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
You can’t perform that action at this time.
0 commit comments