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