Skip to content

Commit

Permalink
feat: set a maximum 20 entities per query in service/instance/endpoin…
Browse files Browse the repository at this point in the history
…t list widgets (#406)
  • Loading branch information
Fine0830 authored Jul 30, 2024
1 parent 4e00073 commit 6b2b6a5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
1 change: 1 addition & 0 deletions src/hooks/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export const MaximumEntities = 20;

export enum sizeEnum {
XS = "XS",
Expand Down
65 changes: 47 additions & 18 deletions src/hooks/useExpressionsProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { RespFields } from "./data";
import { RespFields, MaximumEntities } from "./data";
import { EntityType, ExpressionResultType } from "@/views/dashboard/data";
import { ElMessage } from "element-plus";
import { useDashboardStore } from "@/store/modules/dashboard";
Expand Down Expand Up @@ -156,15 +156,15 @@ 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[];
metricConfig: MetricConfigOpt[];
},
scope: string,
) {
function expressionsGraphqlPods() {
function expressionsGraphqlPods(pods: Array<(Instance | Endpoint | Service) & Indexable>) {
const metrics: string[] = [];
const subMetrics: string[] = [];
config.expressions = config.expressions || [];
Expand Down Expand Up @@ -196,18 +196,22 @@ export async function useExpressionsQueryPodsMetrics(
variables.push(`$entity${index}: Entity!`);
conditions[`entity${index}`] = entity;
const f = metrics.map((name: string, idx: number) => {
variables.push(`$expression${index}${idx}: String!`);
conditions[`expression${index}${idx}`] = name;
if (index === 0) {
variables.push(`$expression${idx}: String!`);
conditions[`expression${idx}`] = name;
}
let str = "";
if (config.subExpressions[idx]) {
variables.push(`$subExpression${index}${idx}: String!`);
conditions[`subExpression${index}${idx}`] = config.subExpressions[idx];
str = `subexpression${index}${idx}: execExpression(expression: $subExpression${index}${idx}, entity: $entity${index}, duration: $duration)${RespFields.execExpression}`;
if (index === 0) {
variables.push(`$subExpression${idx}: String!`);
conditions[`subExpression${idx}`] = config.subExpressions[idx];
}
str = `subexpression${index}${idx}: execExpression(expression: $subExpression${idx}, entity: $entity${index}, duration: $duration)${RespFields.execExpression}`;
}

return (
str +
`expression${index}${idx}: execExpression(expression: $expression${index}${idx}, entity: $entity${index}, duration: $duration)${RespFields.execExpression}`
`expression${index}${idx}: execExpression(expression: $expression${idx}, entity: $entity${index}, duration: $duration)${RespFields.execExpression}`
);
});
return f;
Expand All @@ -218,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 {};
Expand Down Expand Up @@ -300,17 +307,39 @@ export async function useExpressionsQueryPodsMetrics(
return { data, names, subNames, metricConfigArr, metricTypesArr, expressionsTips, subExpressionsTips };
}

const dashboardStore = useDashboardStore();
const params = await expressionsGraphqlPods();
const json = await dashboardStore.fetchMetricValue(params);
async function fetchPodsExpressionValues(pods: Array<(Instance | Endpoint | Service) & Indexable>) {
const dashboardStore = useDashboardStore();
const params = await expressionsGraphqlPods(pods);

if (json.errors) {
ElMessage.error(json.errors);
return {};
const json = await dashboardStore.fetchMetricValue(params);

if (json.errors) {
ElMessage.error(json.errors);
return {};
}
const expressionParams = expressionsPodsSource(json, pods);

return expressionParams;
}
const expressionParams = expressionsPodsSource(json);

return expressionParams;
const result = [];
for (let i = 0; i < allPods.length; i += MaximumEntities) {
result.push(allPods.slice(i, i + MaximumEntities));
}
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)[]) {
Expand Down

0 comments on commit 6b2b6a5

Please sign in to comment.