2
2
3
3
const { getValueAsString } = require ( './util' ) ;
4
4
5
+ const ESCAPE_STRING_REPLACE_MAP = {
6
+ '\\' : '\\\\' ,
7
+ '\n' : '\\n' ,
8
+ } ;
9
+
10
+ const ESCAPE_LABEL_VALUE_REPLACE_MAP = {
11
+ ...ESCAPE_STRING_REPLACE_MAP ,
12
+ '"' : '\\\\"' ,
13
+ } ;
14
+
15
+ const ESCAPE_REPLACE_REGEXP = / \\ | \n | " / g;
16
+
5
17
function REPLACE_FUNC ( dict ) {
6
18
return char => dict [ char ] || '' ;
7
19
}
@@ -15,23 +27,6 @@ class Registry {
15
27
return 'application/openmetrics-text; version=1.0.0; charset=utf-8' ;
16
28
}
17
29
18
- static get ESCAPE_STRING_REPLACE_MAP ( ) {
19
- return {
20
- '\\' : '\\\\' ,
21
- '\n' : '\\n' ,
22
- } ;
23
- }
24
-
25
- static get ESCAPE_LABEL_VALUE_REPLACE_MAP ( ) {
26
- return Object . assign ( { } , Registry . ESCAPE_STRING_REPLACE_MAP , {
27
- '"' : '\\\\"' ,
28
- } ) ;
29
- }
30
-
31
- static get ESCAPE_REPLACE_REGEXP ( ) {
32
- return / \\ | \n | " / g;
33
- }
34
-
35
30
constructor ( regContentType = Registry . PROMETHEUS_CONTENT_TYPE ) {
36
31
this . _metrics = { } ;
37
32
this . _collectors = [ ] ;
@@ -256,14 +251,14 @@ function escapeLabelValue(str) {
256
251
return str ;
257
252
}
258
253
259
- return escapeString ( str , Registry . ESCAPE_LABEL_VALUE_REPLACE_MAP ) ;
254
+ return escapeString ( str , ESCAPE_LABEL_VALUE_REPLACE_MAP ) ;
260
255
}
261
256
function escapeString ( str , extraReplaceDict ) {
262
257
const fullDict = extraReplaceDict
263
258
? extraReplaceDict
264
- : Registry . ESCAPE_STRING_REPLACE_MAP ;
259
+ : ESCAPE_STRING_REPLACE_MAP ;
265
260
266
- return str . replace ( Registry . ESCAPE_REPLACE_REGEXP , REPLACE_FUNC ( fullDict ) ) ;
261
+ return str . replace ( ESCAPE_REPLACE_REGEXP , REPLACE_FUNC ( fullDict ) ) ;
267
262
}
268
263
function standardizeCounterName ( name ) {
269
264
return name . replace ( / _ t o t a l $ / , '' ) ;
0 commit comments