Commit cd923802 authored by Clarakosi's avatar Clarakosi Committed by Petr Pchelko
Browse files

Update _handleStaticLabels

parent bfd5fd24
......@@ -34,13 +34,15 @@ class PrometheusMetric {
}
_handleStaticLabels(labels) {
const updatedLabels = [...labels];
if (this.staticLabels !== undefined) {
Object.keys(this.staticLabels).forEach((name) => {
if (labels.indexOf(this.staticLabels[name]) === -1) {
labels.unshift(this.staticLabels[name]);
if (updatedLabels.indexOf(this.staticLabels[name]) === -1) {
updatedLabels.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);
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment