This commit is contained in:
ismail simsek
2025-05-28 14:14:33 +02:00
parent c8aef4811f
commit ea35bc438c
2 changed files with 15 additions and 5 deletions
@@ -4,8 +4,6 @@ import { PrometheusDatasource } from './datasource';
import { LabelsApiClient, processSeries, SeriesApiClient } from './resource_clients';
import { PrometheusCacheLevel } from './types';
type MockDatasource = Pick<PrometheusDatasource, 'cacheLevel' | 'getAdjustedInterval' | 'getTimeRangeParams' | 'interpolateString'>;
const mockTimeRange: TimeRange = {
from: dateTime(1681300292392),
to: dateTime(1681300293392),
@@ -24,7 +24,11 @@ export interface ResourceApiClient {
queryLabelValues: (timeRange: TimeRange, labelKey: string, match?: string, limit?: string) => Promise<string[]>;
}
type RequestFn = (url: string, params?: Record<string, unknown>, options?: Partial<BackendSrvRequest>) => Promise<unknown>;
type RequestFn = (
url: string,
params?: Record<string, unknown>,
options?: Partial<BackendSrvRequest>
) => Promise<unknown>;
const MATCH_ALL_LABELS = '{__name__!=""}';
const METRIC_LABEL = '__name__';
@@ -35,12 +39,20 @@ abstract class BaseResourceClient {
protected readonly datasource: PrometheusDatasource
) {}
protected async requestLabels(url: string, params?: Record<string, unknown>, options?: Partial<BackendSrvRequest>): Promise<PrometheusLabelsResponse> {
protected async requestLabels(
url: string,
params?: Record<string, unknown>,
options?: Partial<BackendSrvRequest>
): Promise<PrometheusLabelsResponse> {
const response = await this.request(url, params, options);
return Array.isArray(response) ? response : [];
}
protected async requestSeries(url: string, params?: Record<string, unknown>, options?: Partial<BackendSrvRequest>): Promise<PrometheusSeriesResponse> {
protected async requestSeries(
url: string,
params?: Record<string, unknown>,
options?: Partial<BackendSrvRequest>
): Promise<PrometheusSeriesResponse> {
const response = await this.request(url, params, options);
return Array.isArray(response) ? response : [];
}