Explorar o código

feat(alerting): added eval match to test results

Torkel Ödegaard %!s(int64=9) %!d(string=hai) anos
pai
achega
5cf9711862

+ 3 - 0
pkg/api/alerting.go

@@ -106,6 +106,9 @@ func AlertTest(c *middleware.Context, dto dtos.AlertTestCommand) Response {
 	for _, log := range res.Logs {
 	for _, log := range res.Logs {
 		dtoRes.Logs = append(dtoRes.Logs, &dtos.AlertTestResultLog{Message: log.Message, Data: log.Data})
 		dtoRes.Logs = append(dtoRes.Logs, &dtos.AlertTestResultLog{Message: log.Message, Data: log.Data})
 	}
 	}
+	for _, match := range res.EvalMatches {
+		dtoRes.EvalMatches = append(dtoRes.EvalMatches, &dtos.EvalMatch{Metric: match.Metric, Value: match.Value})
+	}
 
 
 	dtoRes.TimeMs = fmt.Sprintf("%1.3fms", res.GetDurationMs())
 	dtoRes.TimeMs = fmt.Sprintf("%1.3fms", res.GetDurationMs())
 
 

+ 9 - 7
pkg/api/dtos/alerting.go

@@ -35,10 +35,11 @@ type AlertTestCommand struct {
 }
 }
 
 
 type AlertTestResult struct {
 type AlertTestResult struct {
-	Firing bool                  `json:"firing"`
-	TimeMs string                `json:"timeMs"`
-	Error  string                `json:"error,omitempty"`
-	Logs   []*AlertTestResultLog `json:"logs,omitempty"`
+	Firing      bool                  `json:"firing"`
+	TimeMs      string                `json:"timeMs"`
+	Error       string                `json:"error,omitempty"`
+	EvalMatches []*EvalMatch          `json:"matches,omitempty"`
+	Logs        []*AlertTestResultLog `json:"logs,omitempty"`
 }
 }
 
 
 type AlertTestResultLog struct {
 type AlertTestResultLog struct {
@@ -46,7 +47,8 @@ type AlertTestResultLog struct {
 	Data    interface{} `json:"data"`
 	Data    interface{} `json:"data"`
 }
 }
 
 
-type AlertEvent struct {
-	Metric string  `json:"metric"`
-	Value  float64 `json:"value"`
+type EvalMatch struct {
+	Tags   map[string]string `json:"tags,omitempty"`
+	Metric string            `json:"metric"`
+	Value  float64           `json:"value"`
 }
 }

+ 2 - 1
pkg/services/alerting/conditions/query.go

@@ -53,8 +53,9 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) {
 				Metric: series.Name,
 				Metric: series.Name,
 				Value:  reducedValue,
 				Value:  reducedValue,
 			})
 			})
-			context.Firing = true
 		}
 		}
+
+		context.Firing = evalMatch
 	}
 	}
 }
 }
 
 

+ 11 - 0
public/app/features/alerting/alert_model.ts

@@ -0,0 +1,11 @@
+ ///<reference path="../../headers/common.d.ts" />
+
+import _ from 'lodash';
+import {QueryPart} from 'app/core/components/query_part/query_part';
+import alertDef from './alert_def';
+
+export class AlertModel {
+  constructor() {
+  }
+}
+

+ 7 - 0
public/app/features/alerting/partials/alert_tab.html

@@ -67,6 +67,13 @@
             <label class="gf-form-label query-keyword" ng-show="conditionModel.evaluator.params.length === 2">TO</label>
             <label class="gf-form-label query-keyword" ng-show="conditionModel.evaluator.params.length === 2">TO</label>
 						<input class="gf-form-input max-width-7" type="number" ng-if="conditionModel.evaluator.params.length === 2" ng-model="conditionModel.evaluator.params[1]" ng-change="ctrl.evaluatorParamsChanged()"></input>
 						<input class="gf-form-input max-width-7" type="number" ng-if="conditionModel.evaluator.params.length === 2" ng-model="conditionModel.evaluator.params[1]" ng-change="ctrl.evaluatorParamsChanged()"></input>
 					</div>
 					</div>
+					<gf-form-switch class="gf-form"
+                        label="OR NO VALUE"
+                        label-class="query-keyword"
+                        checked="dashboard.editable"
+                        >
+					</gf-form-switch>
+
 					<div class="gf-form">
 					<div class="gf-form">
 						<label class="gf-form-label">
 						<label class="gf-form-label">
 							<a class="pointer" tabindex="1" ng-click="ctrl.removeCondition($index)">
 							<a class="pointer" tabindex="1" ng-click="ctrl.removeCondition($index)">

+ 1 - 1
public/app/features/alerting/threshold_mapper.ts

@@ -53,10 +53,10 @@ export class ThresholdMapper {
             thresholds.push({value: value1, op: 'gt'});
             thresholds.push({value: value1, op: 'gt'});
             thresholds.push({value: value2, op: 'lt'});
             thresholds.push({value: value2, op: 'lt'});
           }
           }
-
           break;
           break;
         }
         }
       }
       }
+      break;
     }
     }
 
 
     for (var t of panel.thresholds) {
     for (var t of panel.thresholds) {