diff --git a/src/hooks/useProcessor.ts b/src/hooks/useProcessor.ts index c3d74941..54732cc8 100644 --- a/src/hooks/useProcessor.ts +++ b/src/hooks/useProcessor.ts @@ -19,6 +19,7 @@ import { ElMessage } from "element-plus"; import { useDashboardStore } from "@/store/modules/dashboard"; import { useSelectorStore } from "@/store/modules/selectors"; import { useAppStoreWithOut } from "@/store/modules/app"; +import { Instance } from "@/types/selector"; export function useQueryProcessor(config: any) { if (!(config.metrics && config.metrics.length)) { @@ -191,3 +192,61 @@ function aggregation(json: { } return json.data; } + +export function useQueryPodsMetrics( + pods: Instance[], + config: { metrics: string[]; metricTypes: string[] } +) { + const appStore = useAppStoreWithOut(); + const selectorStore = useSelectorStore(); + const conditions: { [key: string]: unknown } = { + duration: appStore.durationTime, + }; + const variables: string[] = [`$duration: Duration!`]; + const { currentService } = selectorStore; + + const fragmentList = pods.map((d: Instance, index: number) => { + const param = { + scope: "ServiceInstance", + serviceName: currentService.label, + serviceInstanceName: d.label, + normal: currentService.normal, + }; + const f = config.metrics.map((name: string, idx: number) => { + const metricType = config.metricTypes[idx] || ""; + conditions[`condition${index}${idx}`] = { + name, + entity: param, + }; + variables.push(`$condition${index}${idx}: MetricsCondition!`); + return `${name}${index}${idx}: ${metricType}(condition: $condition${index}${idx}, duration: $duration)${RespFields[metricType]}`; + }); + return f; + }); + const fragment = fragmentList.flat(1).join(" "); + const queryStr = `query queryData(${variables}) {${fragment}}`; + + return { queryStr, conditions }; +} +export function usePodsSource( + instances: Instance[], + resp: { errors: string; data: { [key: string]: any } }, + config: { metrics: string[]; metricTypes: string[] } +): any { + if (resp.errors) { + ElMessage.error(resp.errors); + return {}; + } + const data = instances.map((d: Instance | any, idx: number) => { + config.metrics.map((name: string, index: number) => { + const key = name + idx + index; + + d[name] = resp.data[key].values.values.map( + (d: { value: number }) => d.value + ); + }); + + return d; + }); + return data; +} diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index 732bfa33..04cdd44f 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -25,6 +25,7 @@ import { NewControl } from "../data"; import { Duration } from "@/types/app"; import axios, { AxiosResponse } from "axios"; import { cancelToken } from "@/utils/cancelToken"; +import { Instance } from "@/types/selector"; interface DashboardState { showConfig: boolean; layout: LayoutConfig[]; @@ -179,7 +180,10 @@ export const dashboardStore = defineStore({ return res.data; }, - async fetchMetricValue(param: { queryStr: string; conditions: any }) { + async fetchMetricValue(param: { + queryStr: string; + conditions: { [key: string]: unknown }; + }) { const res: AxiosResponse = await axios.post( "/graphql", { query: param.queryStr, variables: { ...param.conditions } }, diff --git a/src/types/dashboard.ts b/src/types/dashboard.ts index 3ff90ada..2735b9e3 100644 --- a/src/types/dashboard.ts +++ b/src/types/dashboard.ts @@ -65,6 +65,8 @@ export interface LineConfig extends AreaConfig { smooth?: boolean; showSymbol?: boolean; step?: boolean; + showXAxis?: boolean; + showYAxis?: boolean; } export interface AreaConfig { diff --git a/src/types/selector.d.ts b/src/types/selector.d.ts index f3727ffd..2c5c1d7b 100644 --- a/src/types/selector.d.ts +++ b/src/types/selector.d.ts @@ -22,3 +22,12 @@ export type Service = { normal: boolean; group: string; }; + +export type Instance = { + value: string; + label: string; + layer: string; + language: string; + instanceUUID: string; + attributes: { name: string; value: string }[]; +}; diff --git a/src/views/dashboard/configuration/ConfigEdit.vue b/src/views/dashboard/configuration/ConfigEdit.vue index 037b437d..d684754f 100644 --- a/src/views/dashboard/configuration/ConfigEdit.vue +++ b/src/views/dashboard/configuration/ConfigEdit.vue @@ -61,7 +61,11 @@ limitations under the License. --> diff --git a/src/views/dashboard/configuration/MetricOptions.vue b/src/views/dashboard/configuration/MetricOptions.vue index 03d3d631..96154e78 100644 --- a/src/views/dashboard/configuration/MetricOptions.vue +++ b/src/views/dashboard/configuration/MetricOptions.vue @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. --> - + @@ -65,27 +75,38 @@ limitations under the License. --> diff --git a/src/views/dashboard/graphs/Line.vue b/src/views/dashboard/graphs/Line.vue index 1874a417..cfd5bf1f 100644 --- a/src/views/dashboard/graphs/Line.vue +++ b/src/views/dashboard/graphs/Line.vue @@ -20,6 +20,7 @@ import { computed } from "vue"; import type { PropType } from "vue"; import { Event } from "@/types/events"; import { LineConfig } from "@/types/dashboard"; +import { config } from "@vue/test-utils"; /*global defineProps */ const props = defineProps({ @@ -37,6 +38,8 @@ const props = defineProps({ smooth: false, showSymbol: false, opacity: 0.4, + showXAxis: true, + showYAxis: true, }), }, }); @@ -143,6 +146,8 @@ function getOption() { color, tooltip: { trigger: "axis", + zlevel: 1000, + z: 60, backgroundColor: "rgb(50,50,50)", textStyle: { fontSize: 13, @@ -171,6 +176,7 @@ function getOption() { }, xAxis: { type: "category", + show: props.config.showXAxis, axisTick: { lineStyle: { color: "#c1c5ca41" }, alignWithLabel: true, @@ -184,7 +190,11 @@ function getOption() { axisLine: { show: false }, axisTick: { show: false }, splitLine: { lineStyle: { color: "#c1c5ca41", type: "dashed" } }, - axisLabel: { color: "#9da5b2", fontSize: "11" }, + axisLabel: { + color: "#9da5b2", + fontSize: "11", + show: props.config.showYAxis, + }, }, series: temp, }; diff --git a/src/views/dashboard/graphs/MinLine.vue b/src/views/dashboard/graphs/MinLine.vue new file mode 100644 index 00000000..e69de29b