From 7dece3ff0cb7b4401933d1dcdf8d4b8113415ed7 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 15 Dec 2016 07:35:32 +0100 Subject: [PATCH 1/7] test(mqe): solves brittle unit test --- pkg/tsdb/mqe/response_parser.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/tsdb/mqe/response_parser.go b/pkg/tsdb/mqe/response_parser.go index ca2f29b4811..283098e74f3 100644 --- a/pkg/tsdb/mqe/response_parser.go +++ b/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 + " " } From e3b53fe599187388beff153b1f02d87a3472ba81 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 15 Dec 2016 07:35:54 +0100 Subject: [PATCH 2/7] test(mqe): adds test for double function usage --- pkg/tsdb/mqe/types_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/tsdb/mqe/types_test.go b/pkg/tsdb/mqe/types_test.go index 27b400b3c08..1138e0599e7 100644 --- a/pkg/tsdb/mqe/types_test.go +++ b/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{ From f907330c9eee2498e499838e187381688aae3f92 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 15 Dec 2016 08:27:21 +0100 Subject: [PATCH 3/7] tech(mailer): improves error when grafana cannot read open cert/key file ref #6949 --- pkg/services/notifications/mailer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/services/notifications/mailer.go b/pkg/services/notifications/mailer.go index 4bcce804ee4..c2d2cd5beca 100644 --- a/pkg/services/notifications/mailer.go +++ b/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} } From 51c4385c92ed41439a3f51253e1fc5f37a4552e6 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 15 Dec 2016 08:52:43 +0100 Subject: [PATCH 4/7] fix(mqe): only parse none empty functions --- pkg/tsdb/mqe/model_parser.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/tsdb/mqe/model_parser.go b/pkg/tsdb/mqe/model_parser.go index 19c7cca40c8..d139bea9c15 100644 --- a/pkg/tsdb/mqe/model_parser.go +++ b/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 From 6a161216deb3687a82755b4d0119aa14a4b220c3 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 15 Dec 2016 10:54:22 +0100 Subject: [PATCH 5/7] fix(influxdb): fixes bug with empty tagColumn for annotations --- .../datasource/influxdb/influx_series.js | 2 +- .../influxdb/specs/influx_series_specs.ts | 70 +++++++++++++------ 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/public/app/plugins/datasource/influxdb/influx_series.js b/public/app/plugins/datasource/influxdb/influx_series.js index 2815330a683..c422bb87d00 100644 --- a/public/app/plugins/datasource/influxdb/influx_series.js +++ b/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; } }); diff --git a/public/app/plugins/datasource/influxdb/specs/influx_series_specs.ts b/public/app/plugins/datasource/influxdb/specs/influx_series_specs.ts index da6c14719a2..2daa21d7e30 100644 --- a/public/app/plugins/datasource/influxdb/specs/influx_series_specs.ts +++ b/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'); + }); }); }); }); From ca7baca21d8e2acd09c3e590f0cf2ca183941aae Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 15 Dec 2016 11:13:19 +0100 Subject: [PATCH 6/7] feat(alerting): adds ok as no data option closes #6866 --- pkg/models/alert.go | 5 +++-- public/app/features/alerting/alert_def.ts | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/models/alert.go b/pkg/models/alert.go index 67170a0dd36..0d2289c0678 100644 --- a/pkg/models/alert.go +++ b/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 { diff --git a/public/app/features/alerting/alert_def.ts b/public/app/features/alerting/alert_def.ts index 804a9f3d083..fd08823c4a9 100644 --- a/public/app/features/alerting/alert_def.ts +++ b/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 = [ From 0c8193a6af4ad47c435030be78b1dd08b123f818 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 15 Dec 2016 11:15:06 +0100 Subject: [PATCH 7/7] docs(changelog): adds note about closing #6866 --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a33102ef8b0..50b814f5149 100644 --- a/CHANGELOG.md +++ b/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)