mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: use alignment period that is passed from frontend. if set to auto, use value provided from the panel. also added tests for alignment period
This commit is contained in:
@@ -6,10 +6,12 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -138,6 +140,7 @@ func setAggParams(params *url.Values, query *tsdb.Query) {
|
|||||||
primaryAggregation := query.Model.Get("primaryAggregation").MustString()
|
primaryAggregation := query.Model.Get("primaryAggregation").MustString()
|
||||||
secondaryAggregation := query.Model.Get("secondaryAggregation").MustString()
|
secondaryAggregation := query.Model.Get("secondaryAggregation").MustString()
|
||||||
perSeriesAligner := query.Model.Get("perSeriesAligner").MustString()
|
perSeriesAligner := query.Model.Get("perSeriesAligner").MustString()
|
||||||
|
alignmentPeriod := query.Model.Get("alignmentPeriod").MustString()
|
||||||
|
|
||||||
if primaryAggregation == "" {
|
if primaryAggregation == "" {
|
||||||
primaryAggregation = "REDUCE_NONE"
|
primaryAggregation = "REDUCE_NONE"
|
||||||
@@ -154,9 +157,15 @@ func setAggParams(params *url.Values, query *tsdb.Query) {
|
|||||||
if secondaryAggregation == "" {
|
if secondaryAggregation == "" {
|
||||||
secondaryAggregation = "REDUCE_NONE"
|
secondaryAggregation = "REDUCE_NONE"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if alignmentPeriod == "auto" {
|
||||||
|
alignmentPeriodValue := int(math.Max(float64(query.IntervalMs), 60.0))
|
||||||
|
alignmentPeriod = "+" + strconv.Itoa(alignmentPeriodValue) + "s"
|
||||||
|
}
|
||||||
|
|
||||||
params.Add("aggregation.crossSeriesReducer", primaryAggregation)
|
params.Add("aggregation.crossSeriesReducer", primaryAggregation)
|
||||||
params.Add("aggregation.perSeriesAligner", perSeriesAligner)
|
params.Add("aggregation.perSeriesAligner", perSeriesAligner)
|
||||||
params.Add("aggregation.alignmentPeriod", "+60s")
|
params.Add("aggregation.alignmentPeriod", alignmentPeriod)
|
||||||
// params.Add("aggregation.secondaryAggregation.crossSeriesReducer", secondaryAggregation)
|
// params.Add("aggregation.secondaryAggregation.crossSeriesReducer", secondaryAggregation)
|
||||||
|
|
||||||
groupBys := query.Model.Get("groupBys").MustArray()
|
groupBys := query.Model.Get("groupBys").MustArray()
|
||||||
|
|||||||
@@ -64,6 +64,33 @@ func TestStackdriver(t *testing.T) {
|
|||||||
So(queries[0].Params["filter"][0], ShouldEqual, `metric.type="a/metric/type" key="value" key2="value2"`)
|
So(queries[0].Params["filter"][0], ShouldEqual, `metric.type="a/metric/type" key="value" key2="value2"`)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Convey("and alignmentPeriod is set to auto", func() {
|
||||||
|
Convey("and IntervalMs is larger than 60", func() {
|
||||||
|
tsdbQuery.Queries[0].IntervalMs = 1000
|
||||||
|
tsdbQuery.Queries[0].Model = simplejson.NewFromAny(map[string]interface{}{
|
||||||
|
"target": "target",
|
||||||
|
"alignmentPeriod": "auto",
|
||||||
|
"filters": []interface{}{"key", "=", "value", "AND", "key2", "=", "value2"},
|
||||||
|
})
|
||||||
|
|
||||||
|
queries, err := executor.buildQueries(tsdbQuery)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(queries[0].Params["aggregation.alignmentPeriod"][0], ShouldEqual, `+1000s`)
|
||||||
|
})
|
||||||
|
Convey("and IntervalMs is less than 60", func() {
|
||||||
|
tsdbQuery.Queries[0].IntervalMs = 30
|
||||||
|
tsdbQuery.Queries[0].Model = simplejson.NewFromAny(map[string]interface{}{
|
||||||
|
"target": "target",
|
||||||
|
"alignmentPeriod": "auto",
|
||||||
|
"filters": []interface{}{"key", "=", "value", "AND", "key2", "=", "value2"},
|
||||||
|
})
|
||||||
|
|
||||||
|
queries, err := executor.buildQueries(tsdbQuery)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
So(queries[0].Params["aggregation.alignmentPeriod"][0], ShouldEqual, `+60s`)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
Convey("and query has aggregation mean set", func() {
|
Convey("and query has aggregation mean set", func() {
|
||||||
tsdbQuery.Queries[0].Model = simplejson.NewFromAny(map[string]interface{}{
|
tsdbQuery.Queries[0].Model = simplejson.NewFromAny(map[string]interface{}{
|
||||||
"target": "target",
|
"target": "target",
|
||||||
|
|||||||
Reference in New Issue
Block a user