From f84dc24fcb1e1a7e842b11f58a74461adccc060c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 15 May 2017 16:17:05 +0200 Subject: [PATCH 1/3] alerting: improving and fixing alert history, #7257 --- pkg/services/alerting/result_handler.go | 12 +++++------- .../app/features/alerting/alert_tab_ctrl.ts | 19 ++++++++++++++----- .../features/alerting/partials/alert_tab.html | 10 +++++++--- public/sass/components/edit_sidemenu.scss | 1 + 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/pkg/services/alerting/result_handler.go b/pkg/services/alerting/result_handler.go index 1298a5dda36..972fbd3a461 100644 --- a/pkg/services/alerting/result_handler.go +++ b/pkg/services/alerting/result_handler.go @@ -31,17 +31,15 @@ func (handler *DefaultResultHandler) Handle(evalContext *EvalContext) error { executionError := "" annotationData := simplejson.New() - if evalContext.Firing { - annotationData = simplejson.NewFromAny(evalContext.EvalMatches) + if len(evalContext.EvalMatches) > 0 { + annotationData.Set("evalMatches", simplejson.NewFromAny(evalContext.EvalMatches)) } if evalContext.Error != nil { executionError = evalContext.Error.Error() - annotationData.Set("errorMessage", executionError) - } - - if evalContext.NoDataFound { - annotationData.Set("no_data", true) + annotationData.Set("error", executionError) + } else if evalContext.NoDataFound { + annotationData.Set("noData", true) } countStateResult(evalContext.Rule.State) diff --git a/public/app/features/alerting/alert_tab_ctrl.ts b/public/app/features/alerting/alert_tab_ctrl.ts index b21e5363ad8..63d192099c0 100644 --- a/public/app/features/alerting/alert_tab_ctrl.ts +++ b/public/app/features/alerting/alert_tab_ctrl.ts @@ -81,14 +81,23 @@ 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.metrics = alertDef.joinEvalMatches(ah.data, ', '); + ah.reason = ""; - if (ah.data.errorMessage) { - ah.metrics = "Error: " + ah.data.errorMessage; + 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.no_data) { - ah.metrics = "(due to no data)"; + 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"; } return ah; diff --git a/public/app/features/alerting/partials/alert_tab.html b/public/app/features/alerting/partials/alert_tab.html index 4c63c4507fc..b18f49c69a1 100644 --- a/public/app/features/alerting/partials/alert_tab.html +++ b/public/app/features/alerting/partials/alert_tab.html @@ -148,16 +148,20 @@
  1. +
    +
    +
    +
    - {{ah.stateModel.text}} - {{ah.metrics}} + {{ah.stateModel.text}} + {{ah.time}}
    - {{ah.time}} +  {{ah.metrics}}
    diff --git a/public/sass/components/edit_sidemenu.scss b/public/sass/components/edit_sidemenu.scss index d7844ab6f36..5da2f6a21ce 100644 --- a/public/sass/components/edit_sidemenu.scss +++ b/public/sass/components/edit_sidemenu.scss @@ -26,6 +26,7 @@ display: block; color: $text-color; margin: 0 0 1.5rem 1rem; + white-space: nowrap; } } From 89189221799a4b3057db043cd90013e7fa77fe48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 18 May 2017 14:10:12 +0200 Subject: [PATCH 2/3] alerting: fixed issue with included alerting error & no data reasons, fixes #8412 --- public/app/features/alerting/alert_def.ts | 25 ++++++++++++++++++- .../app/features/alerting/alert_tab_ctrl.ts | 20 +-------------- .../features/alerting/partials/alert_tab.html | 2 +- .../app/plugins/panel/alertlist/module.html | 2 +- public/app/plugins/panel/alertlist/module.ts | 2 +- 5 files changed, 28 insertions(+), 23 deletions(-) diff --git a/public/app/features/alerting/alert_def.ts b/public/app/features/alerting/alert_def.ts index c65a35878e7..dc5be8b41c4 100644 --- a/public/app/features/alerting/alert_def.ts +++ b/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, }; diff --git a/public/app/features/alerting/alert_tab_ctrl.ts b/public/app/features/alerting/alert_tab_ctrl.ts index 63d192099c0..938b24ebc21 100644 --- a/public/app/features/alerting/alert_tab_ctrl.ts +++ b/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; }); }); diff --git a/public/app/features/alerting/partials/alert_tab.html b/public/app/features/alerting/partials/alert_tab.html index b18f49c69a1..2e7956d4a6e 100644 --- a/public/app/features/alerting/partials/alert_tab.html +++ b/public/app/features/alerting/partials/alert_tab.html @@ -161,7 +161,7 @@ {{ah.time}}
    -  {{ah.metrics}} + {{ah.info}}
    diff --git a/public/app/plugins/panel/alertlist/module.html b/public/app/plugins/panel/alertlist/module.html index 2940e2ae33e..2c0cb00d2ef 100644 --- a/public/app/plugins/panel/alertlist/module.html +++ b/public/app/plugins/panel/alertlist/module.html @@ -40,7 +40,7 @@ {{al.stateModel.text}} - {{al.metrics}} + {{al.info}} diff --git a/public/app/plugins/panel/alertlist/module.ts b/public/app/plugins/panel/alertlist/module.ts index 3795e1c8197..e120ed05b6d 100644 --- a/public/app/plugins/panel/alertlist/module.ts +++ b/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; }); }); From 59f3cca135d2dd64cf69fdf92331ccdd028820ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 18 May 2017 14:13:05 +0200 Subject: [PATCH 3/3] docs: updated changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88c5e9b08f5..55c4b60cf52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ## Bug fixes * **Graphite**: Fixed issue with Toggle edit mode did in query editor [#8377](https://github.com/grafana/grafana/issues/8377) +* **Alerting**: Fixed issue with state history not showing query execution errors [#8412](https://github.com/grafana/grafana/issues/8412) +* **Alerting**: Fixed issue with missing state history events/annotations when using sqlite3 database [#7992](https://github.com/grafana/grafana/issues/7992) +* **Sqlite**: Fixed with database table locked and using sqlite3 database [#7992](https://github.com/grafana/grafana/issues/7992) # 4.3.0-beta1 (2017-05-12)