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.
DataSourceApi class
The main data source abstraction interface, represents an instance of a data source
Although this is a class, datasource implementations do not *yet* need to extend it. As such, we can not yet add functions with default implementations.
Signature
declare abstract class DataSourceApi<TQuery extends DataQuery = DataQuery, TOptions extends DataSourceJsonData = DataSourceJsonData, TQueryImportConfiguration extends Record<string, object> = {}>
Import
import { DataSourceApi } from '@grafana/data';
Constructors
Properties
Methods
constructor(instanceSettings)
Constructs a new instance of the DataSourceApi
class
Signature
constructor(instanceSettings: DataSourceInstanceSettings<TOptions>);
Parameters
annotations property
An annotation processor allows explicit control for how annotations are managed.
It is only necessary to configure an annotation processor if the default behavior is not desirable
Signature
annotations?: AnnotationSupport<TQuery>;
components property
Set after constructor call, as the data source instance is the most common thing to pass around we attach the components to this instance for easy access
Signature
components?: DataSourcePluginComponents<DataSourceApi<TQuery, TOptions>, TQuery, TOptions>;
id property
Set in constructor
Signature
readonly id: number;
init property
Initializes a datasource after instantiation
Signature
init?: () => void;
interval property
min interval range
Signature
interval?: string;
languageProvider property
Used in explore
Signature
languageProvider?: any;
meta property
static information about the datasource
Signature
meta: DataSourcePluginMeta;
name property
Set in constructor
Signature
readonly name: string;
type property
Set in constructor
Signature
readonly type: string;
uid property
Set in constructor
Signature
readonly uid: string;
annotationQuery method
Can be optionally implemented to allow datasource to be a source of annotations for dashboard. This function will only be called if an angular is configured and the is undefined
Signature
annotationQuery?(options: AnnotationQueryRequest<TQuery>): Promise<AnnotationEvent[]>;
Parameters
Returns:
Promise<AnnotationEvent[]>
filterQuery method
Override to skip executing a query
Signature
/** @virtual */
filterQuery?(query: TQuery): boolean;
Parameters
Returns:
boolean
false if the query should be skipped
getHighlighterExpression method
Signature
getHighlighterExpression?(query: TQuery): string[];
Parameters
Returns:
string[]
getImportQueryConfiguration method
Returns configuration for importing queries from other data sources
Signature
getImportQueryConfiguration?(): TQueryImportConfiguration;
Returns:
TQueryImportConfiguration
getQueryDisplayText method
Convert a query to a simple text string
Signature
getQueryDisplayText?(query: TQuery): string;
Parameters
Returns:
string
getQueryHints method
Get hints for query improvements
Signature
getQueryHints?(query: TQuery, results: any[], ...rest: any): QueryHint[];
Parameters
Returns:
QueryHint[]
getRef method
Get an identifier object for this datasource instance
Signature
getRef(): DataSourceRef;
Returns:
DataSourceRef
getTagKeys method
Get tag keys for adhoc filters
Signature
getTagKeys?(options?: any): Promise<MetricFindValue[]>;
Parameters
Returns:
Promise<MetricFindValue[]>
getTagValues method
Get tag values for adhoc filters
Signature
getTagValues?(options: any): Promise<MetricFindValue[]>;
Parameters
Returns:
Promise<MetricFindValue[]>
getVersion method
Signature
getVersion?(optionalOptions?: any): Promise<string>;
Parameters
Returns:
Promise<string>
importQueries method
Signature
importQueries?(queries: DataQuery[], originDataSource: DataSourceApi<DataQuery>): Promise<TQuery[]>;
Parameters
Returns:
Promise<TQuery[]>
interpolateVariablesInQueries method
Signature
interpolateVariablesInQueries?(queries: TQuery[], scopedVars: ScopedVars | {}): TQuery[];
Parameters
Returns:
TQuery[]
metricFindQuery method
Variable query action.
Signature
metricFindQuery?(query: any, options?: any): Promise<MetricFindValue[]>;
Parameters
Returns:
Promise<MetricFindValue[]>
modifyQuery method
Used in explore
Signature
modifyQuery?(query: TQuery, action: QueryFixAction): TQuery;
Parameters
Returns:
TQuery
query method
Query for data, and optionally stream results
Signature
abstract query(request: DataQueryRequest<TQuery>): Promise<DataQueryResponse> | Observable<DataQueryResponse>;
Parameters
Returns:
Promise<DataQueryResponse> | Observable<DataQueryResponse>
targetContainsTemplate method
Used by alerting to check if query contains template variables
Signature
targetContainsTemplate?(query: TQuery): boolean;
Parameters
Returns:
boolean
testDatasource method
Test & verify datasource settings & connection details (returning TestingStatus)
When verification fails - errors specific to the data source should be handled here and converted to a TestingStatus object. Unknown errors and HTTP errors can be re-thrown and will be handled here: public/app/features/datasources/state/actions.ts
Signature
abstract testDatasource(): Promise<any>;
Returns:
Promise<any>