The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/alerting/state/ThresholdMapper.ts

71 lines
2.2 KiB

import { PanelModel } from 'app/features/dashboard/state';
export const hiddenReducerTypes = ['percent_diff', 'percent_diff_abs'];
export class ThresholdMapper {
static alertToGraphThresholds(panel: PanelModel) {
if (!panel.alert) {
return false; // no update when no alerts
}
for (let i = 0; i < panel.alert.conditions.length; i++) {
const condition = panel.alert.conditions[i];
if (condition.type !== 'query') {
continue;
}
const evaluator = condition.evaluator;
const thresholds: any[] = (panel.thresholds = []);
const visible = hiddenReducerTypes.indexOf(condition.reducer?.type) === -1;
switch (evaluator.type) {
case 'gt': {
const value = evaluator.params[0];
thresholds.push({ value: value, op: 'gt', visible });
break;
}
case 'lt': {
const value = evaluator.params[0];
thresholds.push({ value: value, op: 'lt', visible });
break;
}
case 'outside_range': {
const value1 = evaluator.params[0];
const value2 = evaluator.params[1];
if (value1 > value2) {
thresholds.push({ value: value1, op: 'gt', visible });
thresholds.push({ value: value2, op: 'lt', visible });
} else {
thresholds.push({ value: value1, op: 'lt', visible });
thresholds.push({ value: value2, op: 'gt', visible });
}
break;
}
case 'within_range': {
const value1 = evaluator.params[0];
const value2 = evaluator.params[1];
if (value1 > value2) {
thresholds.push({ value: value1, op: 'lt', visible });
thresholds.push({ value: value2, op: 'gt', visible });
} else {
thresholds.push({ value: value1, op: 'gt', visible });
thresholds.push({ value: value2, op: 'lt', visible });
}
break;
}
}
break;
}
for (const t of panel.thresholds) {
t.fill = panel.options.alertThreshold;
t.line = panel.options.alertThreshold;
t.colorMode = 'critical';
}
const updated = true;
return updated;
}
}