Add optional queries parameter to DataSourceGetTagValuesOptions (#85436)

Add optional `queries` parameter to `getTagKeysOptions`
This commit is contained in:
Bogdan Matei
2024-04-02 13:22:37 +03:00
committed by GitHub
parent 06a22005e8
commit 582b252488
7 changed files with 9 additions and 8 deletions

View File

@@ -290,7 +290,7 @@ abstract class DataSourceApi<
/**
* Get tag values for adhoc filters
*/
getTagValues?(options: DataSourceGetTagValuesOptions): Promise<MetricFindValue[]>;
getTagValues?(options: DataSourceGetTagValuesOptions<TQuery>): Promise<MetricFindValue[]>;
/**
* Set after constructor call, as the data source instance is the most common thing to pass around
@@ -380,7 +380,7 @@ export interface DataSourceGetTagKeysOptions<TQuery extends DataQuery = DataQuer
/**
* Options argument to DataSourceAPI.getTagValues
*/
export interface DataSourceGetTagValuesOptions {
export interface DataSourceGetTagValuesOptions<TQuery extends DataQuery = DataQuery> {
key: string;
/**
* The other existing filters or base filters. New in v10.3
@@ -390,6 +390,7 @@ export interface DataSourceGetTagValuesOptions {
* Context time range. New in v10.3
*/
timeRange?: TimeRange;
queries?: TQuery[];
}
export interface MetadataInspectorProps<

View File

@@ -696,7 +696,7 @@ export class PrometheusDatasource
}
// By implementing getTagKeys and getTagValues we add ad-hoc filters functionality
async getTagValues(options: DataSourceGetTagValuesOptions) {
async getTagValues(options: DataSourceGetTagValuesOptions<PromQuery>) {
const labelFilters: QueryBuilderLabelFilter[] = options.filters.map((f) => ({
label: f.key,
value: f.value,

View File

@@ -855,7 +855,7 @@ export class ElasticDatasource
return lastValueFrom(this.getFields());
}
getTagValues(options: DataSourceGetTagValuesOptions) {
getTagValues(options: DataSourceGetTagValuesOptions<ElasticsearchQuery>) {
return lastValueFrom(this.getTerms({ field: options.key }, options.timeRange));
}

View File

@@ -404,7 +404,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
return this.metricFindQuery(query);
}
getTagValues(options: DataSourceGetTagValuesOptions) {
getTagValues(options: DataSourceGetTagValuesOptions<InfluxQuery>) {
const query = buildMetadataQuery({
type: 'TAG_VALUES',
templateService: this.templateSrv,

View File

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

View File

@@ -696,7 +696,7 @@ export class PrometheusDatasource
}
// By implementing getTagKeys and getTagValues we add ad-hoc filters functionality
async getTagValues(options: DataSourceGetTagValuesOptions) {
async getTagValues(options: DataSourceGetTagValuesOptions<PromQuery>) {
const labelFilters: QueryBuilderLabelFilter[] = options.filters.map((f) => ({
label: f.key,
value: f.value,

View File

@@ -216,7 +216,7 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
}
// Allows to retrieve the list of tag values for ad-hoc filters
getTagValues(options: DataSourceGetTagValuesOptions): Promise<Array<{ text: string }>> {
getTagValues(options: DataSourceGetTagValuesOptions<TempoQuery>): Promise<Array<{ text: string }>> {
return this.labelValuesQuery(options.key.replace(/^(resource|span)\./, ''));
}