Просмотр исходного кода

Merge branch 'v4.0.x' of github.com:grafana/grafana into v4.0.x

Torkel Ödegaard 9 лет назад
Родитель
Сommit
497a1fcefc

+ 1 - 1
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"

+ 6 - 4
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

+ 5 - 2
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 {

+ 14 - 0
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))

+ 0 - 1
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() {

+ 1 - 1
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'},

+ 1 - 1
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'},
         ];