本文整理汇总了TypeScript中app/core/services/backend_srv.BackendSrv.datasourceRequest方法的典型用法代码示例。如果您正苦于以下问题:TypeScript BackendSrv.datasourceRequest方法的具体用法?TypeScript BackendSrv.datasourceRequest怎么用?TypeScript BackendSrv.datasourceRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app/core/services/backend_srv.BackendSrv
的用法示例。
在下文中一共展示了BackendSrv.datasourceRequest方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getDefaultProject
async getDefaultProject() {
try {
if (this.authenticationType === 'gce' || !this.projectName) {
const { data } = await this.backendSrv.datasourceRequest({
url: '/api/tsdb/query',
method: 'POST',
data: {
queries: [
{
refId: 'ensureDefaultProjectQuery',
type: 'ensureDefaultProjectQuery',
datasourceId: this.id,
},
],
},
});
this.projectName = data.results.ensureDefaultProjectQuery.meta.defaultProject;
return this.projectName;
} else {
return this.projectName;
}
} catch (error) {
throw this.formatStackdriverError(error);
}
}
示例2: it
it('should return the http status code', async () => {
try {
await _backendSrv.datasourceRequest({
url: 'gateway-error',
});
} catch (err) {
expect(err.status).toBe(502);
}
});
示例3: _request
_request(apiUrl: string, data?, options?: any) {
const baseUrl = this.instanceSettings.url;
const params = data ? serializeParams(data) : '';
const url = `${baseUrl}${apiUrl}?${params}`;
const req = {
...options,
url,
};
return this.backendSrv.datasourceRequest(req);
}
示例4: awsRequest
awsRequest(url, data) {
const options = {
method: 'POST',
url: url,
data: data,
};
return this.backendSrv.datasourceRequest(options).then(result => {
return result.data;
});
}
示例5: doRequest
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;
});
}
示例6: annotationQuery
async annotationQuery(options) {
const annotation = options.annotation;
const queries = [
{
refId: 'annotationQuery',
datasourceId: this.id,
metricType: this.templateSrv.replace(annotation.target.metricType, options.scopedVars || {}),
crossSeriesReducer: '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],
tags: [],
text: v[3],
};
});
return results;
}
示例7: _request
_request(url, data?, options?: any) {
var options: any = {
url: this.url + url,
method: this.httpMethod,
...options,
};
if (options.method === 'GET') {
if (!_.isEmpty(data)) {
options.url =
options.url +
'?' +
_.map(data, (v, k) => {
return encodeURIComponent(k) + '=' + encodeURIComponent(v);
}).join('&');
}
} else {
options.headers = {
'Content-Type': 'application/x-www-form-urlencoded',
};
options.transformRequest = data => {
return $.param(data);
};
options.data = data;
}
if (this.basicAuth || this.withCredentials) {
options.withCredentials = true;
}
if (this.basicAuth) {
options.headers = {
Authorization: this.basicAuth,
};
}
return this.backendSrv.datasourceRequest(options);
}
示例8: getTimeSeries
async getTimeSeries(options) {
const queries = options.targets
.filter(target => {
return !target.hide && target.metricType;
})
.map(t => {
return {
refId: t.refId,
intervalMs: options.intervalMs,
datasourceId: this.id,
metricType: this.templateSrv.replace(t.metricType, options.scopedVars || {}),
crossSeriesReducer: this.templateSrv.replace(t.crossSeriesReducer || 'REDUCE_MEAN', options.scopedVars || {}),
perSeriesAligner: this.templateSrv.replace(t.perSeriesAligner, options.scopedVars || {}),
alignmentPeriod: this.templateSrv.replace(t.alignmentPeriod, options.scopedVars || {}),
groupBys: this.interpolateGroupBys(t.groupBys, options.scopedVars),
view: t.view || 'FULL',
filters: this.interpolateFilters(t.filters, options.scopedVars),
aliasBy: this.templateSrv.replace(t.aliasBy, options.scopedVars || {}),
type: 'timeSeriesQuery',
};
});
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: [] };
}
}