Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph: Make old graph panel thresholds work even if ngalert is enabled #38918

Merged
merged 3 commits into from
Sep 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion public/app/features/alerting/state/ThresholdMapper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { config } from 'app/core/config';
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) {
if (!panel.alert || config.featureToggles.ngalert) {
return false; // no update when no alerts
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Modal, ConfirmModal, Button } from '@grafana/ui';
import { DashboardModel, PanelModel } from '../../state';
import { useDashboardDelete } from './useDashboardDelete';
import useAsyncFn from 'react-use/lib/useAsyncFn';
import { config } from 'app/core/config';

type DeleteDashboardModalProps = {
hideModal(): void;
Expand Down Expand Up @@ -41,7 +42,7 @@ export const DeleteDashboardModal: React.FC<DeleteDashboardModalProps> = ({ hide

const getModalBody = (panels: PanelModel[], title: string) => {
const totalAlerts = sumBy(panels, (panel) => (panel.alert ? 1 : 0));
return totalAlerts > 0 ? (
return totalAlerts > 0 && !config.featureToggles.ngalert ? (
<>
<p>Do you want to delete this dashboard?</p>
<p>
Expand Down
7 changes: 4 additions & 3 deletions public/app/features/dashboard/utils/panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ import { UnlinkModal } from 'app/features/library-panels/components/UnlinkModal/
export const removePanel = (dashboard: DashboardModel, panel: PanelModel, ask: boolean) => {
// confirm deletion
if (ask !== false) {
const text2 = panel.alert
? 'Panel includes an alert rule. removing the panel will also remove the alert rule'
: undefined;
const text2 =
panel.alert && !config.featureToggles.ngalert
? 'Panel includes an alert rule. removing the panel will also remove the alert rule'
: undefined;
const confirmText = panel.alert ? 'YES' : undefined;

appEvents.publish(
Expand Down
19 changes: 5 additions & 14 deletions public/app/plugins/panel/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class GraphElement {
data: any[] = [];
panelWidth: number;
eventManager: EventManager;
thresholdManager?: ThresholdManager;
thresholdManager: ThresholdManager;
timeRegionManager: TimeRegionManager;
declare legendElem: HTMLElement;

Expand All @@ -76,10 +76,7 @@ class GraphElement {

this.panelWidth = 0;
this.eventManager = new EventManager(this.ctrl);
// unified alerting does not support threshold for graphs, at least for now
if (!config.featureToggles.ngalert) {
this.thresholdManager = new ThresholdManager(this.ctrl);
}
this.thresholdManager = new ThresholdManager(this.ctrl);
this.timeRegionManager = new TimeRegionManager(this.ctrl);
// @ts-ignore
this.tooltip = new GraphTooltip(this.elem, this.ctrl.dashboard, this.scope, () => {
Expand Down Expand Up @@ -382,9 +379,7 @@ class GraphElement {
}
msg.appendTo(this.elem);
}
if (this.thresholdManager) {
this.thresholdManager.draw(plot);
}
this.thresholdManager.draw(plot);
this.timeRegionManager.draw(plot);
}

Expand Down Expand Up @@ -455,9 +450,7 @@ class GraphElement {
}

// give space to alert editing
if (this.thresholdManager) {
this.thresholdManager.prepare(this.elem, this.data);
}
this.thresholdManager.prepare(this.elem, this.data);

// un-check dashes if lines are unchecked
this.panel.dashes = this.panel.lines ? this.panel.dashes : false;
Expand All @@ -466,9 +459,7 @@ class GraphElement {
const options: any = this.buildFlotOptions(this.panel);
this.prepareXAxis(options, this.panel);
this.configureYAxisOptions(this.data, options);
if (this.thresholdManager) {
this.thresholdManager.addFlotOptions(options, this.panel);
}
this.thresholdManager.addFlotOptions(options, this.panel);
this.timeRegionManager.addFlotOptions(options, this.panel);
this.eventManager.addFlotEvents(this.annotations, options);
this.sortedSeries = this.sortSeries(this.data, this.panel);
Expand Down
2 changes: 1 addition & 1 deletion public/app/plugins/panel/graph/thresholds_form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ThresholdFormCtrl {
$onInit() {
this.panel = this.panelCtrl.panel;

if (this.panel.alert) {
if (this.panel.alert && !config.featureToggles.ngalert) {
this.disabled = true;
}

Expand Down