(rule, metricName)
| 1241 | } |
| 1242 | |
| 1243 | function humanizeThresholdRule(rule, metricName) { |
| 1244 | if (!rule) { |
| 1245 | return ""; |
| 1246 | } |
| 1247 | |
| 1248 | let match = rule.match(/^p\((\d+)\)\s*<\s*([\d.]+)$/); |
| 1249 | if (match) { |
| 1250 | const [, percentileValue, thresholdValue] = match; |
| 1251 | return `P${percentileValue} under ${formatThresholdValue(metricName, Number(thresholdValue))}`; |
| 1252 | } |
| 1253 | |
| 1254 | match = rule.match(/^(avg|max|min|med|rate)\s*<\s*([\d.]+)$/); |
| 1255 | if (match) { |
| 1256 | const [, stat, thresholdValue] = match; |
| 1257 | const readableStat = { |
| 1258 | avg: "Average", |
| 1259 | max: "Max", |
| 1260 | min: "Min", |
| 1261 | med: "Median", |
| 1262 | rate: "Rate", |
| 1263 | }[stat] || stat; |
| 1264 | return `${readableStat} under ${formatThresholdValue(metricName, Number(thresholdValue))}`; |
| 1265 | } |
| 1266 | |
| 1267 | return rule.replaceAll("<", " under ").replaceAll(">", " over "); |
| 1268 | } |
| 1269 | |
| 1270 | function formatThresholdValue(metricName, value) { |
| 1271 | if (!Number.isFinite(value)) { |
no test coverage detected