feat: Support for custom prometheus requests
1. Support custom prometheus request function 2. Support convert request url in prometheus request Change-Id: I451282990346c187283dae1cf64e3cb4b9782cb6
This commit is contained in:
parent
1506dd9353
commit
7c8f9f7e26
@ -19,6 +19,7 @@ function getChartData(data, device, devices) {
|
||||
|
||||
const BaseCard = (props) => {
|
||||
const {
|
||||
fetchPrometheusFunc,
|
||||
createFetchParams,
|
||||
handleDataParams,
|
||||
fetchDataParams,
|
||||
@ -38,7 +39,10 @@ const BaseCard = (props) => {
|
||||
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const fetchData = createFetchPrometheusClient(createFetchParams);
|
||||
const fetchData = createFetchPrometheusClient(
|
||||
createFetchParams,
|
||||
fetchPrometheusFunc
|
||||
);
|
||||
|
||||
const dataHandler = createDataHandler(handleDataParams);
|
||||
|
||||
|
@ -23,8 +23,13 @@ import ChartCard from '../ChartCard';
|
||||
import BaseContentContext from './context';
|
||||
|
||||
const Charts = (props) => {
|
||||
const { baseTopCardProps, baseChartProps, topCardList, chartCardList } =
|
||||
props;
|
||||
const {
|
||||
baseTopCardProps,
|
||||
baseChartProps,
|
||||
topCardList,
|
||||
chartCardList,
|
||||
fetchPrometheusFunc,
|
||||
} = props;
|
||||
|
||||
const ctx = useContext(BaseContentContext);
|
||||
|
||||
@ -60,7 +65,11 @@ const Charts = (props) => {
|
||||
}
|
||||
return (
|
||||
<Col {...colProps}>
|
||||
<BaseCard {...rest} fetchDataParams={newFetchDataParams} />
|
||||
<BaseCard
|
||||
{...rest}
|
||||
fetchDataParams={newFetchDataParams}
|
||||
fetchPrometheusFunc={fetchPrometheusFunc}
|
||||
/>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
@ -97,7 +106,11 @@ const Charts = (props) => {
|
||||
}
|
||||
return (
|
||||
<Col {...colProps}>
|
||||
<ChartCard {...rest} fetchDataParams={newFetchDataParams} />
|
||||
<ChartCard
|
||||
{...rest}
|
||||
fetchDataParams={newFetchDataParams}
|
||||
fetchPrometheusFunc={fetchPrometheusFunc}
|
||||
/>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
|
@ -2,8 +2,8 @@ import { get, clone, isArray } from 'lodash';
|
||||
import DataSet from '@antv/data-set';
|
||||
import { baseReturnFunc, fetchPrometheus, getRequestUrl } from './utils';
|
||||
|
||||
export function createFetchPrometheusClient(createParams) {
|
||||
const { requestType, metricKey } = createParams;
|
||||
export function createFetchPrometheusClient(createParams, fetchPrometheusFunc) {
|
||||
const { requestType, metricKey, convertUrl } = createParams;
|
||||
|
||||
const queryParams = get(METRICDICT, metricKey);
|
||||
|
||||
@ -14,8 +14,16 @@ export function createFetchPrometheusClient(createParams) {
|
||||
(queryParams.finalFormatFunc || [])[idx] || baseReturnFunc;
|
||||
// get base params in order
|
||||
const baseParams = (queryParams.baseParams || [])[idx] || {};
|
||||
const finalUrl = getRequestUrl(u, params, finalFormatFunc, baseParams);
|
||||
return fetchPrometheus(finalUrl, requestType, currentRange, interval);
|
||||
const formattedUrl = getRequestUrl(
|
||||
u,
|
||||
params,
|
||||
finalFormatFunc,
|
||||
baseParams
|
||||
);
|
||||
const finalUrl = convertUrl ? convertUrl(formattedUrl) : formattedUrl;
|
||||
return fetchPrometheusFunc
|
||||
? fetchPrometheusFunc(finalUrl, requestType, currentRange, interval)
|
||||
: fetchPrometheus(finalUrl, requestType, currentRange, interval);
|
||||
});
|
||||
return Promise.all(promises);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user