当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript BackendSrv.datasourceRequest方法代码示例

本文整理汇总了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);
   }
 }
开发者ID:grafana,项目名称:grafana,代码行数:25,代码来源:datasource.ts

示例2: it

 it('should return the http status code', async () => {
   try {
     await _backendSrv.datasourceRequest({
       url: 'gateway-error',
     });
   } catch (err) {
     expect(err.status).toBe(502);
   }
 });
开发者ID:gzq0616,项目名称:grafana,代码行数:9,代码来源:backend_srv.test.ts

示例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);
 }
开发者ID:johntdyer,项目名称:grafana,代码行数:10,代码来源:datasource.ts

示例4: awsRequest

  awsRequest(url, data) {
    const options = {
      method: 'POST',
      url: url,
      data: data,
    };

    return this.backendSrv.datasourceRequest(options).then(result => {
      return result.data;
    });
  }
开发者ID:johntdyer,项目名称:grafana,代码行数:11,代码来源:datasource.ts

示例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;
      });
  }
开发者ID:grafana,项目名称:grafana,代码行数:14,代码来源:azure_log_analytics_datasource.ts

示例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;
  }
开发者ID:grafana,项目名称:grafana,代码行数:42,代码来源:datasource.ts

示例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);
  }
开发者ID:cboggs,项目名称:grafana,代码行数:37,代码来源:datasource.ts

示例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: [] };
    }
  }
开发者ID:grafana,项目名称:grafana,代码行数:37,代码来源:datasource.ts


注:本文中的app/core/services/backend_srv.BackendSrv.datasourceRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。