refactor: remove scope in metric query

This commit is contained in:
Fine 2023-06-02 12:21:00 +08:00
parent 1ceaef6802
commit 8f919b4583
4 changed files with 7 additions and 43 deletions

View File

@ -57,13 +57,11 @@ export function useQueryProcessor(config: Indexable) {
name,
parentService: ["All"].includes(dashboardStore.entity) ? null : selectorStore.currentService.value,
normal: selectorStore.currentService ? selectorStore.currentService.normal : true,
scope: config.catalog,
topN: Number(c.topN) || 10,
order: c.sortOrder || "DES",
};
} else {
const entity = {
scope: config.catalog,
serviceName: dashboardStore.entity === "All" ? undefined : selectorStore.currentService.value,
normal: dashboardStore.entity === "All" ? undefined : selectorStore.currentService.normal,
serviceInstanceName: ["ServiceInstance", "ServiceInstanceRelation", "ProcessRelation"].includes(
@ -99,7 +97,6 @@ export function useQueryProcessor(config: Indexable) {
order: c.sortOrder || "DES",
};
} else {
entity.scope = dashboardStore.entity;
if (metricType === MetricQueryTypes.ReadLabeledMetricsValues) {
const labels = (c.labelsIndex || "").split(",").map((item: string) => item.replace(/^\s*|\s*$/g, ""));
variables.push(`$labels${index}: [String!]!`);
@ -233,7 +230,6 @@ export function useQueryPodsMetrics(
const currentService = selectorStore.currentService || {};
const fragmentList = pods.map((d: (Instance | Endpoint | Service) & Indexable, index: number) => {
const param = {
scope,
serviceName: scope === "Service" ? d.label : currentService.label,
serviceInstanceName: scope === "ServiceInstance" ? d.label : undefined,
endpointName: scope === "Endpoint" ? d.label : undefined,
@ -440,26 +436,3 @@ export function aggregation(val: number, config: { calculation?: string }): numb
return data;
}
export async function useGetMetricEntity(metric: string, metricType: string) {
if (!metric || !metricType) {
return;
}
let catalog = "";
const dashboardStore = useDashboardStore();
if (
([MetricQueryTypes.ReadSampledRecords, MetricQueryTypes.SortMetrics, MetricQueryTypes.ReadRecords] as any).includes(
metricType,
)
) {
const res = await dashboardStore.fetchMetricList(metric);
if (res.errors) {
ElMessage.error(res.errors);
return;
}
const c: string = res.data.metrics[0].catalog;
catalog = (MetricCatalog as Indexable)[c];
}
return catalog;
}

View File

@ -51,7 +51,7 @@ limitations under the License. -->
import { useRoute } from "vue-router";
import { useSelectorStore } from "@/store/modules/selectors";
import { useDashboardStore } from "@/store/modules/dashboard";
import { useQueryProcessor, useSourceProcessor, useGetMetricEntity } from "@/hooks/useMetricsProcessor";
import { useQueryProcessor, useSourceProcessor } from "@/hooks/useMetricsProcessor";
import graphs from "./graphs";
import { EntityType } from "./data";
import timeFormat from "@/utils/timeFormat";
@ -122,10 +122,7 @@ limitations under the License. -->
}
}
async function queryMetrics() {
const metricTypes = config.value.metricTypes || [];
const metrics = config.value.metrics || [];
const catalog = await useGetMetricEntity(metrics[0], metricTypes[0]);
const params = await useQueryProcessor({ ...config.value, catalog });
const params = await useQueryProcessor({ ...config.value });
if (!params) {
source.value = {};
return;

View File

@ -108,12 +108,10 @@ limitations under the License. -->
ChartTypes,
PodsChartTypes,
MetricsType,
ProtocolTypes,
ExpressionResultType,
} from "../../../data";
import { ElMessage } from "element-plus";
import Icon from "@/components/Icon.vue";
import { useQueryProcessor, useSourceProcessor, useGetMetricEntity } from "@/hooks/useMetricsProcessor";
import { useQueryProcessor, useSourceProcessor } from "@/hooks/useMetricsProcessor";
import { useExpressionsQueryProcessor, useExpressionsSourceProcessor } from "@/hooks/useExpressionsProcessor";
import { useI18n } from "vue-i18n";
import type { DashboardItem, MetricConfigOpt } from "@/types/dashboard";
@ -185,7 +183,7 @@ limitations under the License. -->
}
arr = json.data.metrics;
}
states.metricList = (arr || []).filter((d: { catalog: string; type: string }) => {
states.metricList = (arr || []).filter((d: { type: string }) => {
if (states.isList) {
if (d.type === MetricsType.REGULAR_VALUE || d.type === MetricsType.LABELED_VALUE) {
return d;
@ -335,8 +333,7 @@ limitations under the License. -->
if (!(metrics && metrics[0] && metricTypes && metricTypes[0])) {
return;
}
const catalog = await useGetMetricEntity(metrics[0], metricTypes[0]);
const params = useQueryProcessor({ ...states, metricConfig, catalog });
const params = useQueryProcessor({ ...states, metricConfig });
if (!params) {
emit("update", {});
return;

View File

@ -76,7 +76,7 @@ limitations under the License. -->
import { useSelectorStore } from "@/store/modules/selectors";
import graphs from "../graphs";
import { useI18n } from "vue-i18n";
import { useQueryProcessor, useSourceProcessor, useGetMetricEntity } from "@/hooks/useMetricsProcessor";
import { useQueryProcessor, useSourceProcessor } from "@/hooks/useMetricsProcessor";
import { EntityType, ListChartTypes } from "../data";
import type { EventParams } from "@/types/dashboard";
import getDashboard from "@/hooks/useDashboardsSession";
@ -113,10 +113,7 @@ limitations under the License. -->
}
async function queryMetrics() {
const metricTypes: string[] = props.data.metricTypes || [];
const metrics = props.data.metrics || [];
const catalog = await useGetMetricEntity(metrics[0], metricTypes[0]);
const params = await useQueryProcessor({ ...props.data, catalog });
const params = await useQueryProcessor({ ...props.data });
if (!params) {
state.source = {};