From c17064fb4468e1f17f7fcb879fdea617b589436c Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 2 Dec 2016 16:18:40 +0100 Subject: [PATCH 1/4] fix(webdav): adds missing auth headers closes #6779 --- pkg/components/imguploader/webdavuploader.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/components/imguploader/webdavuploader.go b/pkg/components/imguploader/webdavuploader.go index 3b59e1690fd..541a44d4b4a 100644 --- a/pkg/components/imguploader/webdavuploader.go +++ b/pkg/components/imguploader/webdavuploader.go @@ -7,7 +7,6 @@ import ( "net/http" "net/url" "path" - "time" "github.com/grafana/grafana/pkg/util" ) @@ -19,14 +18,17 @@ type WebdavUploader struct { } func (u *WebdavUploader) Upload(pa string) (string, error) { - client := http.Client{Timeout: time.Duration(10 * time.Second)} - url, _ := url.Parse(u.url) url.Path = path.Join(url.Path, util.GetRandomString(20)+".png") imgData, err := ioutil.ReadFile(pa) req, err := http.NewRequest("PUT", url.String(), bytes.NewReader(imgData)) - res, err := client.Do(req) + + if u.username != "" { + req.SetBasicAuth(u.username, u.password) + } + + res, err := http.DefaultClient.Do(req) if err != nil { return "", err From dd3060fdc3dcdbecb329fd50216f1de57d392c6c Mon Sep 17 00:00:00 2001 From: bergquist Date: Fri, 2 Dec 2016 23:44:14 +0100 Subject: [PATCH 2/4] feat(alerting): calculate avg of valid points --- pkg/services/alerting/conditions/reducer.go | 7 +++++-- pkg/services/alerting/conditions/reducer_test.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pkg/services/alerting/conditions/reducer.go b/pkg/services/alerting/conditions/reducer.go index b2d17f4f8ab..b7816a61d1d 100644 --- a/pkg/services/alerting/conditions/reducer.go +++ b/pkg/services/alerting/conditions/reducer.go @@ -27,13 +27,17 @@ func (s *SimpleReducer) Reduce(series *tsdb.TimeSeries) null.Float { switch s.Type { case "avg": + validPointsCount := 0 for _, point := range series.Points { if point[0].Valid { value += point[0].Float64 + validPointsCount += 1 allNull = false } } - value = value / float64(len(series.Points)) + if validPointsCount > 0 { + value = value / float64(validPointsCount) + } case "sum": for _, point := range series.Points { if point[0].Valid { @@ -90,7 +94,6 @@ func (s *SimpleReducer) Reduce(series *tsdb.TimeSeries) null.Float { value = (values[(length/2)-1] + values[length/2]) / 2 } } - } if allNull { diff --git a/pkg/services/alerting/conditions/reducer_test.go b/pkg/services/alerting/conditions/reducer_test.go index 477595c5af1..badf868e8fc 100644 --- a/pkg/services/alerting/conditions/reducer_test.go +++ b/pkg/services/alerting/conditions/reducer_test.go @@ -16,6 +16,20 @@ func TestSimpleReducer(t *testing.T) { So(result, ShouldEqual, float64(2)) }) + Convey("avg of none null data", func() { + reducer := NewSimpleReducer("avg") + series := &tsdb.TimeSeries{ + Name: "test time serie", + } + + series.Points = append(series.Points, tsdb.NewTimePoint(null.FloatFrom(3), 1)) + series.Points = append(series.Points, tsdb.NewTimePoint(null.FloatFromPtr(nil), 2)) + series.Points = append(series.Points, tsdb.NewTimePoint(null.FloatFromPtr(nil), 3)) + series.Points = append(series.Points, tsdb.NewTimePoint(null.FloatFrom(3), 4)) + + So(reducer.Reduce(series).Float64, ShouldEqual, float64(3)) + }) + Convey("sum", func() { result := testReducer("sum", 1, 2, 3) So(result, ShouldEqual, float64(6)) From a90f650109fdafcc06a1763bbdd42a7194df050c Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 8 Dec 2016 14:04:08 +0100 Subject: [PATCH 3/4] update package.json version to 4.0.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 697c8a604fd..176c378e129 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "company": "Coding Instinct AB" }, "name": "grafana", - "version": "4.0.1", + "version": "4.0.2", "repository": { "type": "git", "url": "http://github.com/grafana/grafana.git" From 8feaef20e094e2f4149d3c38fdf3d9c77743c10f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 12 Dec 2016 14:36:49 +0100 Subject: [PATCH 4/4] fix(graph): fixed graph issue with axes mode set to series and picking Max value, fixes #6926 --- public/app/features/dashboard/submenu/submenu.ts | 1 - public/app/plugins/panel/graph/axes_editor.ts | 2 +- public/app/plugins/panel/graph/data_processor.ts | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/public/app/features/dashboard/submenu/submenu.ts b/public/app/features/dashboard/submenu/submenu.ts index 5e011b7588d..2ecb298236c 100644 --- a/public/app/features/dashboard/submenu/submenu.ts +++ b/public/app/features/dashboard/submenu/submenu.ts @@ -15,7 +15,6 @@ export class SubmenuCtrl { private $location) { this.annotations = this.dashboard.templating.list; this.variables = this.variableSrv.variables; - console.log(this.variables); } annotationStateChanged() { diff --git a/public/app/plugins/panel/graph/axes_editor.ts b/public/app/plugins/panel/graph/axes_editor.ts index 38083a80a56..b73ddf3868e 100644 --- a/public/app/plugins/panel/graph/axes_editor.ts +++ b/public/app/plugins/panel/graph/axes_editor.ts @@ -36,7 +36,7 @@ export class AxesEditorCtrl { this.xAxisStatOptions = [ {text: 'Avg', value: 'avg'}, {text: 'Min', value: 'min'}, - {text: 'Max', value: 'min'}, + {text: 'Max', value: 'max'}, {text: 'Total', value: 'total'}, {text: 'Count', value: 'count'}, {text: 'Current', value: 'current'}, diff --git a/public/app/plugins/panel/graph/data_processor.ts b/public/app/plugins/panel/graph/data_processor.ts index 6233ac345c9..50d62aff03a 100644 --- a/public/app/plugins/panel/graph/data_processor.ts +++ b/public/app/plugins/panel/graph/data_processor.ts @@ -166,7 +166,7 @@ export class DataProcessor { return [ {text: 'Avg', value: 'avg'}, {text: 'Min', value: 'min'}, - {text: 'Max', value: 'min'}, + {text: 'Max', value: 'max'}, {text: 'Total', value: 'total'}, {text: 'Count', value: 'count'}, ];