From fdde83e64ace9ee6addfcac4967207887a9b9f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Palancher?= Date: Tue, 5 Nov 2024 14:31:22 +0100 Subject: [PATCH] feat(front): resources/jobs charts in dashboard [WIP] --- .../dashboard/DashboardDiagrams.vue | 17 ++ .../dashboard/HistoricalJobsDiagram.vue | 40 +++ .../dashboard/HistoricalNodesDiagram.vue | 237 ++++++++++++++++++ frontend/src/composables/DataGetter.ts | 27 +- frontend/src/composables/GatewayAPI.ts | 26 +- frontend/src/stores/runtime.ts | 9 + frontend/src/views/DashboardView.vue | 5 + 7 files changed, 354 insertions(+), 7 deletions(-) create mode 100644 frontend/src/components/dashboard/DashboardDiagrams.vue create mode 100644 frontend/src/components/dashboard/HistoricalJobsDiagram.vue create mode 100644 frontend/src/components/dashboard/HistoricalNodesDiagram.vue diff --git a/frontend/src/components/dashboard/DashboardDiagrams.vue b/frontend/src/components/dashboard/DashboardDiagrams.vue new file mode 100644 index 00000000..6c72b3fb --- /dev/null +++ b/frontend/src/components/dashboard/DashboardDiagrams.vue @@ -0,0 +1,17 @@ + + + + + diff --git a/frontend/src/components/dashboard/HistoricalJobsDiagram.vue b/frontend/src/components/dashboard/HistoricalJobsDiagram.vue new file mode 100644 index 00000000..5d73d766 --- /dev/null +++ b/frontend/src/components/dashboard/HistoricalJobsDiagram.vue @@ -0,0 +1,40 @@ + + + + + diff --git a/frontend/src/components/dashboard/HistoricalNodesDiagram.vue b/frontend/src/components/dashboard/HistoricalNodesDiagram.vue new file mode 100644 index 00000000..fa99db10 --- /dev/null +++ b/frontend/src/components/dashboard/HistoricalNodesDiagram.vue @@ -0,0 +1,237 @@ + + + + + diff --git a/frontend/src/composables/DataGetter.ts b/frontend/src/composables/DataGetter.ts index ea052225..39513f9d 100644 --- a/frontend/src/composables/DataGetter.ts +++ b/frontend/src/composables/DataGetter.ts @@ -73,6 +73,8 @@ export function useClusterDataGetter( callback: GatewayAnyClusterApiKey, otherParam?: string | number ) { + let _callback = callback + let _otherParam = otherParam const data: Ref = ref() const unable: Ref = ref(false) const loaded: Ref = ref(false) @@ -99,12 +101,12 @@ export function useClusterDataGetter( try { unable.value = false - if (gateway.isValidGatewayClusterWithStringAPIKey(callback)) { - data.value = (await gateway[callback](cluster, otherParam as string)) as Type - } else if (gateway.isValidGatewayClusterWithNumberAPIKey(callback)) { - data.value = (await gateway[callback](cluster, otherParam as number)) as Type + if (gateway.isValidGatewayClusterWithStringAPIKey(_callback)) { + data.value = (await gateway[_callback](cluster, _otherParam as string)) as Type + } else if (gateway.isValidGatewayClusterWithNumberAPIKey(_callback)) { + data.value = (await gateway[_callback](cluster, _otherParam as number)) as Type } else { - data.value = (await gateway[callback](cluster)) as Type + data.value = (await gateway[_callback](cluster)) as Type } loaded.value = true } catch (error: any) { @@ -124,6 +126,19 @@ export function useClusterDataGetter( } } + function setCallback(callback: GatewayAnyClusterApiKey, otherParam?: string | number) { + _callback = callback + if (runtime.currentCluster) { + get(runtime.currentCluster.name) + } + } + function setParam(otherParam: string | number) { + _otherParam = otherParam + if (runtime.currentCluster) { + get(runtime.currentCluster.name) + } + } + watch( () => runtime.currentCluster, (newCluster, oldCluster) => { @@ -141,5 +156,5 @@ export function useClusterDataGetter( get(runtime.currentCluster.name) } }) - return { data, unable, loaded } + return { data, unable, loaded, setCallback, setParam } } diff --git a/frontend/src/composables/GatewayAPI.ts b/frontend/src/composables/GatewayAPI.ts index c78a08af..7e626228 100644 --- a/frontend/src/composables/GatewayAPI.ts +++ b/frontend/src/composables/GatewayAPI.ts @@ -24,6 +24,7 @@ interface loginIdents { export interface ClusterDescription { name: string infrastructure: string + metrics: boolean permissions: ClusterPermissions stats?: ClusterStats } @@ -255,6 +256,9 @@ export interface ClusterReservation { flags: string[] } +export type MetricValue = [number, string] +export type MetricResourceState = 'idle' | 'down' | 'mixed' | 'allocated' | 'drain' | 'unknown' + export function renderClusterOptionalNumber(optionalNumber: ClusterOptionalNumber): string { if (!optionalNumber.set) { return '-' @@ -356,7 +360,7 @@ const GatewayClusterAPIKeys = [ export type GatewayClusterAPIKey = (typeof GatewayClusterAPIKeys)[number] const GatewayClusterWithNumberAPIKeys = ['job'] as const export type GatewayClusterWithNumberAPIKey = (typeof GatewayClusterWithNumberAPIKeys)[number] -const GatewayClusterWithStringAPIKeys = ['node'] as const +const GatewayClusterWithStringAPIKeys = ['node', 'metrics_nodes', 'metrics_cores'] as const export type GatewayClusterWithStringAPIKey = (typeof GatewayClusterWithStringAPIKeys)[number] export type GatewayAnyClusterApiKey = | GatewayClusterAPIKey @@ -525,6 +529,24 @@ export function useGatewayAPI() { return await get(`/agents/${cluster}/accounts`) } + async function metrics_nodes( + cluster: string, + last: string + ): Promise> { + return await get>( + `/agents/${cluster}/metrics/nodes?range=${last}` + ) + } + + async function metrics_cores( + cluster: string, + last: string + ): Promise> { + return await get>( + `/agents/${cluster}/metrics/cores?range=${last}` + ) + } + async function infrastructureImagePng( cluster: string, infrastructure: string, @@ -599,6 +621,8 @@ export function useGatewayAPI() { qos, reservations, accounts, + metrics_nodes, + metrics_cores, infrastructureImagePng, abort, isValidGatewayGenericAPIKey, diff --git a/frontend/src/stores/runtime.ts b/frontend/src/stores/runtime.ts index d4d4b8cd..902b29e8 100644 --- a/frontend/src/stores/runtime.ts +++ b/frontend/src/stores/runtime.ts @@ -13,6 +13,14 @@ import type { RouteLocation } from 'vue-router' import { getNodeMainState } from '@/composables/GatewayAPI' import type { ClusterDescription, ClusterJob, ClusterNode } from '@/composables/GatewayAPI' +/* + * Dashboard view settings + */ + +class DashboardViewSettings { + range: string = 'hour' +} + /* * Jobs view settings */ @@ -277,6 +285,7 @@ export const useRuntimeStore = defineStore('runtime', () => { const routePath: Ref = ref('/') const beforeSettingsRoute: Ref = ref(undefined) + const dashboard = ref(new DashboardViewSettings()) const jobs: Ref = ref(new JobsViewSettings()) const resources: Ref = ref(new ResourcesViewSettings()) diff --git a/frontend/src/views/DashboardView.vue b/frontend/src/views/DashboardView.vue index c1d4d14b..85505150 100644 --- a/frontend/src/views/DashboardView.vue +++ b/frontend/src/views/DashboardView.vue @@ -8,10 +8,14 @@