DataSourceWithBackend class

Extend this class to implement a data source plugin that is depending on the Grafana backend API.

Signature

  1. declare class DataSourceWithBackend<TQuery extends DataQuery = DataQuery, TOptions extends DataSourceJsonData = DataSourceJsonData> extends DataSourceApi<TQuery, TOptions>

Import

  1. import { DataSourceWithBackend } from '@grafana/runtime';

Constructors

ConstructorModifiersDescription
constructor(instanceSettings)Constructs a new instance of the DataSourceWithBackend class

Properties

PropertyModifiersTypeDescription
streamOptionsProviderStreamOptionsProvider<TQuery>Optionally override the streaming behavior

Methods

MethodModifiersDescription
applyTemplateVariables(query, scopedVars)Override to apply template variables. The result is usually also TQuery, but sometimes this can be used to modify the query structure before sending to the backend.NOTE: if you do modify the structure or use template variables, alerting queries may not work as expected
callHealthCheck()Run the datasource healthcheck
getResource(path, params)Make a GET request to the datasource resource path
interpolateVariablesInQueries(queries, scopedVars)Apply template variables for explore
postResource(path, body)Send a POST request to the datasource resource path
query(request)Ideally final – any other implementation may not work as expected
testDatasource()Checks the plugin health see public/app/features/datasources/state/actions.ts for what needs to be returned here

constructor(instanceSettings)

Constructs a new instance of the DataSourceWithBackend class

Signature

  1. constructor(instanceSettings: DataSourceInstanceSettings<TOptions>);

Parameters

ParameterTypeDescription
instanceSettingsDataSourceInstanceSettings<TOptions>

streamOptionsProvider property

Optionally override the streaming behavior

Signature

  1. streamOptionsProvider: StreamOptionsProvider<TQuery>;

applyTemplateVariables method

Override to apply template variables. The result is usually also TQuery, but sometimes this can be used to modify the query structure before sending to the backend.

NOTE: if you do modify the structure or use template variables, alerting queries may not work as expected

Signature

  1. /** @virtual */
  2. applyTemplateVariables(query: TQuery, scopedVars: ScopedVars): Record<string, any>;

Parameters

ParameterTypeDescription
queryTQuery
scopedVarsScopedVars

Returns:

Record<string, any>

callHealthCheck method

Run the datasource healthcheck

Signature

  1. callHealthCheck(): Promise<HealthCheckResult>;

Returns:

Promise<HealthCheckResult>

getResource method

Make a GET request to the datasource resource path

Signature

  1. getResource(path: string, params?: any): Promise<any>;

Parameters

ParameterTypeDescription
pathstring
paramsany

Returns:

Promise<any>

interpolateVariablesInQueries method

Apply template variables for explore

Signature

  1. interpolateVariablesInQueries(queries: TQuery[], scopedVars: ScopedVars | {}): TQuery[];

Parameters

ParameterTypeDescription
queriesTQuery[]
scopedVarsScopedVars | {}

Returns:

TQuery[]

postResource method

Send a POST request to the datasource resource path

Signature

  1. postResource(path: string, body?: any): Promise<any>;

Parameters

ParameterTypeDescription
pathstring
bodyany

Returns:

Promise<any>

query method

Ideally final – any other implementation may not work as expected

Signature

  1. query(request: DataQueryRequest<TQuery>): Observable<DataQueryResponse>;

Parameters

ParameterTypeDescription
requestDataQueryRequest<TQuery>

Returns:

Observable<DataQueryResponse>

testDatasource method

Checks the plugin health see public/app/features/datasources/state/actions.ts for what needs to be returned here

Signature

  1. testDatasource(): Promise<any>;

Returns:

Promise<any>