Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zones): adds ingress/egress online/total counts to zone listing #1612

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 80 additions & 1 deletion src/app/zones/views/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@
:src="`/zone-cps?page=${route.params.page}&size=${route.params.size}`"
@change="setIsCreateZoneButtonVisible"
>
<DataSource
:src="`/zone-ingress-overviews?page=1&size=100`"
@change="getIngresses"
/>
<DataSource
:src="`/zone-egress-overviews?page=1&size=100`"
@change="getEgresses"
/>
<KCard>
<template #body>
<ErrorBlock
Expand All @@ -56,6 +64,8 @@
{ label: 'Name', key: 'name' },
{ label: 'Zone CP Version', key: 'zoneCpVersion' },
{ label: 'Type', key: 'type' },
{ label: 'Ingresses (online / total)', key: 'ingress' },
{ label: 'Egresses (online / total)', key: 'egress' },
{ label: 'Status', key: 'status' },
{ label: 'Warnings', key: 'warnings', hideLabel: true },
{ label: 'Actions', key: 'actions', hideLabel: true },
Expand Down Expand Up @@ -88,6 +98,22 @@
{{ rowValue || t('common.collection.none') }}
</template>

<template #ingress="{ row: item }">
<template
v-for="proxies in [ingresses[item.name] || {online: [], offline: []}]"
>
{{ proxies.online.length }} / {{ proxies.online.length + proxies.offline.length }}
</template>
</template>

<template #egress="{ row: item }">
<template
v-for="proxies in [egresses[item.name] || {online: [], offline: []}]"
>
{{ proxies.online.length }} / {{ proxies.online.length + proxies.offline.length }}
</template>
</template>

<template #status="{ rowValue }">
<StatusBadge
v-if="rowValue"
Expand Down Expand Up @@ -217,7 +243,7 @@ import ErrorBlock from '@/app/common/ErrorBlock.vue'
import StatusBadge from '@/app/common/StatusBadge.vue'
import WarningIcon from '@/app/common/WarningIcon.vue'
import type { MeSource } from '@/app/me/sources'
import { StatusKeyword, ZoneOverview } from '@/types/index.d'
import type { DiscoverySubscription, StatusKeyword, ZoneEgressOverview, ZoneIngressOverview, ZoneOverview } from '@/types/index.d'
import { useKumaApi } from '@/utilities'

type ZoneOverviewTableRow = {
Expand All @@ -238,6 +264,59 @@ const isDeleteModalVisible = ref(false)
const isCreateZoneButtonVisible = ref(false)
const deleteZoneName = ref('')

type ZoneProxies<T> = Record<string, {online: T[], offline: T[]}>
const ingresses = ref<ZoneProxies<ZoneIngressOverview>>({})
const egresses = ref<ZoneProxies<ZoneEgressOverview>>({})

const getState = (subscriptions: DiscoverySubscription[]) => {
let state: 'online' | 'offline' = 'offline'
if (subscriptions.length > 0) {
state = 'online'
const lastSubscription = subscriptions[subscriptions.length - 1]
if (typeof lastSubscription.disconnectTime !== 'undefined') {
state = 'offline'
}
}
return state
}

const getIngresses = (data: {items: ZoneIngressOverview[]}) => {
const prop = 'zoneIngress'
ingresses.value = data.items.reduce((prev, item) => {
const name = item[prop]?.zone
if (typeof name !== 'undefined') {
if (typeof prev[name] === 'undefined') {
prev[name] = {
online: [],
offline: [],
}
}
const subscriptions = item[`${prop}Insight`].subscriptions || []
const state = getState(subscriptions)
prev[name][state].push(item)
}
return prev
}, {} as ZoneProxies<ZoneIngressOverview>)
}
const getEgresses = (data: {items: ZoneEgressOverview[]}) => {
const prop = 'zoneEgress'
egresses.value = data.items.reduce((prev, item) => {
const name = item[prop]?.zone
if (typeof name !== 'undefined') {
if (typeof prev[name] === 'undefined') {
prev[name] = {
online: [],
offline: [],
}
}
const subscriptions = item[`${prop}Insight`].subscriptions || []
const state = getState(subscriptions)
prev[name][state].push(item)
}
return prev
}, {} as ZoneProxies<ZoneEgressOverview>)
}

function transformToTableData(zoneOverviews: ZoneOverview[]): ZoneOverviewTableRow[] {
return zoneOverviews.map((zoneOverview) => {
const { name } = zoneOverview
Expand Down