Просмотр исходного кода

alerting: fixed issue with included alerting error & no data reasons, fixes #8412

Torkel Ödegaard 8 лет назад
Родитель
Сommit
8918922179

+ 24 - 1
public/app/features/alerting/alert_def.ts

@@ -131,6 +131,29 @@ function joinEvalMatches(matches, separator: string) {
   }, []).join(separator);
 }
 
+function getAlertAnnotationInfo(ah) {
+
+  // backward compatability, can be removed in grafana 5.x
+  // old way stored evalMatches in data property directly,
+  // new way stores it in evalMatches property on new data object
+
+  if (_.isArray(ah.data)) {
+    return joinEvalMatches(ah.data, ', ');
+  } else if (_.isArray(ah.data.evalMatches)) {
+    return joinEvalMatches(ah.data.evalMatches, ', ');
+  }
+
+  if (ah.data.error) {
+    return "Error: " + ah.data.error;
+  }
+
+  if (ah.data.noData || ah.data.no_data) {
+    return "No Data";
+  }
+
+  return "";
+}
+
 export default {
   alertQueryDef: alertQueryDef,
   getStateDisplayModel: getStateDisplayModel,
@@ -141,6 +164,6 @@ export default {
   executionErrorModes: executionErrorModes,
   reducerTypes: reducerTypes,
   createReducerPart: createReducerPart,
-  joinEvalMatches: joinEvalMatches,
+  getAlertAnnotationInfo: getAlertAnnotationInfo,
   alertStateSortScore: alertStateSortScore,
 };

+ 1 - 19
public/app/features/alerting/alert_tab_ctrl.ts

@@ -81,25 +81,7 @@ export class AlertTabCtrl {
       this.alertHistory = _.map(res, ah => {
         ah.time = moment(ah.time).format('MMM D, YYYY HH:mm:ss');
         ah.stateModel = alertDef.getStateDisplayModel(ah.newState);
-        ah.reason = "";
-
-        if (_.isArray(ah.data)) {
-          ah.reason = "Conditions";
-          ah.metrics = alertDef.joinEvalMatches(ah.data, ', ');
-        } else if (_.isArray(ah.data.evalMatches)) {
-          ah.metrics = alertDef.joinEvalMatches(ah.data.evalMatches, ', ');
-        }
-
-        if (ah.data.error) {
-          ah.metrics = "" + ah.data.error;
-          ah.reason = "Error";
-        }
-
-        if (ah.data.noData || ah.data.no_data) {
-          ah.metrics = "";
-          ah.reason = "No Data";
-        }
-
+        ah.info = alertDef.getAlertAnnotationInfo(ah);
         return ah;
       });
     });

+ 1 - 1
public/app/features/alerting/partials/alert_tab.html

@@ -161,7 +161,7 @@
                     </span> {{ah.time}}
 									</div>
 									<div class="card-item-sub-name">
-									  &nbsp;{{ah.metrics}}
+										{{ah.info}}
 									</div>
 								</div>
 							</div>

+ 1 - 1
public/app/plugins/panel/alertlist/module.html

@@ -40,7 +40,7 @@
                 <span class="alert-list-item-state {{al.stateModel.stateClass}}">
                   <i class="{{al.stateModel.iconClass}}"></i>
                   {{al.stateModel.text}}
-                </span> {{al.metrics}}
+                </span> {{al.info}}
               </div>
             </div>
           </div>

+ 1 - 1
public/app/plugins/panel/alertlist/module.ts

@@ -106,7 +106,7 @@ class AlertListPanel extends PanelCtrl {
         this.alertHistory = _.map(res, al => {
           al.time = moment(al.time).format('MMM D, YYYY HH:mm:ss');
           al.stateModel = alertDef.getStateDisplayModel(al.newState);
-          al.metrics = alertDef.joinEvalMatches(al.data, ', ');
+          al.info = alertDef.getAlertAnnotationInfo(al);
           return al;
         });
       });