update list metrics

This commit is contained in:
Qiuxia Fan 2022-03-25 21:55:41 +08:00
parent b84b5f9338
commit 59b4c2ad29
7 changed files with 30 additions and 24 deletions

View File

@ -36,7 +36,7 @@ limitations under the License. -->
i: dashboardStore.selectedGrid.i, i: dashboardStore.selectedGrid.i,
metrics: dashboardStore.selectedGrid.metrics, metrics: dashboardStore.selectedGrid.metrics,
metricTypes: dashboardStore.selectedGrid.metricTypes, metricTypes: dashboardStore.selectedGrid.metricTypes,
standard: dashboardStore.selectedGrid.standard, metricConfig: dashboardStore.selectedGrid.metricConfig,
}" }"
:isEdit="isEdit" :isEdit="isEdit"
@changeOpt="setStatus" @changeOpt="setStatus"

View File

@ -31,7 +31,7 @@ limitations under the License. -->
/> />
</div> </div>
<div class="item mb-10"> <div class="item mb-10">
<span class="label">{{ t("metricLabel") }}</span> <span class="label">{{ t("labels") }}</span>
<el-input <el-input
class="input" class="input"
v-model="currentMetric.label" v-model="currentMetric.label"
@ -60,7 +60,7 @@ limitations under the License. -->
size="small" size="small"
placeholder="Select a option" placeholder="Select a option"
@change="changeConfigs(index, { calculation: $event[0].value })" @change="changeConfigs(index, { calculation: $event[0].value })"
class="aggregation" class="selectors"
:clearable="true" :clearable="true"
/> />
</div> </div>
@ -71,7 +71,7 @@ limitations under the License. -->
:options="SortOrder" :options="SortOrder"
size="small" size="small"
placeholder="Select a sort order" placeholder="Select a sort order"
class="aggregation" class="selectors"
@change="changeConfigs(index, { sortOrder: $event[0].value })" @change="changeConfigs(index, { sortOrder: $event[0].value })"
/> />
</div> </div>
@ -130,7 +130,7 @@ function closePopper() {
right: -15px; right: -15px;
} }
.aggregation { .selectors {
width: 365px; width: 365px;
} }
</style> </style>

View File

@ -64,8 +64,8 @@ limitations under the License. -->
metrics: data.metrics, metrics: data.metrics,
metricTypes: data.metricTypes, metricTypes: data.metricTypes,
i: data.i, i: data.i,
metricConfig: data.metricConfig,
}" }"
:standard="data.metricConfig"
:needQuery="needQuery" :needQuery="needQuery"
/> />
</div> </div>

View File

@ -26,11 +26,13 @@ limitations under the License. -->
? null ? null
: singleVal.toFixed(2) : singleVal.toFixed(2)
}} }}
<span v-show="config.showUint">{{ standard.unit }}</span> <span v-show="config.showUint">
<i v-for="(m, index) in metricConfig" :key="index">{{ m.unit }}</i>
</span>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, PropType } from "vue"; import { computed, PropType, ref } from "vue";
import { CardConfig, MetricConfigOpt } from "@/types/dashboard"; import { CardConfig, MetricConfigOpt } from "@/types/dashboard";
/*global defineProps */ /*global defineProps */
@ -40,14 +42,11 @@ const props = defineProps({
default: () => ({}), default: () => ({}),
}, },
config: { config: {
type: Object as PropType<CardConfig>, type: Object as PropType<CardConfig & { metricConfig?: MetricConfigOpt[] }>,
default: () => ({ fontSize: 12, showUint: true, textAlign: "center" }), default: () => ({ fontSize: 12, showUint: true, textAlign: "center" }),
}, },
standard: {
type: Object as PropType<MetricConfigOpt>,
default: () => ({ unit: "" }),
},
}); });
const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []);
const key = computed(() => Object.keys(props.data)[0]); const key = computed(() => Object.keys(props.data)[0]);
const singleVal = computed(() => props.data[key.value]); const singleVal = computed(() => props.data[key.value]);
</script> </script>

View File

@ -92,6 +92,7 @@ import Card from "./Card.vue";
import { EntityType } from "../data"; import { EntityType } from "../data";
import router from "@/router"; import router from "@/router";
import getDashboard from "@/hooks/useDashboardsSession"; import getDashboard from "@/hooks/useDashboardsSession";
import { MetricConfigOpt } from "@/types/dashboard";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
@ -104,7 +105,7 @@ const props = defineProps({
i: string; i: string;
metrics: string[]; metrics: string[];
metricTypes: string[]; metricTypes: string[];
} } & { metricConfig: MetricConfigOpt[] }
>, >,
default: () => ({ dashboardName: "", fontSize: 12, i: "" }), default: () => ({ dashboardName: "", fontSize: 12, i: "" }),
}, },
@ -119,6 +120,7 @@ const endpoints = ref<Endpoint[]>([]);
const pageSize = 5; const pageSize = 5;
const total = 10; const total = 10;
const searchText = ref<string>(""); const searchText = ref<string>("");
const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []);
queryEndpoints(total); queryEndpoints(total);
@ -155,7 +157,10 @@ async function queryEndpointMetrics(currentPods: Endpoint[]) {
ElMessage.error(json.errors); ElMessage.error(json.errors);
return; return;
} }
endpoints.value = usePodsSource(currentPods, json, props.config); endpoints.value = usePodsSource(currentPods, json, {
...props.config,
metricConfig: metricConfig.value,
});
return; return;
} }
endpoints.value = currentPods; endpoints.value = currentPods;

View File

@ -112,6 +112,7 @@ import { useQueryPodsMetrics, usePodsSource } from "@/hooks/useProcessor";
import { EntityType } from "../data"; import { EntityType } from "../data";
import router from "@/router"; import router from "@/router";
import getDashboard from "@/hooks/useDashboardsSession"; import getDashboard from "@/hooks/useDashboardsSession";
import { MetricConfigOpt } from "@/types/dashboard";
/*global defineProps */ /*global defineProps */
const props = defineProps({ const props = defineProps({
@ -122,7 +123,7 @@ const props = defineProps({
metrics: string[]; metrics: string[];
metricTypes: string[]; metricTypes: string[];
isEdit: boolean; isEdit: boolean;
} } & { metricConfig: MetricConfigOpt[] }
>, >,
default: () => ({ default: () => ({
dashboardName: "", dashboardName: "",
@ -144,6 +145,7 @@ const instances = ref<Instance[]>([]); // current instances
const searchInstances = ref<Instance[]>([]); // all instances const searchInstances = ref<Instance[]>([]); // all instances
const pageSize = 5; const pageSize = 5;
const searchText = ref<string>(""); const searchText = ref<string>("");
const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []);
queryInstance(); queryInstance();
async function queryInstance() { async function queryInstance() {
@ -180,7 +182,10 @@ async function queryInstanceMetrics(currentInstances: Instance[]) {
ElMessage.error(json.errors); ElMessage.error(json.errors);
return; return;
} }
instances.value = usePodsSource(currentInstances, json, props.config); instances.value = usePodsSource(currentInstances, json, {
...props.config,
metricConfig: metricConfig.value,
});
return; return;
} }
instances.value = currentInstances; instances.value = currentInstances;

View File

@ -118,16 +118,12 @@ const props = defineProps({
metrics: string[]; metrics: string[];
metricTypes: string[]; metricTypes: string[];
isEdit: boolean; isEdit: boolean;
} } & { metricConfig: MetricConfigOpt[] }
>, >,
default: () => ({ dashboardName: "", fontSize: 12 }), default: () => ({ dashboardName: "", fontSize: 12 }),
}, },
intervalTime: { type: Array as PropType<string[]>, default: () => [] }, intervalTime: { type: Array as PropType<string[]>, default: () => [] },
isEdit: { type: Boolean, default: false }, isEdit: { type: Boolean, default: false },
standard: {
type: Object as PropType<MetricConfigOpt[]>,
default: () => ({ unit: "" }),
},
}); });
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
@ -137,6 +133,7 @@ const services = ref<Service[]>([]);
const searchText = ref<string>(""); const searchText = ref<string>("");
const groups = ref<any>({}); const groups = ref<any>({});
const sortServices = ref<(Service & { merge: boolean })[]>([]); const sortServices = ref<(Service & { merge: boolean })[]>([]);
const metricConfig = ref<MetricConfigOpt[]>(props.config.metricConfig || []);
queryServices(); queryServices();
@ -206,7 +203,7 @@ async function queryServiceMetrics(currentServices: Service[]) {
return; return;
} }
const { metrics } = props.config; const { metrics } = props.config;
console.log(props.config);
if (metrics.length && metrics[0]) { if (metrics.length && metrics[0]) {
const params = await useQueryPodsMetrics( const params = await useQueryPodsMetrics(
currentServices, currentServices,
@ -221,7 +218,7 @@ async function queryServiceMetrics(currentServices: Service[]) {
} }
services.value = usePodsSource(currentServices, json, { services.value = usePodsSource(currentServices, json, {
...props.config, ...props.config,
metricConfig: props.standard || [], metricConfig: metricConfig.value || [],
}); });
return; return;
} }