fix: update metrics

This commit is contained in:
Qiuxia Fan 2022-01-25 14:43:24 +08:00
parent 9389eeb184
commit 137f093e05
9 changed files with 50 additions and 34 deletions

View File

@ -41,8 +41,11 @@ onMounted(() => {
watch( watch(
() => props.option, () => props.option,
(opt) => { (newVal, oldVal) => {
setOptions(opt); if (JSON.stringify(newVal) === JSON.stringify(oldVal)) {
return;
}
setOptions(newVal);
} }
); );

View File

@ -79,10 +79,10 @@ export function useQueryProcessor(config: any) {
? undefined ? undefined
: selectorStore.currentService.normal, : selectorStore.currentService.normal,
serviceInstanceName: dashboardStore.entity.includes("ServiceInstance") serviceInstanceName: dashboardStore.entity.includes("ServiceInstance")
? selectorStore.currentPod.value ? selectorStore.currentPod && selectorStore.currentPod.value
: undefined, : undefined,
endpointName: dashboardStore.entity.includes("Endpoint") endpointName: dashboardStore.entity.includes("Endpoint")
? selectorStore.currentPod.value ? selectorStore.currentPod && selectorStore.currentPod.value
: undefined, : undefined,
destNormal: isRelation destNormal: isRelation
? selectorStore.currentDestService.normal ? selectorStore.currentDestService.normal
@ -92,11 +92,13 @@ export function useQueryProcessor(config: any) {
: undefined, : undefined,
destServiceInstanceName: destServiceInstanceName:
dashboardStore.entity === "ServiceInstanceRelation" dashboardStore.entity === "ServiceInstanceRelation"
? selectorStore.currentDestPod.value ? selectorStore.currentDestPod &&
selectorStore.currentDestPod.value
: undefined, : undefined,
destEndpointName: destEndpointName:
dashboardStore.entity === "EndpointRelation" dashboardStore.entity === "EndpointRelation"
? selectorStore.currentDestPod.value ? selectorStore.currentDestPod &&
selectorStore.currentDestPod.value
: undefined, : undefined,
}, },
}; };

View File

@ -48,6 +48,7 @@ export const selectorStore = defineStore({
this.currentService = service; this.currentService = service;
}, },
setCurrentPod(pod: Nullable<Instance | Endpoint>) { setCurrentPod(pod: Nullable<Instance | Endpoint>) {
console.log(pod);
this.currentPod = pod; this.currentPod = pod;
}, },
async fetchLayers(): Promise<AxiosResponse> { async fetchLayers(): Promise<AxiosResponse> {

View File

@ -93,6 +93,7 @@ import {
EntityType, EntityType,
ChartTypes, ChartTypes,
PodsChartTypes, PodsChartTypes,
TableEntity,
} from "../data"; } from "../data";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import Icon from "@/components/Icon.vue"; import Icon from "@/components/Icon.vue";
@ -127,7 +128,11 @@ states.visTypes = setVisTypes();
setMetricType(); setMetricType();
async function setMetricType(catalog?: string) { async function setMetricType(catalog?: string) {
catalog = catalog || dashboardStore.entity; if (states.isTable) {
catalog = catalog || TableEntity[graph.type];
} else {
catalog = catalog || dashboardStore.entity;
}
const json = await dashboardStore.fetchMetricList(); const json = await dashboardStore.fetchMetricList();
if (json.errors) { if (json.errors) {
ElMessage.error(json.errors); ElMessage.error(json.errors);

View File

@ -62,7 +62,6 @@ limitations under the License. -->
<script lang="ts"> <script lang="ts">
import { toRefs, reactive, defineComponent, ref, watch } from "vue"; import { toRefs, reactive, defineComponent, ref, watch } from "vue";
import type { PropType } from "vue"; import type { PropType } from "vue";
import { useRoute } from "vue-router";
import { LayoutConfig } from "@/types/dashboard"; import { LayoutConfig } from "@/types/dashboard";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";

View File

@ -155,6 +155,11 @@ export const EntityType = [
}, },
{ value: "EndpointRelation", label: "Endpoint Relation", key: 4 }, { value: "EndpointRelation", label: "Endpoint Relation", key: 4 },
]; ];
export const TableEntity: any = {
InstanceList: EntityType[3].value,
EndpointList: EntityType[2].value,
ServiceList: EntityType[0].value,
};
export const SortOrder = [ export const SortOrder = [
{ label: "DES", value: "DES" }, { label: "DES", value: "DES" },
{ label: "ASC", value: "ASC" }, { label: "ASC", value: "ASC" },

View File

@ -42,7 +42,7 @@ limitations under the License. -->
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
v-for="(metric, index) in dashboardStore.selectedGrid.metrics" v-for="(metric, index) in config.metrics"
:label="metric" :label="metric"
:key="metric + index" :key="metric + index"
> >
@ -87,7 +87,13 @@ const props = defineProps({
type: Object, type: Object,
}, },
config: { config: {
type: Object as PropType<EndpointListConfig & { i: string }>, type: Object as PropType<
EndpointListConfig & {
i: string;
metrics: string[];
metricTypes: string[];
}
>,
default: () => ({ dashboardName: "", fontSize: 12, i: "" }), default: () => ({ dashboardName: "", fontSize: 12, i: "" }),
}, },
intervalTime: { type: Array as PropType<string[]>, default: () => [] }, intervalTime: { type: Array as PropType<string[]>, default: () => [] },
@ -116,7 +122,7 @@ async function queryEndpoints() {
queryEndpointMetrics(endpoints.value); queryEndpointMetrics(endpoints.value);
} }
async function queryEndpointMetrics(currentPods: Endpoint[]) { async function queryEndpointMetrics(currentPods: Endpoint[]) {
const { metrics } = dashboardStore.selectedGrid; const { metrics } = props.config;
if (metrics.length && metrics[0]) { if (metrics.length && metrics[0]) {
const params = await useQueryPodsMetrics( const params = await useQueryPodsMetrics(
@ -150,14 +156,9 @@ function searchList() {
endpoints.value = currentEndpoints.splice(0, pageSize); endpoints.value = currentEndpoints.splice(0, pageSize);
} }
watch( watch(
() => [ () => [props.config.metricTypes, props.config.metrics],
dashboardStore.selectedGrid.metricTypes,
dashboardStore.selectedGrid.metrics,
],
() => { () => {
if (dashboardStore.selectedGrid.i === props.config.i) { queryEndpointMetrics(endpoints.value);
queryEndpointMetrics(endpoints.value);
}
} }
); );
</script> </script>

View File

@ -50,13 +50,13 @@ limitations under the License. -->
<div class="chart"> <div class="chart">
<Line <Line
v-if="config.metricTypes[index] === 'readMetricsValues'" v-if="config.metricTypes[index] === 'readMetricsValues'"
:data="{ metric: scope.row[metric] }" :data="metric ? { [metric]: scope.row[metric] } : {}"
:intervalTime="intervalTime" :intervalTime="intervalTime"
:config="{ showXAxis: false, showYAxis: false }" :config="{ showXAxis: false, showYAxis: false }"
/> />
<Card <Card
v-else v-else
:data="{ metric: scope.row[metric] }" :data="{ [metric]: scope.row[metric] }"
:config="{ textAlign: 'left' }" :config="{ textAlign: 'left' }"
/> />
</div> </div>
@ -128,6 +128,8 @@ async function queryInstance() {
return; return;
} }
searchInstances.value = selectorStore.pods; searchInstances.value = selectorStore.pods;
instances.value = searchInstances.value.splice(0, pageSize);
queryInstanceMetrics(instances.value);
} }
async function queryInstanceMetrics(currentInstances: Instance[]) { async function queryInstanceMetrics(currentInstances: Instance[]) {
@ -168,10 +170,7 @@ function searchList() {
watch( watch(
() => [props.config.metricTypes, props.config.metrics], () => [props.config.metricTypes, props.config.metrics],
() => { () => {
if (dashboardStore.selectedGrid.i === props.config.i) { queryInstanceMetrics(instances.value);
const currentInstances = searchInstances.value.splice(0, pageSize);
queryInstanceMetrics(currentInstances);
}
} }
); );
</script> </script>

View File

@ -43,7 +43,7 @@ limitations under the License. -->
</template> </template>
</el-table-column> </el-table-column>
<el-table-column <el-table-column
v-for="(metric, index) in dashboardStore.selectedGrid.metrics" v-for="(metric, index) in config.metrics"
:label="metric" :label="metric"
:key="metric + index" :key="metric + index"
> >
@ -88,7 +88,13 @@ const props = defineProps({
type: Object, type: Object,
}, },
config: { config: {
type: Object as PropType<ServiceListConfig>, type: Object as PropType<
ServiceListConfig & {
i: string;
metrics: string[];
metricTypes: string[];
}
>,
default: () => ({ dashboardName: "", fontSize: 12 }), default: () => ({ dashboardName: "", fontSize: 12 }),
}, },
intervalTime: { type: Array as PropType<string[]>, default: () => [] }, intervalTime: { type: Array as PropType<string[]>, default: () => [] },
@ -114,7 +120,7 @@ async function queryServices() {
services.value = selectorStore.services.splice(0, pageSize); services.value = selectorStore.services.splice(0, pageSize);
} }
async function queryServiceMetrics(currentServices: Service[]) { async function queryServiceMetrics(currentServices: Service[]) {
const { metrics } = dashboardStore.selectedGrid; const { metrics } = props.config;
if (metrics.length && metrics[0]) { if (metrics.length && metrics[0]) {
const params = await useQueryPodsMetrics( const params = await useQueryPodsMetrics(
@ -147,14 +153,9 @@ function searchList() {
services.value = searchServices.value.splice(0, pageSize); services.value = searchServices.value.splice(0, pageSize);
} }
watch( watch(
() => [ () => [props.config.metricTypes, props.config.metrics],
dashboardStore.selectedGrid.metricTypes,
dashboardStore.selectedGrid.metrics,
],
() => { () => {
if (dashboardStore.selectedGrid.i === props.config.i) { queryServiceMetrics(services.value);
queryServiceMetrics(services.value);
}
} }
); );
</script> </script>