From e05b86375b4d98f04718f86857d85d9340c07752 Mon Sep 17 00:00:00 2001 From: Daniel Lee Date: Tue, 18 Sep 2018 16:02:38 +0200 Subject: [PATCH] stackdriver: remove hardcoding of test project name --- pkg/tsdb/stackdriver/stackdriver.go | 13 ++----------- .../datasource/stackdriver/datasource.ts | 4 +++- .../datasource/stackdriver/query_ctrl.ts | 2 +- .../stackdriver/specs/datasource.test.ts | 17 +++++++++++------ .../stackdriver/specs/query_ctrl.test.ts | 1 + .../datasource/stackdriver/specs/testData.ts | 4 ++-- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/pkg/tsdb/stackdriver/stackdriver.go b/pkg/tsdb/stackdriver/stackdriver.go index de117d7018c..38999db8ad7 100644 --- a/pkg/tsdb/stackdriver/stackdriver.go +++ b/pkg/tsdb/stackdriver/stackdriver.go @@ -138,7 +138,6 @@ func (e *StackdriverExecutor) buildQueries(tsdbQuery *tsdb.TsdbQuery) ([]*Stackd func setAggParams(params *url.Values, query *tsdb.Query) { primaryAggregation := query.Model.Get("primaryAggregation").MustString() - secondaryAggregation := query.Model.Get("secondaryAggregation").MustString() perSeriesAligner := query.Model.Get("perSeriesAligner").MustString() alignmentPeriod := query.Model.Get("alignmentPeriod").MustString() @@ -146,18 +145,10 @@ func setAggParams(params *url.Values, query *tsdb.Query) { primaryAggregation = "REDUCE_NONE" } - if secondaryAggregation == "" { - secondaryAggregation = "REDUCE_NONE" - } - if perSeriesAligner == "" { perSeriesAligner = "ALIGN_MEAN" } - if secondaryAggregation == "" { - secondaryAggregation = "REDUCE_NONE" - } - if alignmentPeriod == "auto" || alignmentPeriod == "" { alignmentPeriodValue := int(math.Max(float64(query.IntervalMs), 60.0)) alignmentPeriod = "+" + strconv.Itoa(alignmentPeriodValue) + "s" @@ -172,7 +163,6 @@ func setAggParams(params *url.Values, query *tsdb.Query) { params.Add("aggregation.crossSeriesReducer", primaryAggregation) params.Add("aggregation.perSeriesAligner", perSeriesAligner) params.Add("aggregation.alignmentPeriod", alignmentPeriod) - // params.Add("aggregation.secondaryAggregation.crossSeriesReducer", secondaryAggregation) groupBys := query.Model.Get("groupBys").MustArray() if len(groupBys) > 0 { @@ -317,7 +307,8 @@ func (e *StackdriverExecutor) createRequest(ctx context.Context, dsInfo *models. if !ok { return nil, errors.New("Unable to find datasource plugin Stackdriver") } - proxyPass := fmt.Sprintf("stackdriver%s", "v3/projects/raintank-production/timeSeries") + projectName := dsInfo.JsonData.Get("defaultProject").MustString() + proxyPass := fmt.Sprintf("stackdriver%s", "v3/projects/"+projectName+"/timeSeries") var stackdriverRoute *plugins.AppPluginRoute for _, route := range plugin.Routes { diff --git a/public/app/plugins/datasource/stackdriver/datasource.ts b/public/app/plugins/datasource/stackdriver/datasource.ts index fb78f1fb559..4d4dada3b92 100644 --- a/public/app/plugins/datasource/stackdriver/datasource.ts +++ b/public/app/plugins/datasource/stackdriver/datasource.ts @@ -3,12 +3,14 @@ export default class StackdriverDatasource { id: number; url: string; baseUrl: string; + projectName: string; constructor(instanceSettings, private backendSrv) { this.baseUrl = `/stackdriver/`; this.url = instanceSettings.url; this.doRequest = this.doRequest; this.id = instanceSettings.id; + this.projectName = instanceSettings.jsonData.defaultProject || ''; } async getTimeSeries(options) { @@ -73,7 +75,7 @@ export default class StackdriverDatasource { } testDatasource() { - const path = `v3/projects/raintank-production/metricDescriptors`; + const path = `v3/projects/${this.projectName}/metricDescriptors`; return this.doRequest(`${this.baseUrl}${path}`) .then(response => { if (response.status === 200) { diff --git a/public/app/plugins/datasource/stackdriver/query_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_ctrl.ts index d82414382f8..2fdb145785e 100644 --- a/public/app/plugins/datasource/stackdriver/query_ctrl.ts +++ b/public/app/plugins/datasource/stackdriver/query_ctrl.ts @@ -134,7 +134,7 @@ export class StackdriverQueryCtrl extends QueryCtrl { } async getMetricTypes() { - //projects/raintank-production/metricDescriptors/agent.googleapis.com/agent/api_request_count + //projects/your-project-name/metricDescriptors/agent.googleapis.com/agent/api_request_count if (this.target.project.id !== 'default') { const metricTypes = await this.datasource.getMetricTypes(this.target.project.id); if (this.target.metricType === this.defaultDropdownValue && metricTypes.length > 0) { diff --git a/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts b/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts index 8ea111f6cff..7c5be8d89e3 100644 --- a/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts +++ b/public/app/plugins/datasource/stackdriver/specs/datasource.test.ts @@ -3,6 +3,11 @@ import { metricDescriptors } from './testData'; import moment from 'moment'; describe('StackdriverDataSource', () => { + const instanceSettings = { + jsonData: { + projectName: 'testproject', + }, + }; describe('when performing testDataSource', () => { describe('and call to stackdriver api succeeds', () => { let ds; @@ -13,7 +18,7 @@ describe('StackdriverDataSource', () => { return Promise.resolve({ status: 200 }); }, }; - ds = new StackdriverDataSource({}, backendSrv); + ds = new StackdriverDataSource(instanceSettings, backendSrv); result = await ds.testDatasource(); }); it('should return successfully', () => { @@ -28,7 +33,7 @@ describe('StackdriverDataSource', () => { const backendSrv = { datasourceRequest: async () => Promise.resolve({ status: 200, data: metricDescriptors }), }; - ds = new StackdriverDataSource({}, backendSrv); + ds = new StackdriverDataSource(instanceSettings, backendSrv); result = await ds.testDatasource(); }); it('should return status success', () => { @@ -47,7 +52,7 @@ describe('StackdriverDataSource', () => { data: { error: { code: 400, message: 'Field interval.endTime had an invalid value' } }, }), }; - ds = new StackdriverDataSource({}, backendSrv); + ds = new StackdriverDataSource(instanceSettings, backendSrv); result = await ds.testDatasource(); }); @@ -83,7 +88,7 @@ describe('StackdriverDataSource', () => { return Promise.resolve({ status: 200, data: response }); }, }; - ds = new StackdriverDataSource({}, backendSrv); + ds = new StackdriverDataSource(instanceSettings, backendSrv); result = await ds.getProjects(); }); @@ -132,7 +137,7 @@ describe('StackdriverDataSource', () => { const backendSrv = { datasourceRequest: async () => Promise.resolve({ status: 200, data: response }), }; - ds = new StackdriverDataSource({}, backendSrv); + ds = new StackdriverDataSource(instanceSettings, backendSrv); }); it('should return a list of datapoints', () => { @@ -166,7 +171,7 @@ describe('StackdriverDataSource', () => { }); }, }; - ds = new StackdriverDataSource({}, backendSrv); + ds = new StackdriverDataSource(instanceSettings, backendSrv); result = await ds.getMetricTypes(); }); it('should return successfully', () => { diff --git a/public/app/plugins/datasource/stackdriver/specs/query_ctrl.test.ts b/public/app/plugins/datasource/stackdriver/specs/query_ctrl.test.ts index 5c52fcfa8a6..cdd7a6ca617 100644 --- a/public/app/plugins/datasource/stackdriver/specs/query_ctrl.test.ts +++ b/public/app/plugins/datasource/stackdriver/specs/query_ctrl.test.ts @@ -401,6 +401,7 @@ function createTarget(existingFilters?: string[]) { refId: 'A', aggregation: { crossSeriesReducer: '', + secondaryCrossSeriesReducer: '', alignmentPeriod: '', perSeriesAligner: '', groupBys: [], diff --git a/public/app/plugins/datasource/stackdriver/specs/testData.ts b/public/app/plugins/datasource/stackdriver/specs/testData.ts index f69961bfdf2..b97aad7c6ce 100644 --- a/public/app/plugins/datasource/stackdriver/specs/testData.ts +++ b/public/app/plugins/datasource/stackdriver/specs/testData.ts @@ -1,6 +1,6 @@ export const metricDescriptors = [ { - name: 'projects/raintank-production/metricDescriptors/agent.googleapis.com/agent/api_request_count', + name: 'projects/grafana-prod/metricDescriptors/agent.googleapis.com/agent/api_request_count', labels: [ { key: 'state', @@ -20,7 +20,7 @@ export const metricDescriptors = [ }, }, { - name: 'projects/raintank-production/metricDescriptors/agent.googleapis.com/agent/log_entry_count', + name: 'projects/grafana-prod/metricDescriptors/agent.googleapis.com/agent/log_entry_count', labels: [ { key: 'response_code',