update config

This commit is contained in:
Qiuxia Fan 2022-03-22 10:32:38 +08:00
parent c24721b625
commit 457a105644
5 changed files with 35 additions and 40 deletions

View File

@ -34,7 +34,7 @@ interface TopologyState {
call: Nullable<Call>; call: Nullable<Call>;
calls: Call[]; calls: Call[];
nodes: Node[]; nodes: Node[];
nodeMetrics: MetricVal; nodeMetricValue: MetricVal;
linkServerMetrics: MetricVal; linkServerMetrics: MetricVal;
linkClientMetrics: MetricVal; linkClientMetrics: MetricVal;
} }
@ -46,7 +46,7 @@ export const topologyStore = defineStore({
nodes: [], nodes: [],
node: null, node: null,
call: null, call: null,
nodeMetrics: {}, nodeMetricValue: {},
linkServerMetrics: {}, linkServerMetrics: {},
linkClientMetrics: {}, linkClientMetrics: {},
}), }),
@ -105,8 +105,8 @@ export const topologyStore = defineStore({
this.calls = calls; this.calls = calls;
this.nodes = nodes; this.nodes = nodes;
}, },
setNodeMetrics(m: { id: string; value: unknown }[]) { setNodeMetricValue(m: { id: string; value: unknown }[]) {
this.nodeMetrics = m; this.nodeMetricValue = m;
}, },
setLinkServerMetrics(m: { id: string; value: unknown }[]) { setLinkServerMetrics(m: { id: string; value: unknown }[]) {
this.linkServerMetrics = m; this.linkServerMetrics = m;
@ -390,7 +390,7 @@ export const topologyStore = defineStore({
return { calls, nodes }; return { calls, nodes };
}, },
async getNodeMetrics(param: { async getNodeMetricValue(param: {
queryStr: string; queryStr: string;
conditions: { [key: string]: unknown }; conditions: { [key: string]: unknown };
}) { }) {
@ -399,7 +399,7 @@ export const topologyStore = defineStore({
if (res.data.errors) { if (res.data.errors) {
return res.data; return res.data;
} }
this.setNodeMetrics(res.data.data); this.setNodeMetricValue(res.data.data);
return res.data; return res.data;
}, },
async getLinkClientMetrics(linkClientMetrics: string[]) { async getLinkClientMetrics(linkClientMetrics: string[]) {
@ -427,7 +427,7 @@ export const topologyStore = defineStore({
async queryNodeMetrics(nodeMetrics: string[]) { async queryNodeMetrics(nodeMetrics: string[]) {
const ids = this.nodes.map((d: Node) => d.id); const ids = this.nodes.map((d: Node) => d.id);
const param = await useQueryTopologyMetrics(nodeMetrics, ids); const param = await useQueryTopologyMetrics(nodeMetrics, ids);
const res = await this.getNodeMetrics(param); const res = await this.getNodeMetricValue(param);
if (res.errors) { if (res.errors) {
ElMessage.error(res.errors); ElMessage.error(res.errors);

View File

@ -280,7 +280,7 @@ function update() {
const nodeMetrics: string[] = settings.value.nodeMetrics || []; const nodeMetrics: string[] = settings.value.nodeMetrics || [];
const html = nodeMetrics.map((m) => { const html = nodeMetrics.map((m) => {
const metric = const metric =
topologyStore.nodeMetrics[m].values.filter( topologyStore.nodeMetricValue[m].values.filter(
(val: { id: string; value: unknown }) => val.id === data.id (val: { id: string; value: unknown }) => val.id === data.id
)[0] || {}; )[0] || {};
const val = m.includes("_sla") ? metric.value / 100 : metric.value; const val = m.includes("_sla") ? metric.value / 100 : metric.value;

View File

@ -272,10 +272,10 @@ watch(
top: 60px; top: 60px;
right: 10px; right: 10px;
width: 400px; width: 400px;
height: 500px; height: 600px;
background-color: #2b3037; background-color: #2b3037;
overflow: auto; overflow: auto;
padding: 0 15px; padding: 10px 15px;
border-radius: 3px; border-radius: 3px;
color: #ccc; color: #ccc;
transition: all 0.5ms linear; transition: all 0.5ms linear;

View File

@ -105,10 +105,10 @@ function linkTooltip(data: Call) {
} }
function nodeTooltip(data: Node) { function nodeTooltip(data: Node) {
const nodeMetrics: string[] = Object.keys(topologyStore.nodeMetrics); const nodeMetrics: string[] = Object.keys(topologyStore.nodeMetricValue);
const html = nodeMetrics.map((m) => { const html = nodeMetrics.map((m) => {
const metric = const metric =
topologyStore.nodeMetrics[m].values.filter( topologyStore.nodeMetricValue[m].values.filter(
(val: { id: string; value: unknown }) => val.id === data.id (val: { id: string; value: unknown }) => val.id === data.id
)[0] || {}; )[0] || {};
const val = m.includes("_sla") ? metric.value / 100 : metric.value; const val = m.includes("_sla") ? metric.value / 100 : metric.value;

View File

@ -176,11 +176,6 @@ limitations under the License. -->
{{ t("setLegend") }} {{ t("setLegend") }}
</el-button> </el-button>
</div> </div>
<div>
<el-button @click="saveConfig" class="save-btn" size="small" type="primary">
{{ t("apply") }}
</el-button>
</div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { reactive } from "vue"; import { reactive } from "vue";
@ -275,26 +270,26 @@ async function getMetricList() {
entity + "Relation" === (MetricCatalog as any)[d.catalog] && entity + "Relation" === (MetricCatalog as any)[d.catalog] &&
d.type === MetricsType.REGULAR_VALUE d.type === MetricsType.REGULAR_VALUE
); );
if (isService) {
return;
}
states.nodeDashboards = list.reduce(
(
prev: (DashboardItem & { label: string; value: string })[],
d: DashboardItem
) => {
if (d.layer === dashboardStore.layerId && d.entity === entity) {
prev.push({ ...d, label: d.name, value: d.name });
}
return prev;
},
[]
);
} }
async function setLegend() { async function setLegend() {
const metrics = legend.metric.filter( updateSettings();
(d: any) => d.name && d.value && d.condition
);
const names = metrics.map((d: any) => d.name);
const p = {
linkDashboard: states.linkDashboard,
nodeDashboard: isService
? items.filter((d: { scope: string; dashboard: string }) => d.dashboard)
: states.nodeDashboard,
linkServerMetrics: states.linkServerMetrics,
linkClientMetrics: states.linkClientMetrics,
nodeMetrics: states.nodeMetrics,
legend: metrics,
};
emit("update", p);
dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, ...p });
const ids = topologyStore.nodes.map((d: Node) => d.id); const ids = topologyStore.nodes.map((d: Node) => d.id);
const names = dashboardStore.selectedGrid.legend.map((d: any) => d.name);
const param = await useQueryTopologyMetrics(names, ids); const param = await useQueryTopologyMetrics(names, ids);
const res = await topologyStore.getLegendMetrics(param); const res = await topologyStore.getLegendMetrics(param);
@ -343,6 +338,9 @@ function deleteItem(index: number) {
updateSettings(); updateSettings();
} }
function updateSettings() { function updateSettings() {
const metrics = legend.metric.filter(
(d: any) => d.name && d.value && d.condition
);
const param = { const param = {
linkDashboard: states.linkDashboard, linkDashboard: states.linkDashboard,
nodeDashboard: isService nodeDashboard: isService
@ -351,9 +349,10 @@ function updateSettings() {
linkServerMetrics: states.linkServerMetrics, linkServerMetrics: states.linkServerMetrics,
linkClientMetrics: states.linkClientMetrics, linkClientMetrics: states.linkClientMetrics,
nodeMetrics: states.nodeMetrics, nodeMetrics: states.nodeMetrics,
legend: legend.metric, legend: metrics,
}; };
dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, ...param }); dashboardStore.selectWidget({ ...dashboardStore.selectedGrid, ...param });
dashboardStore.setConfigs({ ...dashboardStore.selectedGrid, ...param });
emit("update", param); emit("update", param);
} }
async function changeLinkServerMetrics(options: Option[] | any) { async function changeLinkServerMetrics(options: Option[] | any) {
@ -378,7 +377,7 @@ async function changeNodeMetrics(options: Option[] | any) {
states.nodeMetrics = options.map((d: Option) => d.value); states.nodeMetrics = options.map((d: Option) => d.value);
updateSettings(); updateSettings();
if (!states.nodeMetrics.length) { if (!states.nodeMetrics.length) {
topologyStore.setNodeMetrics({}); topologyStore.setNodeMetricValue({});
return; return;
} }
topologyStore.queryNodeMetrics(states.nodeMetrics); topologyStore.queryNodeMetrics(states.nodeMetrics);
@ -431,8 +430,4 @@ function saveConfig() {
.delete { .delete {
margin: 0 3px; margin: 0 3px;
} }
.save-btn {
margin-top: 20px;
}
</style> </style>