Browse Source

Merge branch 'master' of github.com:grafana/grafana

Torkel Ödegaard 9 years ago
parent
commit
0c94194a5b

+ 1 - 0
CHANGELOG.md

@@ -14,6 +14,7 @@
 * **Influxdb**: Support multiple tags in InfluxDB annotations. [#4550](https://github.com/grafana/grafana/pull/4550), thx [@adrianlzt](https://github.com/adrianlzt)
 * **LDAP**:  Basic Auth now supports LDAP username and password, [#6940](https://github.com/grafana/grafana/pull/6940), thx [@utkarshcmu](https://github.com/utkarshcmu)
 * **LDAP**: Now works with Auth Proxy, role and organisation mapping & sync will regularly be performed. [#6895](https://github.com/grafana/grafana/pull/6895), thx [@Seuf](https://github.com/seuf)
+* **Alerting**: Adds OK as no data option. [#6866](https://github.com/grafana/grafana/issues/6866)
 
 ### Bugfixes
 * **API**: HTTP API for deleting org returning incorrect message for a non-existing org [#6679](https://github.com/grafana/grafana/issues/6679)

+ 3 - 2
pkg/models/alert.go

@@ -20,9 +20,10 @@ const (
 )
 
 const (
+	NoDataSetOK       NoDataOption = "ok"
 	NoDataSetNoData   NoDataOption = "no_data"
-	NoDataSetAlerting NoDataOption = "alerting"
 	NoDataKeepState   NoDataOption = "keep_state"
+	NoDataSetAlerting NoDataOption = "alerting"
 )
 
 const (
@@ -35,7 +36,7 @@ func (s AlertStateType) IsValid() bool {
 }
 
 func (s NoDataOption) IsValid() bool {
-	return s == NoDataSetNoData || s == NoDataSetAlerting || s == NoDataKeepState
+	return s == NoDataSetNoData || s == NoDataSetAlerting || s == NoDataKeepState || s == NoDataSetOK
 }
 
 func (s NoDataOption) ToAlertState() AlertStateType {

+ 1 - 1
pkg/services/notifications/mailer.go

@@ -94,7 +94,7 @@ func createDialer() (*gomail.Dialer, error) {
 	if setting.Smtp.CertFile != "" {
 		cert, err := tls.LoadX509KeyPair(setting.Smtp.CertFile, setting.Smtp.KeyFile)
 		if err != nil {
-			return nil, err
+			return nil, fmt.Errorf("Could not load cert or key file. error: %v", err)
 		}
 		tlsconfig.Certificates = []tls.Certificate{cert}
 	}

+ 3 - 1
pkg/tsdb/mqe/model_parser.go

@@ -49,7 +49,9 @@ func (qp *QueryParser) Parse(model *simplejson.Json, dsInfo *models.DataSource,
 			return nil, err
 		}
 
-		functions = append(functions, f)
+		if f.Func != "" {
+			functions = append(functions, f)
+		}
 	}
 
 	query.FunctionList = functions

+ 2 - 0
pkg/tsdb/mqe/response_parser.go

@@ -81,6 +81,8 @@ func (parser *ResponseParser) Parse(res *http.Response, queryRef *Query) ([]*tsd
 				if key == "cluster" && queryRef.AddClusterToAlias {
 					namePrefix += value + " "
 				}
+			}
+			for key, value := range mqeSerie.Tagset {
 				if key == "host" && queryRef.AddHostToAlias {
 					namePrefix += value + " "
 				}

+ 22 - 0
pkg/tsdb/mqe/types_test.go

@@ -49,6 +49,28 @@ func TestWildcardExpansion(t *testing.T) {
 			So(expandeQueries[2].RawQuery, ShouldEqual, fmt.Sprintf("`os.cpu.1.idle`|aggregate.min {cpu} where cluster in ('demoapp-1', 'demoapp-2') and host in ('staples-lab-1', 'staples-lab-2') from %v to %v", from, to))
 		})
 
+		Convey("With two aggregate functions", func() {
+			query := &Query{
+				Metrics: []Metric{
+					Metric{Metric: "os.cpu.3.idle", Alias: ""},
+				},
+				Hosts:             []string{"staples-lab-1", "staples-lab-2"},
+				Cluster:           []string{"demoapp-1", "demoapp-2"},
+				AddClusterToAlias: false,
+				AddHostToAlias:    false,
+				FunctionList: []Function{
+					Function{Func: "aggregate.min"},
+					Function{Func: "aggregate.max"},
+				},
+				TimeRange: &tsdb.TimeRange{Now: now, From: "5m", To: "now"},
+			}
+
+			expandeQueries, err := query.Build(availableMetrics)
+			So(err, ShouldBeNil)
+			So(len(expandeQueries), ShouldEqual, 1)
+			So(expandeQueries[0].RawQuery, ShouldEqual, fmt.Sprintf("`os.cpu.3.idle`|aggregate.min|aggregate.max where cluster in ('demoapp-1', 'demoapp-2') and host in ('staples-lab-1', 'staples-lab-2') from %v to %v", from, to))
+		})
+
 		Convey("Containg wildcard series", func() {
 			query := &Query{
 				Metrics: []Metric{

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

@@ -47,6 +47,7 @@ var noDataModes = [
   {text: 'Alerting', value: 'alerting'},
   {text: 'No Data', value: 'no_data'},
   {text: 'Keep Last State', value: 'keep_state'},
+  {text: 'Ok', value: 'ok'},
 ];
 
 var executionErrorModes = [

+ 1 - 1
public/app/plugins/datasource/influxdb/influx_series.js

@@ -89,7 +89,7 @@ function (_, TableModel) {
         if (column === 'sequence_number') { return; }
         if (!titleCol) { titleCol = index; }
         if (column === self.annotation.titleColumn) { titleCol = index; return; }
-        if (_.includes(self.annotation.tagsColumn.replace(' ', '').split(","), column)) { tagsCol.push(index); return; }
+        if (_.includes((self.annotation.tagsColumn || '').replace(' ', '').split(","), column)) { tagsCol.push(index); return; }
         if (column === self.annotation.textColumn) { textCol = index; return; }
       });
 

+ 48 - 22
public/app/plugins/datasource/influxdb/specs/influx_series_specs.ts

@@ -208,30 +208,56 @@ describe('when generating timeseries from influxdb response', function() {
   });
 
   describe('given annotation response', function() {
-    var options = {
-      alias: '',
-      annotation: {
-        tagsColumn: 'datacenter, source'
-      },
-      series: [
-        {
-          name: "logins.count",
-          tags:  {datacenter: 'Africa', server: 'server2'},
-          columns: ["time", "datacenter", "hostname", "source", "value"],
-          values: [
-            [1481549440372, "America", "10.1.100.10", "backend", 215.7432653659507],
-          ]
-        }
-      ]
-    };
+    describe('with empty tagsColumn', function() {
+      var options = {
+        alias: '',
+        annotation: {},
+        series: [
+          {
+            name: "logins.count",
+            tags:  {datacenter: 'Africa', server: 'server2'},
+            columns: ["time", "datacenter", "hostname", "source", "value"],
+            values: [
+              [1481549440372, "America", "10.1.100.10", "backend", 215.7432653659507],
+            ]
+          }
+        ]
+      };
+
+      it('should multiple tags', function() {
+        var series = new InfluxSeries(options);
+        var annotations = series.getAnnotations();
 
-    it('should multiple tags', function() {
-      var series = new InfluxSeries(options);
-      var annotations = series.getAnnotations();
+        expect(annotations[0].tags.length).to.be(0);
+      });
+    });
 
-      expect(annotations[0].tags.length).to.be(2);
-      expect(annotations[0].tags[0]).to.be('America');
-      expect(annotations[0].tags[1]).to.be('backend');
+    describe('given annotation response', function() {
+      var options = {
+        alias: '',
+        annotation: {
+          tagsColumn: 'datacenter, source'
+        },
+        series: [
+          {
+            name: "logins.count",
+            tags:  {datacenter: 'Africa', server: 'server2'},
+            columns: ["time", "datacenter", "hostname", "source", "value"],
+            values: [
+              [1481549440372, "America", "10.1.100.10", "backend", 215.7432653659507],
+            ]
+          }
+        ]
+      };
+
+      it('should multiple tags', function() {
+        var series = new InfluxSeries(options);
+        var annotations = series.getAnnotations();
+
+        expect(annotations[0].tags.length).to.be(2);
+        expect(annotations[0].tags[0]).to.be('America');
+        expect(annotations[0].tags[1]).to.be('backend');
+      });
     });
   });
 });