Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
repos
security
Test - Service Runner Fork - NodeJS
Commits
cd923802
Commit
cd923802
authored
Dec 10, 2020
by
Clarakosi
Committed by
Petr Pchelko
Dec 10, 2020
Browse files
Update _handleStaticLabels
parent
bfd5fd24
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/metrics/prometheus.js
View file @
cd923802
...
...
@@ -34,13 +34,15 @@ class PrometheusMetric {
}
_handleStaticLabels
(
labels
)
{
const
updatedLabels
=
[...
labels
];
if
(
this
.
staticLabels
!==
undefined
)
{
Object
.
keys
(
this
.
staticLabels
).
forEach
((
name
)
=>
{
if
(
l
abels
.
indexOf
(
this
.
staticLabels
[
name
])
===
-
1
)
{
l
abels
.
unshift
(
this
.
staticLabels
[
name
]);
if
(
updatedL
abels
.
indexOf
(
this
.
staticLabels
[
name
])
===
-
1
)
{
updatedL
abels
.
unshift
(
this
.
staticLabels
[
name
]);
}
});
}
return
updatedLabels
;
}
_normalize
(
str
)
{
...
...
@@ -50,30 +52,22 @@ class PrometheusMetric {
}
increment
(
amount
,
labels
)
{
let
updatedLabels
=
[...
labels
];
this
.
_handleStaticLabels
(
updatedLabels
);
updatedLabels
=
updatedLabels
.
map
(
this
.
_normalize
);
const
updatedLabels
=
this
.
_handleStaticLabels
(
labels
).
map
(
this
.
_normalize
);
this
.
metric
.
labels
.
apply
(
this
.
metric
,
updatedLabels
).
inc
(
amount
);
}
decrement
(
amount
,
labels
)
{
let
updatedLabels
=
[...
labels
];
this
.
_handleStaticLabels
(
updatedLabels
);
updatedLabels
=
updatedLabels
.
map
(
this
.
_normalize
);
const
updatedLabels
=
this
.
_handleStaticLabels
(
labels
).
map
(
this
.
_normalize
);
this
.
metric
.
labels
.
apply
(
this
.
metric
,
updatedLabels
).
dec
(
amount
);
}
observe
(
value
,
labels
)
{
let
updatedLabels
=
[...
labels
];
this
.
_handleStaticLabels
(
updatedLabels
);
updatedLabels
=
updatedLabels
.
map
(
this
.
_normalize
);
const
updatedLabels
=
this
.
_handleStaticLabels
(
labels
).
map
(
this
.
_normalize
);
this
.
metric
.
labels
.
apply
(
this
.
metric
,
updatedLabels
).
observe
(
value
);
}
gauge
(
amount
,
labels
)
{
let
updatedLabels
=
[...
labels
];
this
.
_handleStaticLabels
(
updatedLabels
);
updatedLabels
=
updatedLabels
.
map
(
this
.
_normalize
);
const
updatedLabels
=
this
.
_handleStaticLabels
(
labels
).
map
(
this
.
_normalize
);
if
(
amount
<
0
)
{
this
.
metric
.
labels
.
apply
(
this
.
metric
,
updatedLabels
).
dec
(
Math
.
abs
(
amount
));
}
else
{
...
...
@@ -82,23 +76,17 @@ class PrometheusMetric {
}
set
(
value
,
labels
)
{
let
updatedLabels
=
[...
labels
];
this
.
_handleStaticLabels
(
updatedLabels
);
updatedLabels
=
updatedLabels
.
map
(
this
.
_normalize
);
const
updatedLabels
=
this
.
_handleStaticLabels
(
labels
).
map
(
this
.
_normalize
);
this
.
metric
.
labels
.
apply
(
this
.
metric
,
updatedLabels
).
set
(
value
);
}
timing
(
value
,
labels
)
{
let
updatedLabels
=
[...
labels
];
this
.
_handleStaticLabels
(
updatedLabels
);
updatedLabels
=
updatedLabels
.
map
(
this
.
_normalize
);
const
updatedLabels
=
this
.
_handleStaticLabels
(
labels
).
map
(
this
.
_normalize
);
this
.
observe
(
value
,
updatedLabels
);
}
endTiming
(
startTime
,
labels
)
{
let
updatedLabels
=
[...
labels
];
this
.
_handleStaticLabels
(
updatedLabels
);
updatedLabels
=
updatedLabels
.
map
(
this
.
_normalize
);
const
updatedLabels
=
this
.
_handleStaticLabels
(
labels
).
map
(
this
.
_normalize
);
this
.
timing
(
Date
.
now
()
-
startTime
,
updatedLabels
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment