mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Squash four commits and claim. Credit to @ikkemaniac in #25034, but taking this to sign CLA and get it landed. Four commit message were: - add 'fill' switch on Alert Tab - add 'fill' to Alert init model. Make default value 'true' not to break current design - use newly created alert.fill when rendering graph - add 'line' switch on Alert tab, add 'line' to Alert init model. Set default to 'true' not to break current design. Use newly created alert.line when rendering graph Should close feature req #7258. * Move alert toggle to Display tab. * Move alertThreshold to PanelModel.options. * Fix ThresholdMapper tests by adding options to each mocked panel. * Update documentation for the new display option. * Update docs with review feedback. * Handle onRender with null panel in ThresholdMapper
70 lines
1.9 KiB
TypeScript
70 lines
1.9 KiB
TypeScript
import { PanelModel } from 'app/features/dashboard/state';
|
|
|
|
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 = []);
|
|
|
|
switch (evaluator.type) {
|
|
case 'gt': {
|
|
const value = evaluator.params[0];
|
|
thresholds.push({ value: value, op: 'gt' });
|
|
break;
|
|
}
|
|
case 'lt': {
|
|
const value = evaluator.params[0];
|
|
thresholds.push({ value: value, op: 'lt' });
|
|
break;
|
|
}
|
|
case 'outside_range': {
|
|
const value1 = evaluator.params[0];
|
|
const value2 = evaluator.params[1];
|
|
|
|
if (value1 > value2) {
|
|
thresholds.push({ value: value1, op: 'gt' });
|
|
thresholds.push({ value: value2, op: 'lt' });
|
|
} else {
|
|
thresholds.push({ value: value1, op: 'lt' });
|
|
thresholds.push({ value: value2, op: 'gt' });
|
|
}
|
|
|
|
break;
|
|
}
|
|
case 'within_range': {
|
|
const value1 = evaluator.params[0];
|
|
const value2 = evaluator.params[1];
|
|
|
|
if (value1 > value2) {
|
|
thresholds.push({ value: value1, op: 'lt' });
|
|
thresholds.push({ value: value2, op: 'gt' });
|
|
} else {
|
|
thresholds.push({ value: value1, op: 'gt' });
|
|
thresholds.push({ value: value2, op: 'lt' });
|
|
}
|
|
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;
|
|
}
|
|
}
|