@grafana/data#DataSourceInstanceSettings TypeScript Examples

The following examples show how to use @grafana/data#DataSourceInstanceSettings. 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: datasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/** @ngInject */
  constructor(instanceSettings: DataSourceInstanceSettings<InfluxOptions>, private templateSrv: TemplateSrv) {
    super(instanceSettings);
    this.type = 'influxdb';
    this.urls = _.map(instanceSettings.url.split(','), url => {
      return url.trim();
    });

    this.username = instanceSettings.username;
    this.password = instanceSettings.password;
    this.name = instanceSettings.name;
    this.database = instanceSettings.database;
    this.basicAuth = instanceSettings.basicAuth;
    this.withCredentials = instanceSettings.withCredentials;
    const settingsData = instanceSettings.jsonData || ({} as InfluxOptions);
    this.interval = settingsData.timeInterval;
    this.httpMode = settingsData.httpMode || 'GET';
    this.responseParser = new ResponseParser();
  }
Example #2
Source File: azure_monitor_datasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/** @ngInject */
  constructor(
    private instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>,
    private templateSrv: TemplateSrv
  ) {
    this.id = instanceSettings.id;
    this.subscriptionId = instanceSettings.jsonData.subscriptionId;
    this.cloudName = instanceSettings.jsonData.cloudName || 'azuremonitor';
    this.baseUrl = `/${this.cloudName}/subscriptions`;
    this.url = instanceSettings.url;

    this.supportedMetricNamespaces = new SupportedNamespaces(this.cloudName).get();
  }
Example #3
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/** @ngInject */
  constructor(
    private instanceSettings: DataSourceInstanceSettings<StackdriverOptions>,
    public templateSrv: TemplateSrv,
    private timeSrv: TimeSrv
  ) {
    super(instanceSettings);
    this.baseUrl = `/stackdriver/`;
    this.url = instanceSettings.url!;
    this.authenticationType = instanceSettings.jsonData.authenticationType || 'jwt';
    this.metricTypesCache = {};
  }
Example #4
Source File: azure_log_analytics_datasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/** @ngInject */
  constructor(
    private instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>,
    private templateSrv: TemplateSrv
  ) {
    this.id = instanceSettings.id;

    switch (this.instanceSettings.jsonData.cloudName) {
      case 'govazuremonitor': // Azure US Government
        break;
      case 'germanyazuremonitor': // Azure Germany
        break;
      case 'chinaazuremonitor': // Azue China
        this.baseUrl = '/chinaloganalyticsazure';
        break;
      default:
        // Azure Global
        this.baseUrl = '/loganalyticsazure';
    }

    this.url = instanceSettings.url;
    this.defaultOrFirstWorkspace = this.instanceSettings.jsonData.logAnalyticsDefaultWorkspace;

    this.setWorkspaceUrl();
  }
Example #5
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
constructor(instanceSettings: DataSourceInstanceSettings<PromOptions>) {
    super(instanceSettings);

    this.type = 'prometheus';
    this.editorSrc = 'app/features/prometheus/partials/query.editor.html';
    this.url = instanceSettings.url;
    this.basicAuth = instanceSettings.basicAuth;
    this.withCredentials = instanceSettings.withCredentials;
    this.interval = instanceSettings.jsonData.timeInterval || '15s';
    this.queryTimeout = instanceSettings.jsonData.queryTimeout;
    this.httpMethod = instanceSettings.jsonData.httpMethod || 'GET';
    this.directUrl = instanceSettings.jsonData.directUrl;
    this.resultTransformer = new ResultTransformer(templateSrv);
    this.ruleMappings = {};
    this.languageProvider = new PrometheusLanguageProvider(this);
    this.customQueryParameters = new URLSearchParams(instanceSettings.jsonData.customQueryParameters);
  }
Example #6
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/** @ngInject */
  constructor(
    instanceSettings: DataSourceInstanceSettings<CloudWatchJsonData>,
    private templateSrv: TemplateSrv,
    private timeSrv: TimeSrv
  ) {
    super(instanceSettings);
    this.type = 'cloudwatch';
    this.proxyUrl = instanceSettings.url;
    this.defaultRegion = instanceSettings.jsonData.defaultRegion;
    this.datasourceName = instanceSettings.name;
    this.standardStatistics = ['Average', 'Maximum', 'Minimum', 'Sum', 'SampleCount'];
    this.debouncedAlert = memoizedDebounce(displayAlert, AppNotificationTimeout.Error);
    this.debouncedCustomAlert = memoizedDebounce(displayCustomError, AppNotificationTimeout.Error);
  }
Example #7
Source File: datasource.test.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
getPrepareTargetsContext = (target: PromQuery, app?: CoreApp) => {
  const instanceSettings = ({
    url: 'proxied',
    directUrl: 'direct',
    user: 'test',
    password: 'mupp',
    jsonData: { httpMethod: 'POST' },
  } as unknown) as DataSourceInstanceSettings<PromOptions>;
  const start = 0;
  const end = 1;
  const panelId = '2';
  const options = ({ targets: [target], interval: '1s', panelId, app } as any) as DataQueryRequest<PromQuery>;

  const ds = new PrometheusDatasource(instanceSettings);
  const { queries, activeTargets } = ds.prepareTargets(options, start, end);

  return {
    queries,
    activeTargets,
    start,
    end,
    panelId,
  };
}
Example #8
Source File: app_insights_datasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/** @ngInject */
  constructor(instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>, private templateSrv: TemplateSrv) {
    this.id = instanceSettings.id;
    this.applicationId = instanceSettings.jsonData.appInsightsAppId;

    switch (instanceSettings.jsonData.cloudName) {
      // Azure US Government
      case 'govazuremonitor':
        break;
      // Azure Germany
      case 'germanyazuremonitor':
        break;
      // Azue China
      case 'chinaazuremonitor':
        this.baseUrl = `/chinaappinsights/${this.version}/apps/${this.applicationId}`;
        break;
      // Azure Global
      default:
        this.baseUrl = `/appinsights/${this.version}/apps/${this.applicationId}`;
    }

    this.url = instanceSettings.url;
  }
Example #9
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 6 votes vote down vote up
/** @ngInject */
  constructor(
    instanceSettings: DataSourceInstanceSettings<ElasticsearchOptions>,
    private templateSrv: TemplateSrv,
    private timeSrv: TimeSrv
  ) {
    super(instanceSettings);
    this.basicAuth = instanceSettings.basicAuth;
    this.withCredentials = instanceSettings.withCredentials;
    this.url = instanceSettings.url;
    this.name = instanceSettings.name;
    this.index = instanceSettings.database;
    const settingsData = instanceSettings.jsonData || ({} as ElasticsearchOptions);

    this.timeField = settingsData.timeField;
    this.esVersion = settingsData.esVersion;
    this.indexPattern = new IndexPattern(this.index, settingsData.interval);
    this.interval = settingsData.timeInterval;
    this.maxConcurrentShardRequests = settingsData.maxConcurrentShardRequests;
    this.queryBuilder = new ElasticQueryBuilder({
      timeField: this.timeField,
      esVersion: this.esVersion,
    });
    this.logMessageField = settingsData.logMessageField || '';
    this.logLevelField = settingsData.logLevelField || '';
    this.dataLinks = settingsData.dataLinks || [];

    if (this.logMessageField === '') {
      this.logMessageField = null;
    }

    if (this.logLevelField === '') {
      this.logLevelField = null;
    }
  }
Example #10
Source File: MixedDataSource.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
constructor(instanceSettings: DataSourceInstanceSettings) {
    super(instanceSettings);
  }
Example #11
Source File: InputDatasource.test.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
describe('InputDatasource', () => {
  const data = readCSV('a,b,c\n1,2,3\n4,5,6');
  const instanceSettings: DataSourceInstanceSettings<InputOptions> = {
    id: 1,
    type: 'x',
    name: 'xxx',
    meta: {} as PluginMeta,
    jsonData: {
      data,
    },
  };

  describe('when querying', () => {
    test('should return the saved data with a query', () => {
      const ds = new InputDatasource(instanceSettings);
      const options = getQueryOptions<InputQuery>({
        targets: [{ refId: 'Z' }],
      });

      return ds.query(options).then(rsp => {
        expect(rsp.data.length).toBe(1);

        const series: DataFrame = rsp.data[0];
        expect(series.refId).toBe('Z');
        expect(series.fields[0].values).toEqual(data[0].fields[0].values);
      });
    });
  });

  test('DataFrame descriptions', () => {
    expect(describeDataFrame([])).toEqual('');
    expect(describeDataFrame(null)).toEqual('');
    expect(
      describeDataFrame([
        new MutableDataFrame({
          name: 'x',
          fields: [{ name: 'a' }],
        }),
      ])
    ).toEqual('1 Fields, 0 Rows');
  });
});
Example #12
Source File: InputDatasource.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
constructor(instanceSettings: DataSourceInstanceSettings<InputOptions>) {
    super(instanceSettings);

    if (instanceSettings.jsonData.data) {
      this.data = instanceSettings.jsonData.data.map(v => toDataFrame(v));
    }
  }
Example #13
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
/** @ngInject */
  constructor(private instanceSettings: DataSourceInstanceSettings<LokiOptions>, private templateSrv: TemplateSrv) {
    super(instanceSettings);

    this.languageProvider = new LanguageProvider(this);
    const settingsData = instanceSettings.jsonData || {};
    this.maxLines = parseInt(settingsData.maxLines, 10) || DEFAULT_MAX_LINES;
  }
Example #14
Source File: MixedDataSource.test.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
datasourceSrv = new DatasourceSrvMock(defaultDS, {
  '-- Mixed --': new MixedDatasource({ name: 'mixed', id: 5 } as DataSourceInstanceSettings),
  A: new MockDataSourceApi('DSA', { data: ['AAAA'] }),
  B: new MockDataSourceApi('DSB', { data: ['BBBB'] }),
  C: new MockDataSourceApi('DSC', { data: ['CCCC'] }),
})
Example #15
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
/** @ngInject */
  constructor(instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>, private templateSrv: TemplateSrv) {
    super(instanceSettings);
    this.azureMonitorDatasource = new AzureMonitorDatasource(instanceSettings, this.templateSrv);
    this.appInsightsDatasource = new AppInsightsDatasource(instanceSettings, this.templateSrv);

    this.azureLogAnalyticsDatasource = new AzureLogAnalyticsDatasource(instanceSettings, this.templateSrv);
  }
Example #16
Source File: metric_find_query.test.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
instanceSettings = ({
  url: 'proxied',
  directUrl: 'direct',
  user: 'test',
  password: 'mupp',
  jsonData: { httpMethod: 'GET' },
} as unknown) as DataSourceInstanceSettings<PromOptions>
Example #17
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
constructor(instanceSettings: DataSourceInstanceSettings) {
    super(instanceSettings);
  }
Example #18
Source File: datasource_srv.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
constructor(name?: string, result?: DataQueryResponse, meta?: any) {
    super({ name: name ? name : 'MockDataSourceApi' } as DataSourceInstanceSettings);
    if (result) {
      this.result = result;
    }

    this.meta = meta || ({} as DataSourcePluginMeta);
  }
Example #19
Source File: DataSource.ts    From grafana-s3-plugin with Apache License 2.0 5 votes vote down vote up
constructor(instanceSettings: DataSourceInstanceSettings<DataSourceOptions>) {
    super(instanceSettings);
  }
Example #20
Source File: datasource.ts    From grafana-kdb-datasource-ws with Apache License 2.0 5 votes vote down vote up
constructor(
    instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>,
    private backendSrv,
    private $q,
    private templateSrv
  ) {
    super(instanceSettings);

    this.templateSrv = templateSrv;
    this.name = instanceSettings.name;
    this.id = instanceSettings.id;
    this.responseParser = new ResponseParser(this.$q);
    this.queryModel = new KDBQuery({});
    this.interval = (instanceSettings.jsonData || {}).timeInterval;
    if (!instanceSettings.jsonData.timeoutLength) {
      this.timeoutLength = defaultTimeout;
    } else {
      this.timeoutLength = Number(instanceSettings.jsonData.timeoutLength);
    }
    this.requestSentList = [];
    this.requestSentIDList = [];
    this.responseReceivedList = [];

    this.url = 'http://' + instanceSettings.jsonData.host;
    if (instanceSettings.jsonData.useAuthentication) {
      if (instanceSettings.jsonData.useTLS === true) {
        this.wsUrl =
          'wss://' +
          instanceSettings.jsonData.user +
          ':' +
          instanceSettings.jsonData.password +
          '@' +
          instanceSettings.jsonData.host;
      } else {
        this.wsUrl =
          'ws://' +
          instanceSettings.jsonData.user +
          ':' +
          instanceSettings.jsonData.password +
          '@' +
          instanceSettings.jsonData.host;
      }
    } else {
      this.wsUrl = 'ws://' + instanceSettings.jsonData.host;
    }
  }
Example #21
Source File: datasource.test.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
describe('grafana data source', () => {
  const getMock = jest.spyOn(backendSrv, 'get');

  beforeEach(() => {
    jest.clearAllMocks();
  });

  describe('when executing an annotations query', () => {
    let calledBackendSrvParams: any;
    let ds: GrafanaDatasource;
    beforeEach(() => {
      getMock.mockImplementation((url: string, options: any) => {
        calledBackendSrvParams = options;
        return Promise.resolve([]);
      });

      ds = new GrafanaDatasource({} as DataSourceInstanceSettings);
    });

    describe('with tags that have template variables', () => {
      const options = setupAnnotationQueryOptions({ tags: ['tag1:$var'] });

      beforeEach(() => {
        return ds.annotationQuery(options);
      });

      it('should interpolate template variables in tags in query options', () => {
        expect(calledBackendSrvParams.tags[0]).toBe('tag1:replaced');
      });
    });

    describe('with tags that have multi value template variables', () => {
      const options = setupAnnotationQueryOptions({ tags: ['$var2'] });

      beforeEach(() => {
        return ds.annotationQuery(options);
      });

      it('should interpolate template variables in tags in query options', () => {
        expect(calledBackendSrvParams.tags[0]).toBe('replaced');
        expect(calledBackendSrvParams.tags[1]).toBe('replaced2');
      });
    });

    describe('with type dashboard', () => {
      const options = setupAnnotationQueryOptions(
        {
          type: 'dashboard',
          tags: ['tag1'],
        },
        { id: 1 }
      );

      beforeEach(() => {
        return ds.annotationQuery(options);
      });

      it('should remove tags from query options', () => {
        expect(calledBackendSrvParams.tags).toBe(undefined);
      });
    });
  });
});
Example #22
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
/** @ngInject */
  constructor(instanceSettings: DataSourceInstanceSettings) {
    super(instanceSettings);
  }
Example #23
Source File: datasource.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
constructor(instanceSettings: DataSourceInstanceSettings) {
    super(instanceSettings);
  }
Example #24
Source File: QueryEditor.test.tsx    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
setup = () => {
  const instanceSettings = {
    jsonData: { defaultRegion: 'us-east-1' },
  } as DataSourceInstanceSettings;

  const templateSrv = new TemplateSrv();
  templateSrv.init([
    new CustomVariable(
      {
        name: 'var3',
        options: [
          { selected: true, value: 'var3-foo' },
          { selected: false, value: 'var3-bar' },
          { selected: true, value: 'var3-baz' },
        ],
        current: {
          value: ['var3-foo', 'var3-baz'],
        },
        multi: true,
      },
      {} as any
    ),
  ]);

  const datasource = new CloudWatchDatasource(instanceSettings, templateSrv as any, {} as any);
  datasource.metricFindQuery = async () => [{ value: 'test', label: 'test' }];

  const props: Props = {
    query: {
      refId: '',
      id: '',
      region: 'us-east-1',
      namespace: 'ec2',
      metricName: 'CPUUtilization',
      dimensions: { somekey: 'somevalue' },
      statistics: [],
      period: '',
      expression: '',
      alias: '',
      matchExact: true,
    },
    datasource,
    history: [],
    onChange: jest.fn(),
    onRunQuery: jest.fn(),
  };

  return props;
}
Example #25
Source File: ExpressionDatasource.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
expressionDatasource = new ExpressionDatasourceApi({
  id: -100,
  name: ExpressionDatasourceID,
} as DataSourceInstanceSettings)
Example #26
Source File: ExpressionDatasource.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
constructor(instanceSettings: DataSourceInstanceSettings) {
    super(instanceSettings);
  }
Example #27
Source File: DataSourceWithBackend.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
constructor(instanceSettings: DataSourceInstanceSettings<TOptions>) {
    super(instanceSettings);
  }
Example #28
Source File: config.ts    From grafana-chinese with Apache License 2.0 5 votes vote down vote up
datasources: { [str: string]: DataSourceInstanceSettings } = {};
Example #29
Source File: DruidDataSource.ts    From druid-grafana with Apache License 2.0 5 votes vote down vote up
constructor(instanceSettings: DataSourceInstanceSettings<DruidSettings>) {
    super(instanceSettings);
  }