當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。