From 772d37b09393d85b8f84f0e0fea7276b161080b3 Mon Sep 17 00:00:00 2001 From: Lou Knauer Date: Fri, 8 Jul 2022 12:23:24 +0200 Subject: [PATCH] Fixes #14: Lazy load additional metrics --- configs/README.md | 2 ++ web/frontend/src/Job.root.svelte | 34 +++++++++++++++++++++++-------- web/frontend/src/PlotTable.svelte | 6 +++--- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/configs/README.md b/configs/README.md index f04fb5a..050ea2c 100644 --- a/configs/README.md +++ b/configs/README.md @@ -49,6 +49,8 @@ All security relevant configuration. e.g., keys and passwords, are set using env - `plot_view_showStatTable`: Type bool. Option to toggle the node statistic table in single job view. Default `true`. - `system_view_selectedMetric`: Type string. Initial metric shown in system view. Default `cpu_load`. +Some of the `ui-defaults` values can be appended by `:` in order to have different settings depending on the current cluster. Those are notably `job_view_nodestats_selectedMetrics`, `job_view_polarPlotMetrics`, `job_view_selectedMetrics` and `plot_list_selectedMetrics`. + ## Environment Variables An example env file is found in this directory. Copy it to `.env` in the project root and adapt it for your needs. diff --git a/web/frontend/src/Job.root.svelte b/web/frontend/src/Job.root.svelte index 92c230b..9ff68ba 100644 --- a/web/frontend/src/Job.root.svelte +++ b/web/frontend/src/Job.root.svelte @@ -31,26 +31,42 @@ const ccconfig = getContext('cc-config'), clusters = getContext('clusters') - let isMetricsSelectionOpen = false, selectedMetrics = [] + let isMetricsSelectionOpen = false, selectedMetrics = [], isFetched = new Set() const [jobMetrics, startFetching] = fetchMetricsStore() getContext('on-init')(() => { let job = $initq.data.job if (!job) return - startFetching(job, null, job.numNodes > 2 ? ["node"] : ["node", "core"]) - - // TODO: Do not even fetch metrics that are not one of the following: flops_any, mem_bw, job_view_selectedMetrics, job_view_nodestats_selectedMetrics selectedMetrics = ccconfig[`job_view_selectedMetrics:${job.cluster}`] || clusters.find(c => c.name == job.cluster).metricConfig.map(mc => mc.name) + let toFetch = new Set([ + 'flops_any', 'mem_bw', + ...selectedMetrics, + ...(ccconfig[`job_view_polarPlotMetrics:${job.cluster}`] || ccconfig[`job_view_polarPlotMetrics`]), + ...(ccconfig[`job_view_nodestats_selectedMetrics:${job.cluster}`] || ccconfig[`job_view_nodestats_selectedMetrics`])]) - // selectedMetrics = ccconfig[`job_view_selectedMetrics:${job.cluster}`] - // || clusters.find(c => c.name == job.cluster).metricConfig.map(mc => mc.name) - - // let toFetch = new Set(['flops_any', 'mem_bw', ]) + startFetching(job, [...toFetch], job.numNodes > 2 ? ["node"] : ["node", "core"]) + isFetched = toFetch }) + const lazyFetchMoreMetrics = () => { + let notYetFetched = new Set() + for (let m of selectedMetrics) { + if (!isFetched.has(m)) { + notYetFetched.add(m) + isFetched.add(m) + } + } + + if (notYetFetched.size > 0) + startFetching($initq.data.job, [...notYetFetched], $initq.data.job.numNodes > 2 ? ["node"] : ["node", "core"]) + } + + // Fetch more data once required: + $: if ($initq.data && $jobMetrics.data && selectedMetrics) lazyFetchMoreMetrics(); + let plots = {}, jobTags, fullWidth, statsTable $: polarPlotSize = Math.min(fullWidth / 3 - 10, 300) $: document.title = $initq.fetching ? 'Loading...' : ($initq.error ? 'Error' : `Job ${$initq.data.job.jobId} - ClusterCockpit`) @@ -88,7 +104,7 @@ diff --git a/web/frontend/src/PlotTable.svelte b/web/frontend/src/PlotTable.svelte index 208c4af..24b851b 100644 --- a/web/frontend/src/PlotTable.svelte +++ b/web/frontend/src/PlotTable.svelte @@ -12,7 +12,7 @@ export let padding = 10 let tableWidth = 0 - const PLACEHOLDER = { magic: 'object' } + const isPlaceholder = x => x._is_placeholder === true function tile(items, itemsPerRow) { const rows = [] @@ -22,7 +22,7 @@ if (ri + ci < items.length) row.push(items[ri + ci]) else - row.push(PLACEHOLDER) + row.push({ _is_placeholder: true, ri, ci }) } rows.push(row) @@ -40,7 +40,7 @@ {#each row as item (item)} - {#if item != PLACEHOLDER && plotWidth > 0} + {#if !isPlaceholder(item) && plotWidth > 0} {/if}