@grafana/data#MetricFindValue TypeScript Examples

The following examples show how to use @grafana/data#MetricFindValue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InputDatasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
metricFindQuery(query: string, options?: any): Promise<MetricFindValue[]> {
    return new Promise((resolve, reject) => {
      const names = [];
      for (const series of this.data) {
        for (const field of series.fields) {
          // TODO, match query/options?
          names.push({
            text: field.name,
          });
        }
      }
      resolve(names);
    });
  }
Example #2
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
metricFindQuery(query: string, options: any) {
    return new Promise<MetricFindValue[]>((resolve, reject) => {
      setTimeout(() => {
        const interpolatedQuery = templateSrv.replace(
          query,
          getSearchFilterScopedVar({ query, wildcardChar: '*', options })
        );
        const children = queryMetricTree(interpolatedQuery);
        const items = children.map(item => ({ value: item.name, text: item.name }));
        resolve(items);
      }, 100);
    });
  }
Example #3
Source File: datasource.ts    From grafana-kdb-datasource-ws with Apache License 2.0 5 votes vote down vote up
//Called for query variables
  metricFindQuery(kdbRequest: KdbRequest): Promise<MetricFindValue[]> {
    kdbRequest = this.injectUserVars(kdbRequest);
    return new Promise((resolve, reject) => {
      return this.connectWS().then((connectStatus) => {
        if (connectStatus === true){
            resolve(
              this.executeAsyncQuery(kdbRequest).then((result) => {
                const values = [];
                var properties = [];
                if (Array.isArray(result)) {
                  if (typeof result[0] === 'string') {
                    for (let i = 0; i < result.length; i++) {
                      values.push({ text: result[i] });
                    }
                  } else if (typeof result[0] === 'object') {
                    if (Object.keys(result[0]).length > 1) {
                      //checking that multiple rows for multiple columns don't come back as the preview tab only shows single values (not objects)
                      const errorResponse =
                        'Can only select single values. Attempted to return an object of key-value pairs. Unsafe query';
                      throw new Error(errorResponse);
                    }
                    for (var key in result[0]) {
                      if (result[0].hasOwnProperty(key) && typeof result[0][key] !== 'function') {
                        properties.push(key);
                      }
                    }
                    for (let i = 0; i < result.length; i++) {
                      values.push({ text: result[i][properties[0]] });
                    }
                  }
                } else if (typeof result === 'string') {
                  const errorResponse = `Check Query. Syntax error with: [ ${result} ]`;
                  throw new Error(errorResponse);
                }
                return values;
              })
            );
          }else{
            resolve([]);
          }
      });
    });
  }
Example #4
Source File: DruidDataSource.ts    From druid-grafana with Apache License 2.0 5 votes vote down vote up
async metricFindQuery(query: DruidQuery, options?: any): Promise<MetricFindValue[]> {
    return this.postResource('query-variable', this.applyTemplateVariables(query)).then((response) => {
      return response;
    });
  }