feat: view from service topology to serviceRelation dashboard

This commit is contained in:
Qiuxia Fan 2022-02-11 18:21:17 +08:00
parent ea895c3a50
commit d7c42fe2cb
9 changed files with 94 additions and 27 deletions

View File

@ -28,6 +28,7 @@ limitations under the License. -->
:key="item.value" :key="item.value"
:label="item.label" :label="item.label"
:value="item.value" :value="item.value"
:disabled="!!item.disabled"
> >
</el-option> </el-option>
</el-select> </el-select>
@ -47,14 +48,14 @@ interface Option {
const emit = defineEmits(["change"]); const emit = defineEmits(["change"]);
const props = defineProps({ const props = defineProps({
options: { options: {
type: Array as PropType<Option[]>, type: Array as PropType<(Option & { disabled: boolean })[]>,
default: () => [], default: () => [],
}, },
value: { value: {
type: [Array, String] as PropType<string[] | string>, type: [Array, String] as PropType<string[] | string>,
default: () => [], default: () => [],
}, },
size: { type: String, default: "small" }, size: { type: String, default: "default" },
placeholder: { type: String, default: "Select a option" }, placeholder: { type: String, default: "Select a option" },
borderRadius: { type: Number, default: 3 }, borderRadius: { type: Number, default: 3 },
multiple: { type: Boolean, default: false }, multiple: { type: Boolean, default: false },

View File

@ -28,6 +28,7 @@ export function useQueryProcessor(config: any) {
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
if (!selectorStore.currentService && dashboardStore.entity !== "All") { if (!selectorStore.currentService && dashboardStore.entity !== "All") {
return; return;
} }

View File

@ -122,3 +122,24 @@ export const ConfigData3: any = {
}, },
children: [], children: [],
}; };
export const ConfigData4: any = {
x: 0,
y: 0,
w: 8,
h: 12,
i: "0",
metrics: ["service_relation_server_resp_time"],
metricTypes: ["readMetricsValues"],
type: "Widget",
widget: {
title: "service_relation_server_resp_time",
tips: "Tooltip",
},
graph: {
type: "Line",
},
standard: {
unit: "min",
},
children: [],
};

View File

@ -18,7 +18,13 @@ import { defineStore } from "pinia";
import { store } from "@/store"; import { store } from "@/store";
import { LayoutConfig } from "@/types/dashboard"; import { LayoutConfig } from "@/types/dashboard";
import graphql from "@/graphql"; import graphql from "@/graphql";
import { ConfigData, ConfigData1, ConfigData2, ConfigData3 } from "../data"; import {
ConfigData,
ConfigData1,
ConfigData2,
ConfigData3,
ConfigData4,
} from "../data";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import { useSelectorStore } from "@/store/modules/selectors"; import { useSelectorStore } from "@/store/modules/selectors";
import { NewControl } from "../data"; import { NewControl } from "../data";
@ -161,6 +167,9 @@ export const dashboardStore = defineStore({
if (type == "Service") { if (type == "Service") {
this.layout = [ConfigData]; this.layout = [ConfigData];
} }
if (type == "ServiceRelation") {
this.layout = [ConfigData4];
}
}, },
setTopology(show: boolean) { setTopology(show: boolean) {
this.showTopology = show; this.showTopology = show;

View File

@ -44,12 +44,18 @@ export const selectorStore = defineStore({
durationTime: useAppStoreWithOut().durationTime, durationTime: useAppStoreWithOut().durationTime,
}), }),
actions: { actions: {
setCurrentService(service: Service) { setCurrentService(service: Nullable<Service>) {
this.currentService = service; this.currentService = service;
}, },
setCurrentDestService(service: Nullable<Service>) {
this.currentDestService = service;
},
setCurrentPod(pod: Nullable<Instance | Endpoint>) { setCurrentPod(pod: Nullable<Instance | Endpoint>) {
this.currentPod = pod; this.currentPod = pod;
}, },
setCurrentDestPod(pod: Nullable<Instance | Endpoint>) {
this.currentPod = pod;
},
async fetchLayers(): Promise<AxiosResponse> { async fetchLayers(): Promise<AxiosResponse> {
const res: AxiosResponse = await graphql.query("queryLayers").params({}); const res: AxiosResponse = await graphql.query("queryLayers").params({});
@ -113,7 +119,7 @@ export const selectorStore = defineStore({
serviceId, serviceId,
}); });
if (!res.data.errors) { if (!res.data.errors) {
this.currentService = res.data.data.service || {}; this.setCurrentService(res.data.data.service);
this.services = [res.data.data.service]; this.services = [res.data.data.service];
} }

View File

@ -18,7 +18,7 @@ limitations under the License. -->
<div class="item"> <div class="item">
<div class="label">{{ t("name") }}</div> <div class="label">{{ t("name") }}</div>
<el-input <el-input
size="small" size="default"
v-model="states.name" v-model="states.name"
placeholder="Please input name" placeholder="Please input name"
/> />
@ -28,7 +28,7 @@ limitations under the License. -->
<Selector <Selector
v-model="states.selectedLayer" v-model="states.selectedLayer"
:options="states.layers" :options="states.layers"
size="small" size="default"
placeholder="Select a layer" placeholder="Select a layer"
@change="changeLayer" @change="changeLayer"
class="selectors" class="selectors"
@ -39,14 +39,14 @@ limitations under the License. -->
<Selector <Selector
v-model="states.entity" v-model="states.entity"
:options="EntityType" :options="EntityType"
size="small" size="default"
placeholder="Select a entity" placeholder="Select a entity"
@change="changeEntity" @change="changeEntity"
class="selectors" class="selectors"
/> />
</div> </div>
<div class="btn"> <div class="btn">
<el-button class="create" size="small" type="primary" @click="onCreate"> <el-button class="create" size="default" type="primary" @click="onCreate">
{{ t("create") }} {{ t("create") }}
</el-button> </el-button>
</div> </div>

View File

@ -93,12 +93,9 @@ 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);
if (!params) { if (!params) {
state.source = {}; state.source = {};
return; return;
@ -137,9 +134,12 @@ export default defineComponent({
} }
); );
watch( watch(
() => selectorStore.currentService, () => [selectorStore.currentService, selectorStore.currentDestService],
() => { () => {
if (dashboardStore.entity === EntityType[0].value) { if (
dashboardStore.entity === EntityType[0].value ||
dashboardStore.entity === EntityType[4].value
) {
queryMetrics(); queryMetrics();
} }
} }

View File

@ -46,11 +46,11 @@ limitations under the License. -->
<div class="selectors-item" v-if="states.key === 2"> <div class="selectors-item" v-if="states.key === 2">
<span class="label">$DestinationService</span> <span class="label">$DestinationService</span>
<Selector <Selector
v-model="selectorStore.currentDestService" v-model="states.currentDestService"
:options="selectorStore.services" :options="selectorStore.services"
size="small" size="small"
placeholder="Select a service" placeholder="Select a service"
@change="changeService" @change="changeDestService"
class="selectors" class="selectors"
/> />
</div> </div>
@ -103,12 +103,14 @@ const states = reactive<{
key: number; key: number;
currentService: string; currentService: string;
currentPod: string; currentPod: string;
currentDestService: string;
}>({ }>({
destService: "", destService: "",
destPod: "", destPod: "",
key: (type && type.key) || 0, key: (type && type.key) || 0,
currentService: "", currentService: "",
currentPod: "", currentPod: "",
currentDestService: "",
}); });
dashboardStore.setLayer(String(params.layerId)); dashboardStore.setLayer(String(params.layerId));
@ -142,11 +144,19 @@ async function setSelector() {
ElMessage.error(json.errors); ElMessage.error(json.errors);
return; return;
} }
const currentService = selectorStore.services.filter( let currentService, currentDestService;
(d: { id: string }) => d.id === String(params.serviceId) for (const d of selectorStore.services) {
)[0]; if (d.id === String(params.serviceId)) {
currentService = d;
}
if (d.id === String(params.destServiceId)) {
currentDestService = d;
}
}
selectorStore.setCurrentService(currentService); selectorStore.setCurrentService(currentService);
selectorStore.setCurrentDestService(currentDestService);
states.currentService = selectorStore.currentService.value; states.currentService = selectorStore.currentService.value;
states.currentDestService = selectorStore.currentDestService.value;
} }
async function getServices() { async function getServices() {
@ -164,7 +174,11 @@ async function getServices() {
selectorStore.setCurrentService( selectorStore.setCurrentService(
selectorStore.services.length ? selectorStore.services[0] : null selectorStore.services.length ? selectorStore.services[0] : null
); );
selectorStore.setCurrentDestService(
selectorStore.services.length ? selectorStore.services[1] : null
);
states.currentService = selectorStore.currentService.value; states.currentService = selectorStore.currentService.value;
states.currentDestService = selectorStore.currentDestService.value;
fetchPods(dashboardStore.entity, true); fetchPods(dashboardStore.entity, true);
} }
@ -174,7 +188,16 @@ async function changeService(service: Service[]) {
selectorStore.setCurrentService(service[0]); selectorStore.setCurrentService(service[0]);
fetchPods(dashboardStore.entity, true); fetchPods(dashboardStore.entity, true);
} else { } else {
selectorStore.setCurrentService(""); selectorStore.setCurrentService(null);
}
}
function changeDestService(service: Service[]) {
if (service[0]) {
states.currentDestService = service[0].value;
selectorStore.setCurrentDestService(service[0]);
} else {
selectorStore.setCurrentDestService(null);
} }
} }
@ -265,7 +288,7 @@ watch(
.icon-btn { .icon-btn {
display: inline-block; display: inline-block;
padding: 0 5px; padding: 0 5px 2px 5px;
text-align: center; text-align: center;
border: 1px solid #ccc; border: 1px solid #ccc;
border-radius: 3px; border-radius: 3px;

View File

@ -28,7 +28,7 @@ limitations under the License. -->
class="inputs" class="inputs"
:multiple="true" :multiple="true"
:value="states.linkMetrics" :value="states.linkMetrics"
:options="states.metricList" :options="states.linkMetricList"
size="small" size="small"
placeholder="Select a metric" placeholder="Select a metric"
@change="changeLinkMetrics" @change="changeLinkMetrics"
@ -49,7 +49,7 @@ limitations under the License. -->
class="inputs" class="inputs"
:multiple="true" :multiple="true"
:value="states.nodeMetrics" :value="states.nodeMetrics"
:options="states.metricList" :options="states.nodeMetricList"
size="small" size="small"
placeholder="Select a metric" placeholder="Select a metric"
@change="changeNodeMetrics" @change="changeNodeMetrics"
@ -73,13 +73,15 @@ const states = reactive<{
nodeDashboard: string; nodeDashboard: string;
linkMetrics: string[]; linkMetrics: string[];
nodeMetrics: string[]; nodeMetrics: string[];
metricList: Option[]; nodeMetricList: Option[];
linkMetricList: Option[];
}>({ }>({
linkDashboard: "", linkDashboard: "",
nodeDashboard: "", nodeDashboard: "",
linkMetrics: [], linkMetrics: [],
nodeMetrics: [], nodeMetrics: [],
metricList: [], nodeMetricList: [],
linkMetricList: [],
}); });
getMetricList(); getMetricList();
@ -89,10 +91,14 @@ async function getMetricList() {
ElMessage.error(json.errors); ElMessage.error(json.errors);
return; return;
} }
states.metricList = (json.data.metrics || []).filter( states.nodeMetricList = (json.data.metrics || []).filter(
(d: { catalog: string }) => (d: { catalog: string }) =>
dashboardStore.entity === (MetricCatalog as any)[d.catalog] dashboardStore.entity === (MetricCatalog as any)[d.catalog]
); );
states.linkMetricList = (json.data.metrics || []).filter(
(d: { catalog: string }) =>
dashboardStore.entity + "Relation" === (MetricCatalog as any)[d.catalog]
);
} }
function updateSettings() { function updateSettings() {
emit("update", { emit("update", {