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 (
164
164
dollarRe = regexp .MustCompile (`\_$` )
165
165
)
166
166
167
+ var prometheusizeCache = make (map [string ]string )
168
+
167
169
// prometheusize renames metrics by replacing some prefixes with shorter names
168
170
// replace special chars to follow Prometheus metric naming rules and adds the
169
171
// exporter name prefix.
170
172
func prometheusize (s string ) string {
173
+ if renamed , exists := prometheusizeCache [s ]; exists {
174
+ return renamed
175
+ }
176
+ back := strings .Clone (s )
177
+
171
178
for _ , pair := range prefixes {
172
179
if strings .HasPrefix (s , pair [0 ]+ "." ) {
173
180
s = pair [1 ] + strings .TrimPrefix (s , pair [0 ])
@@ -180,6 +187,8 @@ func prometheusize(s string) string {
180
187
s = repeatedUnderscoresRe .ReplaceAllString (s , "_" )
181
188
s = strings .TrimPrefix (s , "_" )
182
189
190
+ prometheusizeCache [back ] = strings .Clone (s )
191
+
183
192
return exporterPrefix + s
184
193
}
185
194
You can’t perform that action at this time.
0 commit comments