API Reference@grafana/runtime › DataSourceWithBackend

DataSourceWithBackend class

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

Signature

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

Import

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

Constructors

Constructor Modifiers Description
constructor(instanceSettings) Constructs a new instance of the DataSourceWithBackend class

Methods

Method Modifiers Description
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
filterQuery(query) Override to skip executing a query
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

constructor(instanceSettings: DataSourceInstanceSettings<TOptions>);

Parameters

Parameter Type Description
instanceSettings DataSourceInstanceSettings<TOptions>

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

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

Parameters

Parameter Type Description
query TQuery
scopedVars ScopedVars

Returns:

Record<string, any>

callHealthCheck method

Run the datasource healthcheck

Signature

callHealthCheck(): Promise<HealthCheckResult>;

Returns:

Promise<HealthCheckResult>

filterQuery method

Override to skip executing a query

Signature

/** @virtual */
filterQuery?(query: TQuery): boolean;

Parameters

Parameter Type Description
query TQuery

Returns:

boolean

false if the query should be skipped

getResource method

Make a GET request to the datasource resource path

Signature

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

Parameters

Parameter Type Description
path string
params any

Returns:

Promise<any>

postResource method

Send a POST request to the datasource resource path

Signature

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

Parameters

Parameter Type Description
path string
body any

Returns:

Promise<any>

query method

Ideally final – any other implementation may not work as expected

Signature

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

Parameters

Parameter Type Description
request DataQueryRequest<TQuery>

Returns:

Observable<DataQueryResponse>

testDatasource method

Checks the plugin health

Signature

testDatasource(): Promise<any>;

Returns:

Promise<any>