mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: remove hardcoding of test project name
This commit is contained in:
@@ -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 {
|
||||
|
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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', () => {
|
||||
|
@@ -401,6 +401,7 @@ function createTarget(existingFilters?: string[]) {
|
||||
refId: 'A',
|
||||
aggregation: {
|
||||
crossSeriesReducer: '',
|
||||
secondaryCrossSeriesReducer: '',
|
||||
alignmentPeriod: '',
|
||||
perSeriesAligner: '',
|
||||
groupBys: [],
|
||||
|
@@ -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',
|
||||
|
Reference in New Issue
Block a user