The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/public/app/plugins/datasource/stackdriver/datasource.ts

56 lines
1.4 KiB

/** @ngInject */
export default class StackdriverDatasource {
url: string;
baseUrl: string;
constructor(instanceSettings, private backendSrv) {
this.baseUrl = `/stackdriver/`;
this.url = instanceSettings.url;
this.doRequest = this.doRequest;
}
testDatasource() {
const path = `v3/projects/raintank-production/metricDescriptors`;
return this.doRequest(`${this.baseUrl}${path}`)
.then(response => {
if (response.status === 200) {
return {
status: 'success',
message: 'Successfully queried the Stackdriver API.',
title: 'Success',
};
}
})
.catch(error => {
let message = 'Stackdriver: ';
message += error.statusText ? error.statusText + ': ' : '';
if (error.data && error.data.error && error.data.error.code) {
// 400, 401
message += error.data.error.code + '. ' + error.data.error.message;
} else {
message += 'Cannot connect to Stackdriver API';
}
return {
status: 'error',
message: message,
};
});
}
doRequest(url, maxRetries = 1) {
return this.backendSrv
.datasourceRequest({
url: this.url + url,
method: 'GET',
})
.catch(error => {
if (maxRetries > 0) {
return this.doRequest(url, maxRetries - 1);
}
throw error;
});
}
}