feat: add a calculation and update selectors param (#53)

This commit is contained in:
Fine0830 2022-04-01 23:28:39 +08:00 committed by GitHub
parent fce818aebe
commit f57fdf9312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 91 additions and 33 deletions

View File

@ -32,6 +32,7 @@ export enum Calculations {
Precision = "precision", Precision = "precision",
ConvertSeconds = "convertSeconds", ConvertSeconds = "convertSeconds",
ConvertMilliseconds = "convertMilliseconds", ConvertMilliseconds = "convertMilliseconds",
MsTos = "msTos",
} }
export enum sizeEnum { export enum sizeEnum {
XS = "XS", XS = "XS",

View File

@ -351,6 +351,9 @@ export function aggregation(val: number, config: any): number | string {
case Calculations.Precision: case Calculations.Precision:
data = data.toFixed(2); data = data.toFixed(2);
break; break;
case Calculations.MsTos:
data = val / 1000;
break;
default: default:
data; data;
break; break;

View File

@ -66,7 +66,7 @@ const theme = ref<string>("light");
getVersion(); getVersion();
const setConfig = (value: string) => { const setConfig = (value: string) => {
pageName.value = value || ""; pageName.value = value || "";
theme.value = route.path.includes("/infrastructure/") ? "dark" : "light"; // theme.value = route.path.includes("/infrastructure/") ? "dark" : "light";
}; };
const time = computed(() => [ const time = computed(() => [
appStore.durationRow.start, appStore.durationRow.start,
@ -94,6 +94,9 @@ watch(
} }
); );
async function getVersion() { async function getVersion() {
if (appStore.version) {
return;
}
const res = await appStore.fetchVersion(); const res = await appStore.fetchVersion();
if (res.errors) { if (res.errors) {
ElMessage.error(res.errors); ElMessage.error(res.errors);

View File

@ -38,12 +38,17 @@ limitations under the License. -->
class="body" class="body"
:style="{ :style="{
backgroundColor: TextColors[graph.backgroundColor], backgroundColor: TextColors[graph.backgroundColor],
color: TextColors[graph.fontColor],
fontSize: graph.fontSize + 'px',
textAlign: graph.textAlign, textAlign: graph.textAlign,
}" }"
> >
<a :href="graph.url" target="_blank"> <a
:href="graph.url"
target="_blank"
:style="{
color: TextColors[graph.fontColor],
fontSize: graph.fontSize + 'px',
}"
>
{{ graph.content }} {{ graph.content }}
</a> </a>
</div> </div>

View File

@ -109,11 +109,14 @@ export default defineComponent({
const selectorStore = useSelectorStore(); const selectorStore = useSelectorStore();
const graph = computed(() => props.data.graph || {}); const graph = computed(() => props.data.graph || {});
const widget = computed(() => props.data.widget || {}); const widget = computed(() => props.data.widget || {});
const isList = ListChartTypes.includes( const isList = computed(() =>
(props.data.graph && props.data.graph.type) || "" ListChartTypes.includes((props.data.graph && props.data.graph.type) || "")
); );
if ((props.needQuery || !dashboardStore.currentDashboard.id) && !isList) { if (
(props.needQuery || !dashboardStore.currentDashboard.id) &&
!isList.value
) {
queryMetrics(); queryMetrics();
} }
@ -162,11 +165,8 @@ export default defineComponent({
if (props.data.i !== dashboardStore.selectedGrid.i) { if (props.data.i !== dashboardStore.selectedGrid.i) {
return; return;
} }
const isList = ListChartTypes.includes(
(props.data.graph && props.data.graph.type) || ""
);
const chart = dashboardStore.selectedGrid.graph || {}; const chart = dashboardStore.selectedGrid.graph || {};
if (ListChartTypes.includes(chart.type) || isList) { if (ListChartTypes.includes(chart.type) || isList.value) {
return; return;
} }
queryMetrics(); queryMetrics();
@ -175,10 +175,7 @@ export default defineComponent({
watch( watch(
() => [selectorStore.currentService, selectorStore.currentDestService], () => [selectorStore.currentService, selectorStore.currentDestService],
() => { () => {
const isList = ListChartTypes.includes( if (isList.value) {
(props.data.graph && props.data.graph.type) || ""
);
if (isList) {
return; return;
} }
if ( if (
@ -195,12 +192,18 @@ export default defineComponent({
if (dashboardStore.entity === EntityType[0].value) { if (dashboardStore.entity === EntityType[0].value) {
return; return;
} }
if (isList.value) {
return;
}
queryMetrics(); queryMetrics();
} }
); );
watch( watch(
() => appStore.durationTime, () => appStore.durationTime,
() => { () => {
if (isList.value) {
return;
}
if (dashboardStore.entity === EntityType[1].value) { if (dashboardStore.entity === EntityType[1].value) {
queryMetrics(); queryMetrics();
} }

View File

@ -272,4 +272,5 @@ export const CalculationOpts = [
}, },
{ label: "Convert seconds to YYYY-MM-DD HH:mm:ss", value: "convertSeconds" }, { label: "Convert seconds to YYYY-MM-DD HH:mm:ss", value: "convertSeconds" },
{ label: "Precision is 2", value: "precision" }, { label: "Precision is 2", value: "precision" },
{ label: "Milliseconds to seconds", value: "msTos" },
]; ];

View File

@ -203,8 +203,11 @@ function getLabel(metric: string, index: number) {
return encodeURIComponent(metric); return encodeURIComponent(metric);
} }
watch( watch(
() => [props.config.metricTypes, props.config.metrics], () => [...(props.config.metricTypes || []), ...(props.config.metrics || [])],
async () => { (data, old) => {
if (JSON.stringify(data) === JSON.stringify(old)) {
return;
}
queryEndpointMetrics(endpoints.value); queryEndpointMetrics(endpoints.value);
} }
); );
@ -214,6 +217,15 @@ watch(
queryEndpoints(); queryEndpoints();
} }
); );
watch(
() => [...(props.config.metricConfig || [])],
(data, old) => {
if (JSON.stringify(data) === JSON.stringify(old)) {
return;
}
queryEndpointMetrics(endpoints.value);
}
);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "./style.scss"; @import "./style.scss";

View File

@ -257,8 +257,11 @@ function getLabel(metric: string, index: number) {
} }
watch( watch(
() => [props.config.metricTypes, props.config.metrics], () => [...(props.config.metricTypes || []), ...(props.config.metrics || [])],
() => { (data, old) => {
if (JSON.stringify(data) === JSON.stringify(old)) {
return;
}
queryInstanceMetrics(instances.value); queryInstanceMetrics(instances.value);
} }
); );
@ -268,6 +271,15 @@ watch(
queryInstance(); queryInstance();
} }
); );
watch(
() => [...(props.config.metricConfig || [])],
(data, old) => {
if (JSON.stringify(data) === JSON.stringify(old)) {
return;
}
queryInstanceMetrics(instances.value);
}
);
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import "./style.scss"; @import "./style.scss";

View File

@ -143,7 +143,6 @@ const sortServices = ref<(Service & { merge: boolean })[]>([]);
const colMetrics = computed(() => const colMetrics = computed(() =>
props.config.metrics.filter((d: string) => d) props.config.metrics.filter((d: string) => d)
); );
queryServices(); queryServices();
async function queryServices() { async function queryServices() {
@ -296,9 +295,22 @@ function getLabel(metric: string, index: number) {
} }
return encodeURIComponent(metric); return encodeURIComponent(metric);
} }
watch( watch(
() => [props.config.metricTypes, props.config.metrics], () => [...(props.config.metricTypes || []), ...(props.config.metrics || [])],
() => { (data, old) => {
if (JSON.stringify(data) === JSON.stringify(old)) {
return;
}
queryServiceMetrics(services.value);
}
);
watch(
() => [...(props.config.metricConfig || [])],
(data, old) => {
if (JSON.stringify(data) === JSON.stringify(old)) {
return;
}
queryServiceMetrics(services.value); queryServiceMetrics(services.value);
} }
); );

View File

@ -15,7 +15,7 @@ limitations under the License. -->
<template> <template>
<div class="dashboard-tool flex-h"> <div class="dashboard-tool flex-h">
<div class="flex-h"> <div class="flex-h">
<div class="selectors-item" v-if="states.key !== 10"> <div class="selectors-item" v-if="key !== 10">
<span class="label">$Service</span> <span class="label">$Service</span>
<Selector <Selector
v-model="states.currentService" v-model="states.currentService"
@ -26,7 +26,7 @@ limitations under the License. -->
class="selectors" class="selectors"
/> />
</div> </div>
<div class="selectors-item" v-if="states.key === 3 || states.key === 4"> <div class="selectors-item" v-if="key === 3 || key === 4">
<span class="label"> <span class="label">
{{ {{
["EndpointRelation", "Endpoint"].includes(dashboardStore.entity) ["EndpointRelation", "Endpoint"].includes(dashboardStore.entity)
@ -47,7 +47,7 @@ limitations under the License. -->
" "
/> />
</div> </div>
<div class="selectors-item" v-if="states.key === 2 || states.key === 4"> <div class="selectors-item" v-if="key === 2 || key === 4">
<span class="label">$DestinationService</span> <span class="label">$DestinationService</span>
<Selector <Selector
v-model="states.currentDestService" v-model="states.currentDestService"
@ -58,7 +58,7 @@ limitations under the License. -->
class="selectors" class="selectors"
/> />
</div> </div>
<div class="selectors-item" v-if="states.key === 4"> <div class="selectors-item" v-if="key === 4">
<span class="label"> <span class="label">
{{ {{
dashboardStore.entity === "EndpointRelation" dashboardStore.entity === "EndpointRelation"
@ -120,7 +120,7 @@ limitations under the License. -->
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { reactive, ref } from "vue"; import { reactive, ref, computed } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
@ -165,6 +165,13 @@ const states = reactive<{
currentDestService: "", currentDestService: "",
currentDestPod: "", currentDestPod: "",
}); });
const key = computed(() => {
const type = EntityType.find(
(d: Option) => d.value === dashboardStore.entity
);
return (type && type.key) || 0;
});
setCurrentDashboard(); setCurrentDashboard();
appStore.setEventStack([initSelector]); appStore.setEventStack([initSelector]);
@ -184,10 +191,6 @@ function setCurrentDashboard() {
dashboardStore.setLayer(params.layerId); dashboardStore.setLayer(params.layerId);
dashboardStore.setEntity(params.entity); dashboardStore.setEntity(params.entity);
} }
const type = EntityType.filter(
(d: Option) => d.value === dashboardStore.entity
)[0];
states.key = (type && type.key) || 0;
} }
async function setSelector() { async function setSelector() {
@ -242,9 +245,9 @@ async function setSourceSelector() {
return; return;
} }
const pod = params.podId || selectorStore.pods[0].id; const pod = params.podId || selectorStore.pods[0].id;
const currentPod = selectorStore.pods.filter( const currentPod = selectorStore.pods.find(
(d: { id: string }) => d.id === pod (d: { id: string }) => d.id === pod
)[0]; );
if (currentPod) { if (currentPod) {
selectorStore.setCurrentPod(currentPod); selectorStore.setCurrentPod(currentPod);
states.currentPod = currentPod.label; states.currentPod = currentPod.label;
@ -275,6 +278,9 @@ async function setDestSelector() {
} }
async function getServices() { async function getServices() {
if (key.value === 10 || key.value === 0) {
return;
}
if (!dashboardStore.layerId) { if (!dashboardStore.layerId) {
return; return;
} }