mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-07-18 15:24:03 +02:00
Added sorting to label definition
This commit is contained in:
parent
2e597c7697
commit
9e4d6f1b70
1 changed files with 25 additions and 4 deletions
|
@ -40,7 +40,7 @@ class Prometheus {
|
|||
return Prometheus.sanitizeForPrometheus(tag.name);
|
||||
}).filter((tagName) => {
|
||||
return tagName !== "";
|
||||
}));
|
||||
}).sort(this.sortTags));
|
||||
|
||||
const commonLabels = [
|
||||
...tags,
|
||||
|
@ -86,7 +86,7 @@ class Prometheus {
|
|||
static sanitizeForPrometheus(text) {
|
||||
text = text.replace(/[^a-zA-Z0-9_]/g, "");
|
||||
text = text.replace(/^[^a-zA-Z_]+/, "");
|
||||
return text.toLowerCase();
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -106,7 +106,7 @@ class Prometheus {
|
|||
mappedTags[sanitizedTag] = [];
|
||||
}
|
||||
|
||||
let tagValue = Prometheus.sanitizeForPrometheus(tag.value);
|
||||
let tagValue = Prometheus.sanitizeForPrometheus(tag.value || "");
|
||||
if (tagValue !== "") {
|
||||
mappedTags[sanitizedTag].push(tagValue);
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class Prometheus {
|
|||
});
|
||||
|
||||
// Order the tags alphabetically
|
||||
return Object.keys(mappedTags).sort().reduce((obj, key) => {
|
||||
return Object.keys(mappedTags).sort(this.sortTags).reduce((obj, key) => {
|
||||
obj[key] = mappedTags[key];
|
||||
return obj;
|
||||
}, {});
|
||||
|
@ -188,6 +188,27 @@ class Prometheus {
|
|||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the tags alphabetically, case-insensitive.
|
||||
* @param a {string}
|
||||
* @param b {string}
|
||||
* @returns {number}
|
||||
*/
|
||||
sortTags(a, b) {
|
||||
const aLowerCase = a.toLowerCase();
|
||||
const bLowerCase = b.toLowerCase();
|
||||
|
||||
if (aLowerCase < bLowerCase) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (aLowerCase > bLowerCase) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Add table
Reference in a new issue