Commit 782c4eae by Daniel Lee Committed by GitHub

Merge pull request #15127 from challengerdeep/fix-stackdriver-aggparams-reducer

Change primaryAggregation to crossSeriesReducer in Stackdriver
parents 0c4f59a7 9b6746d8
...@@ -233,12 +233,12 @@ func buildFilterString(metricType string, filterParts []interface{}) string { ...@@ -233,12 +233,12 @@ func buildFilterString(metricType string, filterParts []interface{}) string {
} }
func setAggParams(params *url.Values, query *tsdb.Query, durationSeconds int) { func setAggParams(params *url.Values, query *tsdb.Query, durationSeconds int) {
primaryAggregation := query.Model.Get("primaryAggregation").MustString() crossSeriesReducer := query.Model.Get("crossSeriesReducer").MustString()
perSeriesAligner := query.Model.Get("perSeriesAligner").MustString() perSeriesAligner := query.Model.Get("perSeriesAligner").MustString()
alignmentPeriod := query.Model.Get("alignmentPeriod").MustString() alignmentPeriod := query.Model.Get("alignmentPeriod").MustString()
if primaryAggregation == "" { if crossSeriesReducer == "" {
primaryAggregation = "REDUCE_NONE" crossSeriesReducer = "REDUCE_NONE"
} }
if perSeriesAligner == "" { if perSeriesAligner == "" {
...@@ -267,7 +267,7 @@ func setAggParams(params *url.Values, query *tsdb.Query, durationSeconds int) { ...@@ -267,7 +267,7 @@ func setAggParams(params *url.Values, query *tsdb.Query, durationSeconds int) {
alignmentPeriod = "+3600s" alignmentPeriod = "+3600s"
} }
params.Add("aggregation.crossSeriesReducer", primaryAggregation) params.Add("aggregation.crossSeriesReducer", crossSeriesReducer)
params.Add("aggregation.perSeriesAligner", perSeriesAligner) params.Add("aggregation.perSeriesAligner", perSeriesAligner)
params.Add("aggregation.alignmentPeriod", alignmentPeriod) params.Add("aggregation.alignmentPeriod", alignmentPeriod)
......
...@@ -173,7 +173,7 @@ func TestStackdriver(t *testing.T) { ...@@ -173,7 +173,7 @@ func TestStackdriver(t *testing.T) {
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{}{
"metricType": "a/metric/type", "metricType": "a/metric/type",
"primaryAggregation": "REDUCE_MEAN", "crossSeriesReducer": "REDUCE_SUM",
"view": "FULL", "view": "FULL",
}) })
...@@ -182,11 +182,11 @@ func TestStackdriver(t *testing.T) { ...@@ -182,11 +182,11 @@ func TestStackdriver(t *testing.T) {
So(len(queries), ShouldEqual, 1) So(len(queries), ShouldEqual, 1)
So(queries[0].RefID, ShouldEqual, "A") So(queries[0].RefID, ShouldEqual, "A")
So(queries[0].Target, ShouldEqual, "aggregation.alignmentPeriod=%2B60s&aggregation.crossSeriesReducer=REDUCE_MEAN&aggregation.perSeriesAligner=ALIGN_MEAN&filter=metric.type%3D%22a%2Fmetric%2Ftype%22&interval.endTime=2018-03-15T13%3A34%3A00Z&interval.startTime=2018-03-15T13%3A00%3A00Z&view=FULL") So(queries[0].Target, ShouldEqual, "aggregation.alignmentPeriod=%2B60s&aggregation.crossSeriesReducer=REDUCE_SUM&aggregation.perSeriesAligner=ALIGN_MEAN&filter=metric.type%3D%22a%2Fmetric%2Ftype%22&interval.endTime=2018-03-15T13%3A34%3A00Z&interval.startTime=2018-03-15T13%3A00%3A00Z&view=FULL")
So(len(queries[0].Params), ShouldEqual, 7) So(len(queries[0].Params), ShouldEqual, 7)
So(queries[0].Params["interval.startTime"][0], ShouldEqual, "2018-03-15T13:00:00Z") So(queries[0].Params["interval.startTime"][0], ShouldEqual, "2018-03-15T13:00:00Z")
So(queries[0].Params["interval.endTime"][0], ShouldEqual, "2018-03-15T13:34:00Z") So(queries[0].Params["interval.endTime"][0], ShouldEqual, "2018-03-15T13:34:00Z")
So(queries[0].Params["aggregation.crossSeriesReducer"][0], ShouldEqual, "REDUCE_MEAN") So(queries[0].Params["aggregation.crossSeriesReducer"][0], ShouldEqual, "REDUCE_SUM")
So(queries[0].Params["aggregation.perSeriesAligner"][0], ShouldEqual, "ALIGN_MEAN") So(queries[0].Params["aggregation.perSeriesAligner"][0], ShouldEqual, "ALIGN_MEAN")
So(queries[0].Params["aggregation.alignmentPeriod"][0], ShouldEqual, "+60s") So(queries[0].Params["aggregation.alignmentPeriod"][0], ShouldEqual, "+60s")
So(queries[0].Params["filter"][0], ShouldEqual, "metric.type=\"a/metric/type\"") So(queries[0].Params["filter"][0], ShouldEqual, "metric.type=\"a/metric/type\"")
...@@ -196,7 +196,7 @@ func TestStackdriver(t *testing.T) { ...@@ -196,7 +196,7 @@ func TestStackdriver(t *testing.T) {
Convey("and query has group bys", func() { Convey("and query has group bys", func() {
tsdbQuery.Queries[0].Model = simplejson.NewFromAny(map[string]interface{}{ tsdbQuery.Queries[0].Model = simplejson.NewFromAny(map[string]interface{}{
"metricType": "a/metric/type", "metricType": "a/metric/type",
"primaryAggregation": "REDUCE_NONE", "crossSeriesReducer": "REDUCE_NONE",
"groupBys": []interface{}{"metric.label.group1", "metric.label.group2"}, "groupBys": []interface{}{"metric.label.group1", "metric.label.group2"},
"view": "FULL", "view": "FULL",
}) })
......
...@@ -34,7 +34,7 @@ export default class StackdriverDatasource { ...@@ -34,7 +34,7 @@ export default class StackdriverDatasource {
intervalMs: options.intervalMs, intervalMs: options.intervalMs,
datasourceId: this.id, datasourceId: this.id,
metricType: this.templateSrv.replace(t.metricType, options.scopedVars || {}), metricType: this.templateSrv.replace(t.metricType, options.scopedVars || {}),
primaryAggregation: this.templateSrv.replace(t.crossSeriesReducer || 'REDUCE_MEAN', options.scopedVars || {}), crossSeriesReducer: this.templateSrv.replace(t.crossSeriesReducer || 'REDUCE_MEAN', options.scopedVars || {}),
perSeriesAligner: this.templateSrv.replace(t.perSeriesAligner, options.scopedVars || {}), perSeriesAligner: this.templateSrv.replace(t.perSeriesAligner, options.scopedVars || {}),
alignmentPeriod: this.templateSrv.replace(t.alignmentPeriod, options.scopedVars || {}), alignmentPeriod: this.templateSrv.replace(t.alignmentPeriod, options.scopedVars || {}),
groupBys: this.interpolateGroupBys(t.groupBys, options.scopedVars), groupBys: this.interpolateGroupBys(t.groupBys, options.scopedVars),
...@@ -138,7 +138,7 @@ export default class StackdriverDatasource { ...@@ -138,7 +138,7 @@ export default class StackdriverDatasource {
refId: 'annotationQuery', refId: 'annotationQuery',
datasourceId: this.id, datasourceId: this.id,
metricType: this.templateSrv.replace(annotation.target.metricType, options.scopedVars || {}), metricType: this.templateSrv.replace(annotation.target.metricType, options.scopedVars || {}),
primaryAggregation: 'REDUCE_NONE', crossSeriesReducer: 'REDUCE_NONE',
perSeriesAligner: 'ALIGN_NONE', perSeriesAligner: 'ALIGN_NONE',
title: this.templateSrv.replace(annotation.target.title, options.scopedVars || {}), title: this.templateSrv.replace(annotation.target.title, options.scopedVars || {}),
text: this.templateSrv.replace(annotation.target.text, options.scopedVars || {}), text: this.templateSrv.replace(annotation.target.text, options.scopedVars || {}),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment