From f2436fc7cd6ab27d1830069ce40efb4bcf428b31 Mon Sep 17 00:00:00 2001 From: bergquist Date: Wed, 10 Aug 2016 13:48:44 +0200 Subject: [PATCH 1/7] test(alerting): add tests for simple reducer --- .../alerting/conditions/reducer_test.go | 33 +++++++++++++++++++ pkg/services/alerting/evaluator.go | 15 --------- 2 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 pkg/services/alerting/conditions/reducer_test.go delete mode 100644 pkg/services/alerting/evaluator.go diff --git a/pkg/services/alerting/conditions/reducer_test.go b/pkg/services/alerting/conditions/reducer_test.go new file mode 100644 index 00000000000..c6f0509bbc2 --- /dev/null +++ b/pkg/services/alerting/conditions/reducer_test.go @@ -0,0 +1,33 @@ +package conditions + +import ( + "testing" + + "github.com/grafana/grafana/pkg/tsdb" + . "github.com/smartystreets/goconvey/convey" +) + +func TestSimpleReducer(t *testing.T) { + Convey("Test simple reducer", t, func() { + Convey("can calculate avg of time serie", func() { + result := testReducer("avg", 1, 2, 3) + So(result, ShouldEqual, float64(2)) + }) + }) +} + +func testReducer(typ string, datapoints ...float64) float64 { + reducer := NewSimpleReducer(typ) + var timeserie [][2]float64 + dummieTimestamp := float64(521452145) + + for _, v := range datapoints { + timeserie = append(timeserie, [2]float64{v, dummieTimestamp}) + } + + tsdb := &tsdb.TimeSeries{ + Name: "test time serie", + Points: timeserie, + } + return reducer.Reduce(tsdb) +} diff --git a/pkg/services/alerting/evaluator.go b/pkg/services/alerting/evaluator.go deleted file mode 100644 index bed5ce9709b..00000000000 --- a/pkg/services/alerting/evaluator.go +++ /dev/null @@ -1,15 +0,0 @@ -package alerting - -type compareFn func(float64, float64) bool - -func evalCondition(level Level, result float64) bool { - return operators[level.Operator](result, level.Value) -} - -var operators = map[string]compareFn{ - ">": func(num1, num2 float64) bool { return num1 > num2 }, - ">=": func(num1, num2 float64) bool { return num1 >= num2 }, - "<": func(num1, num2 float64) bool { return num1 < num2 }, - "<=": func(num1, num2 float64) bool { return num1 <= num2 }, - "": func(num1, num2 float64) bool { return false }, -} From 95c1a4a936e5a0672da201731089f0edcaa13121 Mon Sep 17 00:00:00 2001 From: bergquist Date: Wed, 10 Aug 2016 14:06:17 +0200 Subject: [PATCH 2/7] feat(alerting): implement more simple reducers --- pkg/services/alerting/conditions/reducer.go | 23 +++++++++++++++++ .../alerting/conditions/reducer_test.go | 25 +++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/pkg/services/alerting/conditions/reducer.go b/pkg/services/alerting/conditions/reducer.go index d75d1ff9167..92ba268b13a 100644 --- a/pkg/services/alerting/conditions/reducer.go +++ b/pkg/services/alerting/conditions/reducer.go @@ -19,6 +19,29 @@ func (s *SimpleReducer) Reduce(series *tsdb.TimeSeries) float64 { value += point[0] } value = value / float64(len(series.Points)) + case "sum": + for _, point := range series.Points { + value += point[0] + } + case "min": + for i, point := range series.Points { + if i == 0 { + value = point[0] + } + + if value > point[0] { + value = point[0] + } + } + case "max": + for _, point := range series.Points { + if value < point[0] { + value = point[0] + } + } + case "mean": + meanPosition := int64(len(series.Points) / 2) + value = series.Points[meanPosition][0] } return value diff --git a/pkg/services/alerting/conditions/reducer_test.go b/pkg/services/alerting/conditions/reducer_test.go index c6f0509bbc2..ed3c89fbbdd 100644 --- a/pkg/services/alerting/conditions/reducer_test.go +++ b/pkg/services/alerting/conditions/reducer_test.go @@ -8,11 +8,32 @@ import ( ) func TestSimpleReducer(t *testing.T) { - Convey("Test simple reducer", t, func() { - Convey("can calculate avg of time serie", func() { + Convey("Test simple reducer by calculating", t, func() { + Convey("avg", func() { result := testReducer("avg", 1, 2, 3) So(result, ShouldEqual, float64(2)) }) + + Convey("sum", func() { + result := testReducer("sum", 1, 2, 3) + So(result, ShouldEqual, float64(6)) + }) + + Convey("min", func() { + result := testReducer("min", 3, 2, 1) + So(result, ShouldEqual, float64(1)) + }) + + Convey("max", func() { + result := testReducer("max", 1, 2, 3) + So(result, ShouldEqual, float64(3)) + }) + + Convey("mean odd numbers", func() { + result := testReducer("mean", 1, 2, 3000) + So(result, ShouldEqual, float64(2)) + }) + }) } From 124961a9e3e75c8e618da583c7951b1934b499d1 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 10 Aug 2016 21:23:58 +0300 Subject: [PATCH 3/7] Explicitly set charset to utf-8 in viewJson(), fixes #5719. (#5774) --- public/app/features/dashboard/dashnav/dashnav.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/app/features/dashboard/dashnav/dashnav.ts b/public/app/features/dashboard/dashnav/dashnav.ts index 7d25e352e9e..97088fd6e5b 100644 --- a/public/app/features/dashboard/dashnav/dashnav.ts +++ b/public/app/features/dashboard/dashnav/dashnav.ts @@ -191,7 +191,7 @@ export class DashNavCtrl { $scope.viewJson = function() { var clone = $scope.dashboard.getSaveModelClone(); var html = angular.toJson(clone, true); - var uri = "data:application/json," + encodeURIComponent(html); + var uri = "data:application/json;charset=utf-8," + encodeURIComponent(html); var newWindow = window.open(uri); }; From 2c4ab4af025787aa89a334419ae5e9e1474d3586 Mon Sep 17 00:00:00 2001 From: Jeremy Bingham Date: Wed, 10 Aug 2016 22:36:14 -0700 Subject: [PATCH 4/7] Mac grafana wrapper script (#5779) * One of the homebrew folks first asked for a wrapper script to make launching grafana easier. Later I was asked to remove it and submit it upstream, so here it is. * add instructions for installing grafana HEAD from git with homebrew back to the docs --- docs/sources/installation/mac.md | 13 +++++++++++++ packaging/mac/bin/grafana | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 packaging/mac/bin/grafana diff --git a/docs/sources/installation/mac.md b/docs/sources/installation/mac.md index b68cadbd948..640db6d0d6f 100644 --- a/docs/sources/installation/mac.md +++ b/docs/sources/installation/mac.md @@ -24,4 +24,17 @@ brew update brew reinstall grafana ``` +------------- +You can also install the latest unstable grafana from git: + + +``` +brew install --HEAD grafana/grafana/grafana +``` + +To upgrade grafana if you've installed from HEAD: + +``` +brew reinstall --HEAD grafana/grafana/grafana +``` diff --git a/packaging/mac/bin/grafana b/packaging/mac/bin/grafana new file mode 100755 index 00000000000..fb33079079e --- /dev/null +++ b/packaging/mac/bin/grafana @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +DAEMON=grafana-server +EXECUTABLE=/usr/local/bin/grafana-server +CONFIG=/usr/local/etc/grafana/grafana.ini +HOMEPATH=/usr/local/share/grafana +LOGPATH=/usr/local/var/log/grafana +DATAPATH=/usr/local/var/lib/grafana +PLUGINPATH=/usr/local/var/lib/grafana/plugins + +case "$1" in +start) + $EXECUTABLE --config=$CONFIG --homepath=$HOMEPATH cfg:default.paths.logs=$LOGPATH cfg:default.paths.data=$DATAPATH cfg:default.paths.plugins=$PLUGINPATH 2> /dev/null & + [ $? -eq 0 ] && echo "$DAEMON started" +;; +stop) + killall $DAEMON + [ $? -eq 0 ] && echo "$DAEMON stopped" +;; +restart) + $0 stop + $0 start +;; +*) + echo "Usage: $0 (start|stop|restart)" +;; +esac From 7150571e60737900c323c6e284de30413cd4225d Mon Sep 17 00:00:00 2001 From: Jeremy Bingham Date: Wed, 10 Aug 2016 22:36:14 -0700 Subject: [PATCH 5/7] Mac grafana wrapper script (#5779) * One of the homebrew folks first asked for a wrapper script to make launching grafana easier. Later I was asked to remove it and submit it upstream, so here it is. * add instructions for installing grafana HEAD from git with homebrew back to the docs --- docs/sources/installation/mac.md | 13 +++++++++++++ packaging/mac/bin/grafana | 26 ++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100755 packaging/mac/bin/grafana diff --git a/docs/sources/installation/mac.md b/docs/sources/installation/mac.md index b68cadbd948..640db6d0d6f 100644 --- a/docs/sources/installation/mac.md +++ b/docs/sources/installation/mac.md @@ -24,4 +24,17 @@ brew update brew reinstall grafana ``` +------------- +You can also install the latest unstable grafana from git: + + +``` +brew install --HEAD grafana/grafana/grafana +``` + +To upgrade grafana if you've installed from HEAD: + +``` +brew reinstall --HEAD grafana/grafana/grafana +``` diff --git a/packaging/mac/bin/grafana b/packaging/mac/bin/grafana new file mode 100755 index 00000000000..fb33079079e --- /dev/null +++ b/packaging/mac/bin/grafana @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +DAEMON=grafana-server +EXECUTABLE=/usr/local/bin/grafana-server +CONFIG=/usr/local/etc/grafana/grafana.ini +HOMEPATH=/usr/local/share/grafana +LOGPATH=/usr/local/var/log/grafana +DATAPATH=/usr/local/var/lib/grafana +PLUGINPATH=/usr/local/var/lib/grafana/plugins + +case "$1" in +start) + $EXECUTABLE --config=$CONFIG --homepath=$HOMEPATH cfg:default.paths.logs=$LOGPATH cfg:default.paths.data=$DATAPATH cfg:default.paths.plugins=$PLUGINPATH 2> /dev/null & + [ $? -eq 0 ] && echo "$DAEMON started" +;; +stop) + killall $DAEMON + [ $? -eq 0 ] && echo "$DAEMON stopped" +;; +restart) + $0 stop + $0 start +;; +*) + echo "Usage: $0 (start|stop|restart)" +;; +esac From 780ec92dd8ddac597871019743005ac1ebdb772e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 11 Aug 2016 07:39:34 +0200 Subject: [PATCH 6/7] fix(docs): fixed plugins docs, fixes #5777 --- docs/sources/plugins/installation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/sources/plugins/installation.md b/docs/sources/plugins/installation.md index c83a54bdce3..e8e69af6e00 100644 --- a/docs/sources/plugins/installation.md +++ b/docs/sources/plugins/installation.md @@ -9,7 +9,7 @@ page_keywords: grafana, plugins, documentation The easiest way to install plugins is by using the CLI tool grafana-cli which is bundled with grafana. Before any modification take place after modifying plugins, grafana-server needs to be restarted. ### Grafana plugin directory -On Linux systems the grafana-cli will assume that the grafana plugin directory is `/var/lib/grafana/plugins`. It's possible to override the directory which grafana-cli will operate on by specifying the --path flag. On Windows systems this parameter have to be specified for every call. +On Linux systems the grafana-cli will assume that the grafana plugin directory is `/var/lib/grafana/plugins`. It's possible to override the directory which grafana-cli will operate on by specifying the --pluginsDir flag. On Windows systems this parameter have to be specified for every call. ### Grafana-cli commands From 0d26bc63aee291f0f89c1fee54b3967278ffd58e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 11 Aug 2016 10:29:28 +0200 Subject: [PATCH 7/7] fix(graphite): minor fix/improvement to graphite error handling when doing metric exploration in query editor, fixes #5778 --- public/app/core/services/alert_srv.ts | 13 ++++++++++++- .../app/plugins/datasource/graphite/query_ctrl.ts | 5 +++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/public/app/core/services/alert_srv.ts b/public/app/core/services/alert_srv.ts index edfff2e8d00..d8699b46fa6 100644 --- a/public/app/core/services/alert_srv.ts +++ b/public/app/core/services/alert_srv.ts @@ -16,7 +16,7 @@ export class AlertSrv { init() { this.$rootScope.onAppEvent('alert-error', (e, alert) => { - this.set(alert[0], alert[1], 'error', 0); + this.set(alert[0], alert[1], 'error', 7000); }, this.$rootScope); this.$rootScope.onAppEvent('alert-warning', (e, alert) => { @@ -27,10 +27,21 @@ export class AlertSrv { this.set(alert[0], alert[1], 'success', 3000); }, this.$rootScope); + appEvents.on('alert-error', options => { + this.set(options[0], options[1], 'error', 7000); + }); + appEvents.on('confirm-modal', this.showConfirmModal.bind(this)); } set(title, text, severity, timeout) { + if (_.isObject(text)) { + console.log('alert error', text); + if (text.statusText) { + text = `HTTP Error (${text.status}) ${text.statusText}`; + } + } + var newAlert = { title: title || '', text: text || '', diff --git a/public/app/plugins/datasource/graphite/query_ctrl.ts b/public/app/plugins/datasource/graphite/query_ctrl.ts index 84b71685f17..93977dc143d 100644 --- a/public/app/plugins/datasource/graphite/query_ctrl.ts +++ b/public/app/plugins/datasource/graphite/query_ctrl.ts @@ -9,6 +9,7 @@ import moment from 'moment'; import gfunc from './gfunc'; import {Parser} from './parser'; import {QueryCtrl} from 'app/plugins/sdk'; +import appEvents from 'app/core/app_events'; export class GraphiteQueryCtrl extends QueryCtrl { static templateUrl = 'partials/query.editor.html'; @@ -141,7 +142,7 @@ export class GraphiteQueryCtrl extends QueryCtrl { } } }).catch(err => { - this.error = err.message || 'Failed to issue metric query'; + appEvents.emit('alert-error', ['Error', err]); }); } @@ -178,7 +179,7 @@ export class GraphiteQueryCtrl extends QueryCtrl { altSegments.unshift(this.uiSegmentSrv.newSegment('*')); return altSegments; }).catch(err => { - this.error = err.message || 'Failed to issue metric query'; + appEvents.emit('alert-error', ['Error', err]); return []; }); }