Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Fixing issue #1: Metrics coming from plugin with compound name are not usable in thresholds #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class EnsurePlugin {
const vars = Object.assign({}, data.report.counters, data.report.rates);
for(const [name, values] of Object.entries(data.report.summaries || {})) {
for(const [aggregation, value] of Object.entries(values)) {
vars[`${name}.${aggregation}`] = value;
vars[`${EnsurePlugin.sanitizeName(name)}.${aggregation}`] = value;
}
}

Expand All @@ -87,7 +87,7 @@ class EnsurePlugin {
if (typeof o === 'object') {
const metricName = Object.keys(o)[0]; // only one metric check per array entry
const maxValue = o[metricName];
const expr = `${metricName} < ${maxValue}`;
const expr = `${EnsurePlugin.sanitizeName(metricName)} < ${maxValue}`;
let f = () => {};
try {
f = filtrex(expr);
Expand Down Expand Up @@ -159,6 +159,11 @@ class EnsurePlugin {
});
return checkTests;
}

static sanitizeName(varName) {
if(typeof varName !== 'string') return varName
return varName.replaceAll('-', '_')
}
}

module.exports = {
Expand Down
Loading