Menu

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Enterprise Open source

DataSourceWithBackend class

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

Signature

typescript
export declare class DataSourceWithBackend<TQuery extends DataQuery = DataQuery, TOptions extends DataSourceJsonData = DataSourceJsonData> extends DataSourceApi<TQuery, TOptions> 

Import

typescript
import { DataSourceWithBackend } from '@grafana/runtime';

Constructors

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

Methods

MethodModifiersDescription
applyTemplateVariables(query)Override to apply template variables
callHealthCheck()Run the datasource healthcheck
getResource(path, params)Make a GET request to the datasource resource path
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

constructor(instanceSettings)

Constructs a new instance of the DataSourceWithBackend class

Signature

typescript
constructor(instanceSettings: DataSourceInstanceSettings<TOptions>);

Parameters

ParameterTypeDescription
instanceSettingsDataSourceInstanceSettings<TOptions>

applyTemplateVariables method

Override to apply template variables

Signature

typescript
/** @virtual */
applyTemplateVariables(query: DataQuery): DataQuery;

Parameters

ParameterTypeDescription
queryDataQuery

Returns:

DataQuery

callHealthCheck method

Run the datasource healthcheck

Signature

typescript
callHealthCheck(): Promise<HealthCheckResult>;

Returns:

Promise<HealthCheckResult>

getResource method

Make a GET request to the datasource resource path

Signature

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

Parameters

ParameterTypeDescription
pathstring
paramsany

Returns:

Promise<any>

postResource method

Send a POST request to the datasource resource path

Signature

typescript
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

typescript
query(request: DataQueryRequest): Observable<DataQueryResponse>;

Parameters

ParameterTypeDescription
requestDataQueryRequest

Returns:

Observable<DataQueryResponse>

testDatasource method

Checks the plugin health

Signature

typescript
testDatasource(): Promise<any>;

Returns:

Promise<any>