Datasource: Add optional queries parameter to getTagKeysOptions (#81071)

add optional queries parameter to getTagKeysOptions
This commit is contained in:
Ashley Harrison
2024-01-26 13:59:28 +00:00
committed by GitHub
parent 5a2e9ea2ee
commit 1a6105be8d
4 changed files with 6 additions and 5 deletions

View File

@@ -287,7 +287,7 @@ abstract class DataSourceApi<
/**
* Get tag keys for adhoc filters
*/
getTagKeys?(options?: DataSourceGetTagKeysOptions): Promise<MetricFindValue[]>;
getTagKeys?(options?: DataSourceGetTagKeysOptions<TQuery>): Promise<MetricFindValue[]>;
/**
* Get tag values for adhoc filters
@@ -367,7 +367,7 @@ abstract class DataSourceApi<
/**
* Options argument to DataSourceAPI.getTagKeys
*/
export interface DataSourceGetTagKeysOptions {
export interface DataSourceGetTagKeysOptions<TQuery extends DataQuery = DataQuery> {
/**
* The other existing filters or base filters. New in v10.3
*/
@@ -376,6 +376,7 @@ export interface DataSourceGetTagKeysOptions {
* Context time range. New in v10.3
*/
timeRange?: TimeRange;
queries?: TQuery[];
}
/**

View File

@@ -339,7 +339,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
// By implementing getTagKeys and getTagValues we add ad-hoc filters functionality
// Used in public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx::fetchFilterKeys
getTagKeys(options?: DataSourceGetTagKeysOptions) {
getTagKeys(options?: DataSourceGetTagKeysOptions<InfluxQuery>) {
const query = buildMetadataQuery({
type: 'TAG_KEYS',
templateService: this.templateSrv,

View File

@@ -753,7 +753,7 @@ export class LokiDatasource
* Implemented as part of the DataSourceAPI. Retrieves tag keys that can be used for ad-hoc filtering.
* @returns A Promise that resolves to an array of label names represented as MetricFindValue objects.
*/
async getTagKeys(options?: DataSourceGetTagKeysOptions): Promise<MetricFindValue[]> {
async getTagKeys(options?: DataSourceGetTagKeysOptions<LokiQuery>): Promise<MetricFindValue[]> {
const result = await this.languageProvider.fetchLabels({ timeRange: options?.timeRange });
return result.map((value: string) => ({ text: value }));
}

View File

@@ -668,7 +668,7 @@ export class PrometheusDatasource
// this is used to get label keys, a.k.a label names
// it is used in metric_find_query.ts
// and in Tempo here grafana/public/app/plugins/datasource/tempo/QueryEditor/ServiceGraphSection.tsx
async getTagKeys(options: DataSourceGetTagKeysOptions): Promise<MetricFindValue[]> {
async getTagKeys(options: DataSourceGetTagKeysOptions<PromQuery>): Promise<MetricFindValue[]> {
if (!options || options.filters.length === 0) {
await this.languageProvider.fetchLabels(options.timeRange);
return this.languageProvider.getLabelKeys().map((k) => ({ value: k, text: k }));