| 
									
										
										
										
											2018-09-27 20:03:52 +08:00
										 |  |  | import { stackdriverUnitMappings } from './constants'; | 
					
						
							| 
									
										
										
										
											2018-09-27 20:22:20 +08:00
										 |  |  | import appEvents from 'app/core/app_events'; | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  | import _ from 'lodash'; | 
					
						
							| 
									
										
										
										
											2018-10-26 20:03:05 +08:00
										 |  |  | import StackdriverMetricFindQuery from './StackdriverMetricFindQuery'; | 
					
						
							| 
									
										
										
										
											2018-09-27 20:22:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 20:14:34 +08:00
										 |  |  | export default class StackdriverDatasource { | 
					
						
							| 
									
										
										
										
											2018-09-10 04:55:12 +08:00
										 |  |  |   id: number; | 
					
						
							| 
									
										
										
										
											2018-09-05 20:14:34 +08:00
										 |  |  |   url: string; | 
					
						
							|  |  |  |   baseUrl: string; | 
					
						
							| 
									
										
										
										
											2018-09-18 22:02:38 +08:00
										 |  |  |   projectName: string; | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |   authenticationType: string; | 
					
						
							| 
									
										
										
										
											2018-10-10 17:04:06 +08:00
										 |  |  |   queryPromise: Promise<any>; | 
					
						
							| 
									
										
										
										
											2018-10-26 20:03:05 +08:00
										 |  |  |   metricTypes: any[]; | 
					
						
							| 
									
										
										
										
											2018-09-05 20:14:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 20:22:20 +08:00
										 |  |  |   /** @ngInject */ | 
					
						
							| 
									
										
										
										
											2018-09-24 21:26:49 +08:00
										 |  |  |   constructor(instanceSettings, private backendSrv, private templateSrv, private timeSrv) { | 
					
						
							| 
									
										
										
										
											2018-09-05 22:18:03 +08:00
										 |  |  |     this.baseUrl = `/stackdriver/`; | 
					
						
							| 
									
										
										
										
											2018-09-05 20:14:34 +08:00
										 |  |  |     this.url = instanceSettings.url; | 
					
						
							| 
									
										
										
										
											2018-09-06 00:04:51 +08:00
										 |  |  |     this.doRequest = this.doRequest; | 
					
						
							| 
									
										
										
										
											2018-09-10 04:55:12 +08:00
										 |  |  |     this.id = instanceSettings.id; | 
					
						
							| 
									
										
										
										
											2018-09-18 22:02:38 +08:00
										 |  |  |     this.projectName = instanceSettings.jsonData.defaultProject || ''; | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |     this.authenticationType = instanceSettings.jsonData.authenticationType || 'jwt'; | 
					
						
							| 
									
										
										
										
											2018-10-26 20:03:05 +08:00
										 |  |  |     this.metricTypes = []; | 
					
						
							| 
									
										
										
										
											2018-09-05 20:14:34 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 00:22:48 +08:00
										 |  |  |   async getTimeSeries(options) { | 
					
						
							| 
									
										
										
										
											2018-09-15 01:28:48 +08:00
										 |  |  |     const queries = options.targets | 
					
						
							|  |  |  |       .filter(target => { | 
					
						
							|  |  |  |         return !target.hide && target.metricType; | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .map(t => { | 
					
						
							|  |  |  |         if (!t.hasOwnProperty('aggregation')) { | 
					
						
							|  |  |  |           t.aggregation = { | 
					
						
							|  |  |  |             crossSeriesReducer: 'REDUCE_MEAN', | 
					
						
							|  |  |  |             groupBys: [], | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return { | 
					
						
							|  |  |  |           refId: t.refId, | 
					
						
							| 
									
										
										
										
											2018-09-27 16:42:28 +08:00
										 |  |  |           intervalMs: options.intervalMs, | 
					
						
							| 
									
										
										
										
											2018-09-15 01:28:48 +08:00
										 |  |  |           datasourceId: this.id, | 
					
						
							| 
									
										
										
										
											2018-09-20 17:44:17 +08:00
										 |  |  |           metricType: this.templateSrv.replace(t.metricType, options.scopedVars || {}), | 
					
						
							|  |  |  |           primaryAggregation: this.templateSrv.replace(t.aggregation.crossSeriesReducer, options.scopedVars || {}), | 
					
						
							|  |  |  |           perSeriesAligner: this.templateSrv.replace(t.aggregation.perSeriesAligner, options.scopedVars || {}), | 
					
						
							|  |  |  |           alignmentPeriod: this.templateSrv.replace(t.aggregation.alignmentPeriod, options.scopedVars || {}), | 
					
						
							|  |  |  |           groupBys: this.interpolateGroupBys(t.aggregation.groupBys, options.scopedVars), | 
					
						
							| 
									
										
										
										
											2018-09-15 01:28:48 +08:00
										 |  |  |           view: t.view || 'FULL', | 
					
						
							| 
									
										
										
										
											2018-09-20 17:44:17 +08:00
										 |  |  |           filters: (t.filters || []).map(f => { | 
					
						
							|  |  |  |             return this.templateSrv.replace(f, options.scopedVars || {}); | 
					
						
							|  |  |  |           }), | 
					
						
							|  |  |  |           aliasBy: this.templateSrv.replace(t.aliasBy, options.scopedVars || {}), | 
					
						
							| 
									
										
										
										
											2018-09-24 16:17:06 +08:00
										 |  |  |           type: 'timeSeriesQuery', | 
					
						
							| 
									
										
										
										
											2018-09-14 23:01:27 +08:00
										 |  |  |         }; | 
					
						
							| 
									
										
										
										
											2018-09-15 01:28:48 +08:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2018-09-11 21:52:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-11 21:42:44 +08:00
										 |  |  |     if (queries.length > 0) { | 
					
						
							|  |  |  |       const { data } = await this.backendSrv.datasourceRequest({ | 
					
						
							|  |  |  |         url: '/api/tsdb/query', | 
					
						
							|  |  |  |         method: 'POST', | 
					
						
							|  |  |  |         data: { | 
					
						
							|  |  |  |           from: options.range.from.valueOf().toString(), | 
					
						
							|  |  |  |           to: options.range.to.valueOf().toString(), | 
					
						
							|  |  |  |           queries, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |       return data; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return { results: [] }; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-09-14 00:22:48 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-09-11 01:09:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-24 21:26:49 +08:00
										 |  |  |   async getLabels(metricType, refId) { | 
					
						
							| 
									
										
										
										
											2018-10-26 20:56:55 +08:00
										 |  |  |     const response = await this.getTimeSeries({ | 
					
						
							| 
									
										
										
										
											2018-09-24 21:26:49 +08:00
										 |  |  |       targets: [ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           refId: refId, | 
					
						
							|  |  |  |           datasourceId: this.id, | 
					
						
							|  |  |  |           metricType: this.templateSrv.replace(metricType), | 
					
						
							|  |  |  |           aggregation: { | 
					
						
							|  |  |  |             crossSeriesReducer: 'REDUCE_NONE', | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |           view: 'HEADERS', | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       ], | 
					
						
							|  |  |  |       range: this.timeSrv.timeRange(), | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-10-26 20:56:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return response.results[refId]; | 
					
						
							| 
									
										
										
										
											2018-09-24 21:26:49 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-20 17:44:17 +08:00
										 |  |  |   interpolateGroupBys(groupBys: string[], scopedVars): string[] { | 
					
						
							|  |  |  |     let interpolatedGroupBys = []; | 
					
						
							|  |  |  |     (groupBys || []).forEach(gb => { | 
					
						
							|  |  |  |       const interpolated = this.templateSrv.replace(gb, scopedVars || {}, 'csv').split(','); | 
					
						
							|  |  |  |       if (Array.isArray(interpolated)) { | 
					
						
							|  |  |  |         interpolatedGroupBys = interpolatedGroupBys.concat(interpolated); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         interpolatedGroupBys.push(interpolated); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |     return interpolatedGroupBys; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 20:24:28 +08:00
										 |  |  |   resolvePanelUnitFromTargets(targets: any[]) { | 
					
						
							| 
									
										
										
										
											2018-10-18 22:42:08 +08:00
										 |  |  |     let unit; | 
					
						
							| 
									
										
										
										
											2018-09-27 20:03:52 +08:00
										 |  |  |     if (targets.length > 0 && targets.every(t => t.unit === targets[0].unit)) { | 
					
						
							|  |  |  |       if (stackdriverUnitMappings.hasOwnProperty(targets[0].unit)) { | 
					
						
							|  |  |  |         unit = stackdriverUnitMappings[targets[0].unit]; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return unit; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 00:22:48 +08:00
										 |  |  |   async query(options) { | 
					
						
							| 
									
										
										
										
											2018-10-24 17:18:49 +08:00
										 |  |  |     const result = []; | 
					
						
							|  |  |  |     const data = await this.getTimeSeries(options); | 
					
						
							|  |  |  |     if (data.results) { | 
					
						
							|  |  |  |       Object['values'](data.results).forEach(queryRes => { | 
					
						
							|  |  |  |         if (!queryRes.series) { | 
					
						
							|  |  |  |           return; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         const unit = this.resolvePanelUnitFromTargets(options.targets); | 
					
						
							|  |  |  |         queryRes.series.forEach(series => { | 
					
						
							|  |  |  |           let timeSerie: any = { | 
					
						
							|  |  |  |             target: series.name, | 
					
						
							|  |  |  |             datapoints: series.points, | 
					
						
							|  |  |  |             refId: queryRes.refId, | 
					
						
							|  |  |  |             meta: queryRes.meta, | 
					
						
							|  |  |  |           }; | 
					
						
							|  |  |  |           if (unit) { | 
					
						
							|  |  |  |             timeSerie = { ...timeSerie, unit }; | 
					
						
							| 
									
										
										
										
											2018-10-18 22:42:08 +08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2018-10-24 17:18:49 +08:00
										 |  |  |           result.push(timeSerie); | 
					
						
							| 
									
										
										
										
											2018-09-11 01:09:43 +08:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-10-24 17:18:49 +08:00
										 |  |  |       }); | 
					
						
							|  |  |  |       return { data: result }; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       return { data: [] }; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-09-07 23:18:15 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-27 20:22:20 +08:00
										 |  |  |   async annotationQuery(options) { | 
					
						
							|  |  |  |     const annotation = options.annotation; | 
					
						
							|  |  |  |     const queries = [ | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         refId: 'annotationQuery', | 
					
						
							|  |  |  |         datasourceId: this.id, | 
					
						
							|  |  |  |         metricType: this.templateSrv.replace(annotation.target.metricType, options.scopedVars || {}), | 
					
						
							|  |  |  |         primaryAggregation: 'REDUCE_NONE', | 
					
						
							|  |  |  |         perSeriesAligner: 'ALIGN_NONE', | 
					
						
							|  |  |  |         title: this.templateSrv.replace(annotation.target.title, options.scopedVars || {}), | 
					
						
							|  |  |  |         text: this.templateSrv.replace(annotation.target.text, options.scopedVars || {}), | 
					
						
							|  |  |  |         tags: this.templateSrv.replace(annotation.target.tags, options.scopedVars || {}), | 
					
						
							|  |  |  |         view: 'FULL', | 
					
						
							|  |  |  |         filters: (annotation.target.filters || []).map(f => { | 
					
						
							|  |  |  |           return this.templateSrv.replace(f, options.scopedVars || {}); | 
					
						
							|  |  |  |         }), | 
					
						
							|  |  |  |         type: 'annotationQuery', | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const { data } = await this.backendSrv.datasourceRequest({ | 
					
						
							|  |  |  |       url: '/api/tsdb/query', | 
					
						
							|  |  |  |       method: 'POST', | 
					
						
							|  |  |  |       data: { | 
					
						
							|  |  |  |         from: options.range.from.valueOf().toString(), | 
					
						
							|  |  |  |         to: options.range.to.valueOf().toString(), | 
					
						
							|  |  |  |         queries, | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const results = data.results['annotationQuery'].tables[0].rows.map(v => { | 
					
						
							|  |  |  |       return { | 
					
						
							|  |  |  |         annotation: annotation, | 
					
						
							|  |  |  |         time: Date.parse(v[0]), | 
					
						
							|  |  |  |         title: v[1], | 
					
						
							| 
									
										
										
										
											2018-09-29 01:17:34 +08:00
										 |  |  |         tags: [], | 
					
						
							| 
									
										
										
										
											2018-09-27 20:22:20 +08:00
										 |  |  |         text: v[3], | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return results; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 20:03:05 +08:00
										 |  |  |   async metricFindQuery(query) { | 
					
						
							|  |  |  |     const stackdriverMetricFindQuery = new StackdriverMetricFindQuery(this); | 
					
						
							| 
									
										
										
										
											2018-11-09 20:48:57 +08:00
										 |  |  |     return stackdriverMetricFindQuery.execute(query); | 
					
						
							| 
									
										
										
										
											2018-09-28 22:36:43 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:17:29 +08:00
										 |  |  |   async testDatasource() { | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |     let status, message; | 
					
						
							|  |  |  |     const defaultErrorMessage = 'Cannot connect to Stackdriver API'; | 
					
						
							| 
									
										
										
										
											2018-10-09 21:20:05 +08:00
										 |  |  |     try { | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |       const projectName = await this.getDefaultProject(); | 
					
						
							|  |  |  |       const path = `v3/projects/${projectName}/metricDescriptors`; | 
					
						
							|  |  |  |       const response = await this.doRequest(`${this.baseUrl}${path}`); | 
					
						
							|  |  |  |       if (response.status === 200) { | 
					
						
							|  |  |  |         status = 'success'; | 
					
						
							|  |  |  |         message = 'Successfully queried the Stackdriver API.'; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         status = 'error'; | 
					
						
							|  |  |  |         message = response.statusText ? response.statusText : defaultErrorMessage; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-10-09 21:20:05 +08:00
										 |  |  |     } catch (error) { | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |       status = 'error'; | 
					
						
							|  |  |  |       if (_.isString(error)) { | 
					
						
							|  |  |  |         message = error; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         message = 'Stackdriver: '; | 
					
						
							| 
									
										
										
										
											2018-10-11 20:44:51 +08:00
										 |  |  |         message += error.statusText ? error.statusText : defaultErrorMessage; | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |         if (error.data && error.data.error && error.data.error.code) { | 
					
						
							| 
									
										
										
										
											2018-10-11 20:44:51 +08:00
										 |  |  |           message += ': ' + error.data.error.code + '. ' + error.data.error.message; | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } finally { | 
					
						
							| 
									
										
										
										
											2018-10-09 21:20:05 +08:00
										 |  |  |       return { | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |         status, | 
					
						
							|  |  |  |         message, | 
					
						
							| 
									
										
										
										
											2018-10-09 21:20:05 +08:00
										 |  |  |       }; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-09-05 20:14:34 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-11 15:51:44 +08:00
										 |  |  |   formatStackdriverError(error) { | 
					
						
							|  |  |  |     let message = 'Stackdriver: '; | 
					
						
							|  |  |  |     message += error.statusText ? error.statusText + ': ' : ''; | 
					
						
							|  |  |  |     if (error.data && error.data.error) { | 
					
						
							|  |  |  |       try { | 
					
						
							|  |  |  |         const res = JSON.parse(error.data.error); | 
					
						
							|  |  |  |         message += res.error.code + '. ' + res.error.message; | 
					
						
							|  |  |  |       } catch (err) { | 
					
						
							|  |  |  |         message += error.data.error; | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       message += 'Cannot connect to Stackdriver API'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return message; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-24 16:17:06 +08:00
										 |  |  |   async getDefaultProject() { | 
					
						
							| 
									
										
										
										
											2018-09-27 20:22:20 +08:00
										 |  |  |     try { | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |       if (this.authenticationType === 'gce' || !this.projectName) { | 
					
						
							| 
									
										
										
										
											2018-10-10 17:55:45 +08:00
										 |  |  |         const { data } = await this.backendSrv.datasourceRequest({ | 
					
						
							|  |  |  |           url: '/api/tsdb/query', | 
					
						
							|  |  |  |           method: 'POST', | 
					
						
							|  |  |  |           data: { | 
					
						
							|  |  |  |             queries: [ | 
					
						
							|  |  |  |               { | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |                 refId: 'ensureDefaultProjectQuery', | 
					
						
							|  |  |  |                 type: 'ensureDefaultProjectQuery', | 
					
						
							| 
									
										
										
										
											2018-10-10 17:55:45 +08:00
										 |  |  |                 datasourceId: this.id, | 
					
						
							|  |  |  |               }, | 
					
						
							|  |  |  |             ], | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |         this.projectName = data.results.ensureDefaultProjectQuery.meta.defaultProject; | 
					
						
							| 
									
										
										
										
											2018-10-10 17:55:45 +08:00
										 |  |  |         return this.projectName; | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         return this.projectName; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-09-27 20:22:20 +08:00
										 |  |  |     } catch (error) { | 
					
						
							| 
									
										
										
										
											2018-10-11 19:46:51 +08:00
										 |  |  |       throw this.formatStackdriverError(error); | 
					
						
							| 
									
										
										
										
											2018-09-24 16:17:06 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-10 17:04:06 +08:00
										 |  |  |   async getMetricTypes(projectName: string) { | 
					
						
							| 
									
										
										
										
											2018-09-07 23:18:15 +08:00
										 |  |  |     try { | 
					
						
							| 
									
										
										
										
											2018-10-26 20:03:05 +08:00
										 |  |  |       if (this.metricTypes.length === 0) { | 
					
						
							|  |  |  |         const metricsApiPath = `v3/projects/${projectName}/metricDescriptors`; | 
					
						
							|  |  |  |         const { data } = await this.doRequest(`${this.baseUrl}${metricsApiPath}`); | 
					
						
							| 
									
										
										
										
											2018-10-08 21:34:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 20:03:05 +08:00
										 |  |  |         this.metricTypes = data.metricDescriptors.map(m => { | 
					
						
							|  |  |  |           const [service] = m.type.split('/'); | 
					
						
							|  |  |  |           const [serviceShortName] = service.split('.'); | 
					
						
							|  |  |  |           m.service = service; | 
					
						
							|  |  |  |           m.serviceShortName = serviceShortName; | 
					
						
							|  |  |  |           m.displayName = m.displayName || m.type; | 
					
						
							|  |  |  |           return m; | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2018-10-08 21:34:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 20:03:05 +08:00
										 |  |  |       return this.metricTypes; | 
					
						
							| 
									
										
										
										
											2018-09-07 23:18:15 +08:00
										 |  |  |     } catch (error) { | 
					
						
							| 
									
										
										
										
											2018-10-11 15:51:44 +08:00
										 |  |  |       appEvents.emit('ds-request-error', this.formatStackdriverError(error)); | 
					
						
							|  |  |  |       return []; | 
					
						
							| 
									
										
										
										
											2018-09-07 23:18:15 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 17:17:58 +08:00
										 |  |  |   async doRequest(url, maxRetries = 1) { | 
					
						
							| 
									
										
										
										
											2018-09-05 20:14:34 +08:00
										 |  |  |     return this.backendSrv | 
					
						
							|  |  |  |       .datasourceRequest({ | 
					
						
							|  |  |  |         url: this.url + url, | 
					
						
							|  |  |  |         method: 'GET', | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .catch(error => { | 
					
						
							|  |  |  |         if (maxRetries > 0) { | 
					
						
							|  |  |  |           return this.doRequest(url, maxRetries - 1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         throw error; | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2018-09-04 19:21:02 +08:00
										 |  |  | } |