feat: split query

This commit is contained in:
Fine 2024-07-30 18:58:31 +08:00
parent b33fd94b7c
commit a5b1092968

View File

@ -156,7 +156,7 @@ export async function useExpressionsQueryProcessor(config: Indexable) {
}
export async function useExpressionsQueryPodsMetrics(
pods: Array<(Instance | Endpoint | Service) & Indexable>,
allPods: Array<(Instance | Endpoint | Service) & Indexable>,
config: {
expressions: string[];
subExpressions: string[];
@ -164,7 +164,7 @@ export async function useExpressionsQueryPodsMetrics(
},
scope: string,
) {
function expressionsGraphqlPods() {
function expressionsGraphqlPods(pods: Array<(Instance | Endpoint | Service) & Indexable>) {
const metrics: string[] = [];
const subMetrics: string[] = [];
config.expressions = config.expressions || [];
@ -222,7 +222,10 @@ export async function useExpressionsQueryPodsMetrics(
return { queryStr, conditions };
}
function expressionsPodsSource(resp: { errors: string; data: Indexable }): Indexable {
function expressionsPodsSource(
resp: { errors: string; data: Indexable },
pods: Array<(Instance | Endpoint | Service) & Indexable>,
): Indexable {
if (resp.errors) {
ElMessage.error(resp.errors);
return {};
@ -304,17 +307,39 @@ export async function useExpressionsQueryPodsMetrics(
return { data, names, subNames, metricConfigArr, metricTypesArr, expressionsTips, subExpressionsTips };
}
async function fetchPodsExpressionValues(pods: Array<(Instance | Endpoint | Service) & Indexable>) {
const dashboardStore = useDashboardStore();
const params = await expressionsGraphqlPods();
const params = await expressionsGraphqlPods(pods);
const json = await dashboardStore.fetchMetricValue(params);
if (json.errors) {
ElMessage.error(json.errors);
return {};
}
const expressionParams = expressionsPodsSource(json);
const expressionParams = expressionsPodsSource(json, pods);
return expressionParams;
}
const result = [];
for (let i = 0; i < allPods.length; i += 20) {
result.push(allPods.slice(i, i + 20));
}
const promiseArr = result.map((d: Array<(Instance | Endpoint | Service) & Indexable>) =>
fetchPodsExpressionValues(d),
);
const responseList = await Promise.all(promiseArr);
let resp: Indexable = { data: [], expressionsTips: [], subExpressionsTips: [] };
for (const item of responseList) {
resp = {
...item,
data: [...resp.data, ...item.data],
expressionsTips: [...resp.expressionsTips, ...item.expressionsTips],
subExpressionsTips: [...resp.subExpressionsTips, ...item.subExpressionsTips],
};
}
return resp;
}
export function useQueryTopologyExpressionsProcessor(metrics: string[], instances: (Call | Node)[]) {