|
@@ -13,13 +13,12 @@ export default class StackdriverDatasource {
|
|
|
|
|
|
|
|
async query(options) {
|
|
async query(options) {
|
|
|
const queries = options.targets.filter(target => !target.hide).map(t => ({
|
|
const queries = options.targets.filter(target => !target.hide).map(t => ({
|
|
|
- queryType: 'raw',
|
|
|
|
|
refId: t.refId,
|
|
refId: t.refId,
|
|
|
datasourceId: this.id,
|
|
datasourceId: this.id,
|
|
|
- metric: t.metricType,
|
|
|
|
|
|
|
+ metricType: `metric.type="${t.metricType}"`,
|
|
|
}));
|
|
}));
|
|
|
try {
|
|
try {
|
|
|
- const response = await this.backendSrv.datasourceRequest({
|
|
|
|
|
|
|
+ const { data } = await this.backendSrv.datasourceRequest({
|
|
|
url: '/api/tsdb/query',
|
|
url: '/api/tsdb/query',
|
|
|
method: 'POST',
|
|
method: 'POST',
|
|
|
data: {
|
|
data: {
|
|
@@ -28,7 +27,18 @@ export default class StackdriverDatasource {
|
|
|
queries,
|
|
queries,
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
- return response;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ const result = [];
|
|
|
|
|
+
|
|
|
|
|
+ if (data.results) {
|
|
|
|
|
+ Object['values'](data.results).forEach(queryRes => {
|
|
|
|
|
+ queryRes.series.forEach(series => {
|
|
|
|
|
+ result.push({ target: series.name, datapoints: series.points });
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return { data: result };
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
console.log(error);
|
|
|
}
|
|
}
|
|
@@ -77,7 +87,7 @@ export default class StackdriverDatasource {
|
|
|
try {
|
|
try {
|
|
|
const metricsApiPath = `v3/projects/${projectId}/metricDescriptors`;
|
|
const metricsApiPath = `v3/projects/${projectId}/metricDescriptors`;
|
|
|
const { data } = await this.doRequest(`${this.baseUrl}${metricsApiPath}`);
|
|
const { data } = await this.doRequest(`${this.baseUrl}${metricsApiPath}`);
|
|
|
- return data.metricDescriptors.map(m => ({ id: m.name, name: m.displayName }));
|
|
|
|
|
|
|
+ return data.metricDescriptors.map(m => ({ id: m.type, name: m.displayName }));
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
console.log(error);
|
|
|
}
|
|
}
|