import { type TimeRange } from '@grafana/data'; import { type BackendSrvRequest } from '@grafana/runtime'; import { type PrometheusDatasource } from './datasource'; type PrometheusSeriesResponse = Array<{ [key: string]: string; }>; type PrometheusLabelsResponse = string[]; export interface ResourceApiClient { metrics: string[]; histogramMetrics: string[]; labelKeys: string[]; cachedLabelValues: Record; start: (timeRange: TimeRange) => Promise; queryMetrics: (timeRange: TimeRange) => Promise<{ metrics: string[]; histogramMetrics: string[]; }>; queryLabelKeys: (timeRange: TimeRange, match?: string, limit?: number) => Promise; queryLabelValues: (timeRange: TimeRange, labelKey: string, match?: string, limit?: number) => Promise; querySeries: (timeRange: TimeRange, match: string, limit: number) => Promise; } type RequestFn = (url: string, params?: Record, options?: Partial) => Promise; export declare abstract class BaseResourceClient { protected readonly request: RequestFn; protected readonly datasource: PrometheusDatasource; private seriesLimit; constructor(request: RequestFn, datasource: PrometheusDatasource); /** * Returns the effective limit to use for API requests. * Uses the provided limit if specified, otherwise falls back to the datasource's configured series limit. * When zero is provided, it returns zero (which means no limit in Prometheus API). * * @param {number} [limit] - Optional limit parameter from the API call * @returns {number} The limit to use - either the provided limit or datasource's default series limit */ protected getEffectiveLimit(limit?: number): number; protected requestLabels(url: string, params?: Record, options?: Partial): Promise; protected requestSeries(url: string, params?: Record, options?: Partial): Promise; /** * Fetches all time series that match a specific label matcher using **series** endpoint. * * @param {TimeRange} timeRange - Time range to use for the query * @param {string} match - Label matcher to filter time series * @param {string} limit - Maximum number of series to return */ querySeries: (timeRange: TimeRange, match: string | undefined, limit: number) => Promise; } export declare class LabelsApiClient extends BaseResourceClient implements ResourceApiClient { private _cache; histogramMetrics: string[]; metrics: string[]; labelKeys: string[]; cachedLabelValues: Record; start: (timeRange: TimeRange) => Promise; /** * Fetches all available metrics from Prometheus using the labels values endpoint for __name__. * Also processes and identifies histogram metrics (those ending with '_bucket'). * Results are cached and stored in the client instance for future use. * * @param {TimeRange} timeRange - Time range to search for metrics * @param {number} [limit] - Optional maximum number of metrics to return, uses datasource default if not specified * @returns {Promise<{metrics: string[], histogramMetrics: string[]}>} Object containing all metrics and filtered histogram metrics */ queryMetrics: (timeRange: TimeRange, limit?: number) => Promise<{ metrics: string[]; histogramMetrics: string[]; }>; /** * Fetches all available label keys from Prometheus using labels endpoint. * Uses the labels endpoint with optional match parameter for filtering. * * @param {TimeRange} timeRange - Time range to use for the query * @param {string} match - Optional label matcher to filter results * @param {string} limit - Maximum number of results to return * @returns {Promise} Array of label keys sorted alphabetically */ queryLabelKeys: (timeRange: TimeRange, match?: string, limit?: number) => Promise; /** * Fetches all values for a specific label key from Prometheus using labels values endpoint. * * @param {TimeRange} timeRange - Time range to use for the query * @param {string} labelKey - The label key to fetch values for * @param {string} match - Optional label matcher to filter results * @param {string} limit - Maximum number of results to return * @returns {Promise} Array of label values */ queryLabelValues: (timeRange: TimeRange, labelKey: string, match?: string, limit?: number) => Promise; } export declare class SeriesApiClient extends BaseResourceClient implements ResourceApiClient { private _cache; histogramMetrics: string[]; metrics: string[]; labelKeys: string[]; cachedLabelValues: Record; start: (timeRange: TimeRange) => Promise; queryMetrics: (timeRange: TimeRange) => Promise<{ metrics: string[]; histogramMetrics: string[]; }>; queryLabelKeys: (timeRange: TimeRange, match?: string, limit?: number) => Promise; queryLabelValues: (timeRange: TimeRange, labelKey: string, match?: string, limit?: number) => Promise; } export declare function processSeries(series: Array<{ [key: string]: string; }>, findValuesForKey?: string, hasLabelsMatchAPISupport?: boolean, matchSelector?: string): { metrics: string[]; labelKeys: string[]; labelValues: string[]; }; export {};