fix: update services topology

This commit is contained in:
Qiuxia Fan 2022-02-14 19:54:43 +08:00
parent c697428119
commit 413646261d
6 changed files with 97 additions and 24 deletions

View File

@ -19,9 +19,11 @@ import {
EndpointTopology, EndpointTopology,
ServiceTopology, ServiceTopology,
GlobalTopology, GlobalTopology,
ServicesTopology,
} from "../fragments/topology"; } from "../fragments/topology";
export const getGlobalTopology = `query queryData(${GlobalTopology.variable}) {${GlobalTopology.query}}`; export const getGlobalTopology = `query queryData(${GlobalTopology.variable}) {${GlobalTopology.query}}`;
export const getInstanceTopology = `query queryData(${InstanceTopology.variable}) {${InstanceTopology.query}}`; export const getInstanceTopology = `query queryData(${InstanceTopology.variable}) {${InstanceTopology.query}}`;
export const getServiceTopology = `query queryData(${ServiceTopology.variable}) {${ServiceTopology.query}}`; export const getServiceTopology = `query queryData(${ServiceTopology.variable}) {${ServiceTopology.query}}`;
export const getEndpointTopology = `query queryData(${EndpointTopology.variable}) {${EndpointTopology.query}}`; export const getEndpointTopology = `query queryData(${EndpointTopology.variable}) {${EndpointTopology.query}}`;
export const getServicesTopology = `query queryData(${ServicesTopology.variable}) {${ServicesTopology.query}}`;

View File

@ -16,6 +16,7 @@
*/ */
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { store } from "@/store"; import { store } from "@/store";
import { Service } from "@/types/selector";
import { Node, Call } from "@/types/topology"; import { Node, Call } from "@/types/topology";
import graphql from "@/graphql"; import graphql from "@/graphql";
import { useSelectorStore } from "@/store/modules/selectors"; import { useSelectorStore } from "@/store/modules/selectors";
@ -23,14 +24,17 @@ import { useAppStoreWithOut } from "@/store/modules/app";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
import query from "@/graphql/fetch"; import query from "@/graphql/fetch";
interface MetricVal {
[key: string]: { values: { id: string; value: unknown }[] };
}
interface TopologyState { interface TopologyState {
node: Node | null; node: Node | null;
call: Call | null; call: Call | null;
calls: Call[]; calls: Call[];
nodes: Node[]; nodes: Node[];
nodeMetrics: { id: string; value: unknown }[]; nodeMetrics: MetricVal;
linkServerMetrics: { id: string; value: unknown }[]; linkServerMetrics: MetricVal;
linkClientMetrics: { id: string; value: unknown }[]; linkClientMetrics: MetricVal;
} }
export const topologyStore = defineStore({ export const topologyStore = defineStore({
@ -40,9 +44,9 @@ export const topologyStore = defineStore({
nodes: [], nodes: [],
node: null, node: null,
call: null, call: null,
nodeMetrics: [], nodeMetrics: {},
linkServerMetrics: [], linkServerMetrics: {},
linkClientMetrics: [], linkClientMetrics: {},
}), }),
actions: { actions: {
setNode(node: Node) { setNode(node: Node) {
@ -55,6 +59,15 @@ export const topologyStore = defineStore({
this.nodes = data.nodes; this.nodes = data.nodes;
this.calls = data.calls; this.calls = data.calls;
}, },
setNodeMetrics(m: { id: string; value: unknown }[]) {
this.nodeMetrics = m;
},
setLinkServerMetrics(m: { id: string; value: unknown }[]) {
this.linkServerMetrics = m;
},
setLinkClientMetrics(m: { id: string; value: unknown }[]) {
this.linkClientMetrics = m;
},
async getServiceTopology() { async getServiceTopology() {
const serviceId = useSelectorStore().currentService.id; const serviceId = useSelectorStore().currentService.id;
const duration = useAppStoreWithOut().durationTime; const duration = useAppStoreWithOut().durationTime;
@ -69,6 +82,20 @@ export const topologyStore = defineStore({
} }
return res.data; return res.data;
}, },
async getServicesTopology() {
const serviceIds = useSelectorStore().services.map((d: Service) => d.id);
const duration = useAppStoreWithOut().durationTime;
const res: AxiosResponse = await graphql
.query("getServicesTopology")
.params({
serviceIds,
duration,
});
if (!res.data.errors) {
this.setTopology(res.data.data.topology);
}
return res.data;
},
async getGlobalTopology() { async getGlobalTopology() {
const duration = useAppStoreWithOut().durationTime; const duration = useAppStoreWithOut().durationTime;
const res: AxiosResponse = await graphql const res: AxiosResponse = await graphql
@ -120,7 +147,7 @@ export const topologyStore = defineStore({
if (res.data.errors) { if (res.data.errors) {
return res.data; return res.data;
} }
this.nodeMetrics = res.data.data; this.setNodeMetrics(res.data.data);
return res.data; return res.data;
}, },
async getCallServerMetrics(param: { async getCallServerMetrics(param: {
@ -132,7 +159,7 @@ export const topologyStore = defineStore({
if (res.data.errors) { if (res.data.errors) {
return res.data; return res.data;
} }
this.linkServerMetrics = res.data.data; this.setLinkServerMetrics(res.data.data);
return res.data; return res.data;
}, },
async getCallClientMetrics(param: { async getCallClientMetrics(param: {
@ -144,7 +171,7 @@ export const topologyStore = defineStore({
if (res.data.errors) { if (res.data.errors) {
return res.data; return res.data;
} }
this.linkClientMetrics = res.data.data; this.setLinkClientMetrics(res.data.data);
return res.data; return res.data;
}, },
}, },

View File

@ -93,6 +93,10 @@ export default defineComponent({
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
if (dashboardStore.entity === EntityType[1].value) {
queryMetrics();
}
async function queryMetrics() { async function queryMetrics() {
const params = await useQueryProcessor(props.data); const params = await useQueryProcessor(props.data);

View File

@ -179,14 +179,14 @@ async function getServices() {
if (!dashboardStore.layerId) { if (!dashboardStore.layerId) {
return; return;
} }
if (dashboardStore.entity === EntityType[1].value) {
return;
}
const json = await selectorStore.fetchServices(dashboardStore.layerId); const json = await selectorStore.fetchServices(dashboardStore.layerId);
if (json.errors) { if (json.errors) {
ElMessage.error(json.errors); ElMessage.error(json.errors);
return; return;
} }
if (dashboardStore.entity === EntityType[1].value) {
return;
}
selectorStore.setCurrentService( selectorStore.setCurrentService(
selectorStore.services.length ? selectorStore.services[0] : null selectorStore.services.length ? selectorStore.services[0] : null
); );

View File

@ -80,12 +80,7 @@ const legend = ref<any>(null);
const showSetting = ref<boolean>(false); const showSetting = ref<boolean>(false);
const settings = ref<any>({}); const settings = ref<any>({});
const operationsPos = reactive<{ x: number; y: number }>({ x: NaN, y: NaN }); const operationsPos = reactive<{ x: number; y: number }>({ x: NaN, y: NaN });
const items = [ const items = ref([{ id: "alarm", title: "Alarm", func: handleGoAlarm }]);
{ title: "Endpoint", func: handleGoEndpoint },
{ title: "Instance", func: handleGoInstance },
{ title: "Dashboard", func: handleGoDashboard },
{ title: "Alarm", func: handleGoAlarm },
];
onMounted(async () => { onMounted(async () => {
loading.value = true; loading.value = true;
@ -177,7 +172,11 @@ function handleLinkClick(event: any, d: Call) {
event.stopPropagation(); event.stopPropagation();
topologyStore.setNode(null); topologyStore.setNode(null);
topologyStore.setLink(d); topologyStore.setLink(d);
const path = `/dashboard/${dashboardStore.layerId}/${dashboardStore.entity}Relation/${d.source.id}/${d.target.id}/${settings.value.linkDashboard}`; const e =
dashboardStore.entity === EntityType[1].value
? EntityType[0].value
: dashboardStore.entity;
const path = `/dashboard/${dashboardStore.layerId}/${e}Relation/${d.source.id}/${d.target.id}/${settings.value.linkDashboard}`;
const routeUrl = router.resolve({ path }); const routeUrl = router.resolve({ path });
window.open(routeUrl.href, "_blank"); window.open(routeUrl.href, "_blank");
} }
@ -228,8 +227,10 @@ function update() {
{ {
handleLinkClick: handleLinkClick, handleLinkClick: handleLinkClick,
tipHtml: (data: Call) => { tipHtml: (data: Call) => {
const linkClientMetrics: string[] = settings.value.linkClientMetrics; const linkClientMetrics: string[] =
const linkServerMetrics: string[] = settings.value.linkServerMetrics; settings.value.linkClientMetrics || [];
const linkServerMetrics: string[] =
settings.value.linkServerMetrics || [];
const htmlServer = linkServerMetrics.map((m) => { const htmlServer = linkServerMetrics.map((m) => {
const metric = topologyStore.linkServerMetrics[m].values.filter( const metric = topologyStore.linkServerMetrics[m].values.filter(
(val: { id: string; value: unknown }) => val.id === data.id (val: { id: string; value: unknown }) => val.id === data.id
@ -315,7 +316,7 @@ async function getTopology() {
resp = await topologyStore.getServiceTopology(); resp = await topologyStore.getServiceTopology();
break; break;
case EntityType[1].value: case EntityType[1].value:
resp = await topologyStore.getGlobalTopology(); resp = await topologyStore.getServicesTopology();
break; break;
case EntityType[2].value: case EntityType[2].value:
resp = await topologyStore.getEndpointTopology(); resp = await topologyStore.getEndpointTopology();
@ -335,7 +336,29 @@ function resize() {
svg.value.attr("height", height.value).attr("width", width.value); svg.value.attr("height", height.value).attr("width", width.value);
} }
function updateSettings(config: any) { function updateSettings(config: any) {
items.value = [{ id: "alarm", title: "Alarm", func: handleGoAlarm }];
settings.value = config; settings.value = config;
if (config.nodeDashboard) {
items.value.push({
id: "dashboard",
title: "Dashboard",
func: handleGoDashboard,
});
}
if (config.instanceDashboard) {
items.value.push({
id: "instance",
title: "Instance",
func: handleGoInstance,
});
}
if (config.endpointDashboard) {
items.value.push({
id: "endpoint",
title: "Endpoint",
func: handleGoEndpoint,
});
}
} }
onBeforeUnmount(() => { onBeforeUnmount(() => {
window.removeEventListener("resize", resize); window.removeEventListener("resize", resize);

View File

@ -36,6 +36,7 @@ limitations under the License. -->
<div class="label">{{ t("linkClientMetrics") }}</div> <div class="label">{{ t("linkClientMetrics") }}</div>
<Selector <Selector
class="inputs" class="inputs"
v-show="dashboardStore.entity !== EntityType[2].value"
:multiple="true" :multiple="true"
:value="states.linkClientMetrics" :value="states.linkClientMetrics"
:options="states.linkMetricList" :options="states.linkMetricList"
@ -92,6 +93,7 @@ import { MetricCatalog } from "../../data";
import { Option } from "@/types/app"; import { Option } from "@/types/app";
import { useQueryTopologyMetrics } from "@/hooks/useProcessor"; import { useQueryTopologyMetrics } from "@/hooks/useProcessor";
import { Node, Call } from "@/types/topology"; import { Node, Call } from "@/types/topology";
import { EntityType } from "../../data";
/*global defineEmits */ /*global defineEmits */
const emit = defineEmits(["update"]); const emit = defineEmits(["update"]);
@ -131,9 +133,13 @@ async function getMetricList() {
(d: { catalog: string }) => (d: { catalog: string }) =>
dashboardStore.entity === (MetricCatalog as any)[d.catalog] dashboardStore.entity === (MetricCatalog as any)[d.catalog]
); );
const e =
dashboardStore.entity === EntityType[1].value
? EntityType[0].value
: dashboardStore.entity;
states.linkMetricList = (json.data.metrics || []).filter( states.linkMetricList = (json.data.metrics || []).filter(
(d: { catalog: string }) => (d: { catalog: string }) =>
dashboardStore.entity + "Relation" === (MetricCatalog as any)[d.catalog] e + "Relation" === (MetricCatalog as any)[d.catalog]
); );
} }
function updateSettings() { function updateSettings() {
@ -150,6 +156,10 @@ function updateSettings() {
async function changeLinkServerMetrics(options: Option[]) { async function changeLinkServerMetrics(options: Option[]) {
states.linkServerMetrics = options.map((d: Option) => d.value); states.linkServerMetrics = options.map((d: Option) => d.value);
updateSettings(); updateSettings();
if (!states.linkServerMetrics.length) {
topologyStore.setLinkServerMetrics({});
return;
}
const idsS = topologyStore.calls const idsS = topologyStore.calls
.filter((i: Call) => i.detectPoints.includes("SERVER")) .filter((i: Call) => i.detectPoints.includes("SERVER"))
.map((b: Call) => b.id); .map((b: Call) => b.id);
@ -163,6 +173,10 @@ async function changeLinkServerMetrics(options: Option[]) {
async function changeLinkClientMetrics(options: Option[]) { async function changeLinkClientMetrics(options: Option[]) {
states.linkClientMetrics = options.map((d: Option) => d.value); states.linkClientMetrics = options.map((d: Option) => d.value);
updateSettings(); updateSettings();
if (!states.linkClientMetrics.length) {
topologyStore.setLinkClientMetrics({});
return;
}
const idsC = topologyStore.calls const idsC = topologyStore.calls
.filter((i: Call) => i.detectPoints.includes("CLIENT")) .filter((i: Call) => i.detectPoints.includes("CLIENT"))
.map((b: Call) => b.id); .map((b: Call) => b.id);
@ -176,7 +190,10 @@ async function changeLinkClientMetrics(options: Option[]) {
async function changeNodeMetrics(options: Option[]) { async function changeNodeMetrics(options: Option[]) {
states.nodeMetrics = options.map((d: Option) => d.value); states.nodeMetrics = options.map((d: Option) => d.value);
updateSettings(); updateSettings();
if (!states.nodeMetrics.length) {
topologyStore.setNodeMetrics({});
return;
}
const ids = topologyStore.nodes.map((d: Node) => d.id); const ids = topologyStore.nodes.map((d: Node) => d.id);
const param = await useQueryTopologyMetrics(states.nodeMetrics, ids); const param = await useQueryTopologyMetrics(states.nodeMetrics, ids);
const res = await topologyStore.getNodeMetrics(param); const res = await topologyStore.getNodeMetrics(param);