2024-07-25 17:10:00 +02:00
|
|
|
<!--
|
|
|
|
@component Metric plot wrapper with user scope selection; used in job detail view
|
|
|
|
|
|
|
|
Properties:
|
|
|
|
- `job Object`: The GQL job object
|
|
|
|
- `metricName String`: The metrics name
|
|
|
|
- `metricUnit Object`: The metrics GQL unit object
|
|
|
|
- `nativeScope String`: The metrics native scope
|
|
|
|
- `scopes [String]`: The scopes returned for this metric
|
|
|
|
- `rawData [Object]`: Metric data for all scopes returned for this metric
|
|
|
|
- `isShared Bool?`: If this job used shared resources; will adapt threshold indicators accordingly in downstream plots [Default: false]
|
|
|
|
-->
|
|
|
|
|
2022-06-22 11:20:57 +02:00
|
|
|
<script>
|
2024-08-23 13:26:56 +02:00
|
|
|
import {
|
2024-09-24 11:13:39 +02:00
|
|
|
getContext,
|
2024-08-23 13:26:56 +02:00
|
|
|
createEventDispatcher
|
|
|
|
} from "svelte";
|
2024-08-16 14:50:31 +02:00
|
|
|
import {
|
|
|
|
queryStore,
|
|
|
|
gql,
|
|
|
|
getContextClient
|
|
|
|
} from "@urql/svelte";
|
2024-03-09 10:30:40 +01:00
|
|
|
import {
|
|
|
|
InputGroup,
|
|
|
|
InputGroupText,
|
|
|
|
Spinner,
|
|
|
|
Card,
|
|
|
|
} from "@sveltestrap/sveltestrap";
|
2024-09-02 18:22:34 +02:00
|
|
|
import {
|
|
|
|
minScope,
|
|
|
|
} from "../generic/utils.js";
|
2024-07-26 12:34:18 +02:00
|
|
|
import Timeseries from "../generic/plots/MetricPlot.svelte";
|
2022-06-22 11:20:57 +02:00
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
export let job;
|
|
|
|
export let metricName;
|
2024-07-22 15:41:33 +02:00
|
|
|
export let metricUnit;
|
|
|
|
export let nativeScope;
|
2024-03-09 10:30:40 +01:00
|
|
|
export let scopes;
|
|
|
|
export let rawData;
|
|
|
|
export let isShared = false;
|
2022-06-22 11:20:57 +02:00
|
|
|
|
2024-09-24 11:13:39 +02:00
|
|
|
const resampleConfig = getContext("resampling") || null;
|
|
|
|
const resampleDefault = resampleConfig ? Math.max(...resampleConfig.resolutions) : 0;
|
|
|
|
|
2024-09-02 18:22:34 +02:00
|
|
|
let selectedHost = null;
|
|
|
|
let error = null;
|
2024-03-09 10:30:40 +01:00
|
|
|
let selectedScope = minScope(scopes);
|
2024-09-24 11:13:39 +02:00
|
|
|
let selectedResolution = null;
|
|
|
|
let pendingResolution = resampleDefault;
|
2024-08-20 11:39:19 +02:00
|
|
|
let selectedScopeIndex = scopes.findIndex((s) => s == minScope(scopes));
|
|
|
|
let patternMatches = false;
|
2024-08-23 13:53:15 +02:00
|
|
|
let nodeOnly = false; // If, after load-all, still only node scope returned
|
2024-08-20 11:39:19 +02:00
|
|
|
let statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null);
|
2024-09-02 18:22:34 +02:00
|
|
|
let zoomState = null;
|
|
|
|
let pendingZoomState = null;
|
2024-05-02 16:32:01 +02:00
|
|
|
|
2024-08-23 13:26:56 +02:00
|
|
|
const dispatch = createEventDispatcher();
|
2024-08-20 14:52:13 +02:00
|
|
|
const statsPattern = /(.*)-stat$/;
|
2024-08-20 11:39:19 +02:00
|
|
|
const unit = (metricUnit?.prefix ? metricUnit.prefix : "") + (metricUnit?.base ? metricUnit.base : "");
|
2024-08-16 14:50:31 +02:00
|
|
|
const client = getContextClient();
|
|
|
|
const subQuery = gql`
|
|
|
|
query ($dbid: ID!, $selectedMetrics: [String!]!, $selectedScopes: [MetricScope!]!, $selectedResolution: Int) {
|
|
|
|
singleUpdate: jobMetrics(id: $dbid, metrics: $selectedMetrics, scopes: $selectedScopes, resolution: $selectedResolution) {
|
|
|
|
name
|
|
|
|
scope
|
|
|
|
metric {
|
|
|
|
unit {
|
|
|
|
prefix
|
|
|
|
base
|
|
|
|
}
|
|
|
|
timestep
|
|
|
|
statisticsSeries {
|
|
|
|
min
|
2024-09-30 18:31:49 +02:00
|
|
|
mean
|
2024-08-16 14:50:31 +02:00
|
|
|
median
|
|
|
|
max
|
|
|
|
}
|
|
|
|
series {
|
|
|
|
hostname
|
|
|
|
id
|
|
|
|
data
|
|
|
|
statistics {
|
|
|
|
min
|
|
|
|
avg
|
|
|
|
max
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2024-09-02 18:22:34 +02:00
|
|
|
function handleZoom(detail) {
|
|
|
|
if ( // States have to differ, causes deathloop if just set
|
|
|
|
(pendingZoomState?.x?.min !== detail?.lastZoomState?.x?.min) &&
|
|
|
|
(pendingZoomState?.y?.max !== detail?.lastZoomState?.y?.max)
|
|
|
|
) {
|
|
|
|
pendingZoomState = {...detail.lastZoomState}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (detail?.newRes) { // Triggers GQL
|
|
|
|
pendingResolution = detail.newRes
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-16 14:50:31 +02:00
|
|
|
let metricData;
|
|
|
|
let selectedScopes = [...scopes]
|
|
|
|
const dbid = job.id;
|
|
|
|
const selectedMetrics = [metricName]
|
|
|
|
|
2024-08-20 11:51:38 +02:00
|
|
|
$: if (selectedScope || pendingResolution) {
|
2024-08-20 11:39:19 +02:00
|
|
|
if (!selectedResolution) {
|
2024-08-20 11:51:38 +02:00
|
|
|
// Skips reactive data load on init
|
2024-08-20 11:39:19 +02:00
|
|
|
selectedResolution = Number(pendingResolution)
|
2024-08-20 14:52:13 +02:00
|
|
|
|
2024-08-20 11:39:19 +02:00
|
|
|
} else {
|
2024-08-20 14:52:13 +02:00
|
|
|
if (selectedScope == "load-all") {
|
|
|
|
selectedScopes = [...scopes, "socket", "core", "accelerator"]
|
|
|
|
}
|
|
|
|
|
2024-09-24 11:13:39 +02:00
|
|
|
if (pendingResolution) {
|
|
|
|
selectedResolution = Number(pendingResolution)
|
|
|
|
}
|
2024-08-20 11:39:19 +02:00
|
|
|
|
|
|
|
metricData = queryStore({
|
|
|
|
client: client,
|
|
|
|
query: subQuery,
|
|
|
|
variables: { dbid, selectedMetrics, selectedScopes, selectedResolution },
|
2024-08-22 18:33:18 +02:00
|
|
|
// Never user network-only: causes reactive load-loop!
|
2024-08-20 11:39:19 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if ($metricData && !$metricData.fetching) {
|
|
|
|
rawData = $metricData.data.singleUpdate.map((x) => x.metric)
|
|
|
|
scopes = $metricData.data.singleUpdate.map((x) => x.scope)
|
2024-08-23 13:26:56 +02:00
|
|
|
statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null)
|
2024-08-20 11:39:19 +02:00
|
|
|
|
2024-09-02 18:22:34 +02:00
|
|
|
// Keep Zoomlevel if ResChange By Zoom
|
|
|
|
if (pendingZoomState) {
|
|
|
|
zoomState = {...pendingZoomState}
|
|
|
|
}
|
|
|
|
|
2024-08-20 11:51:38 +02:00
|
|
|
// Set selected scope to min of returned scopes
|
2024-08-20 11:39:19 +02:00
|
|
|
if (selectedScope == "load-all") {
|
|
|
|
selectedScope = minScope(scopes)
|
2024-08-23 13:53:15 +02:00
|
|
|
nodeOnly = (selectedScope == "node") // "node" still only scope after load-all
|
2024-08-20 11:39:19 +02:00
|
|
|
}
|
|
|
|
|
2024-08-23 13:26:56 +02:00
|
|
|
const statsTableData = $metricData.data.singleUpdate.filter((x) => x.scope !== "node")
|
|
|
|
if (statsTableData.length > 0) {
|
|
|
|
dispatch("more-loaded", statsTableData);
|
|
|
|
}
|
|
|
|
|
2024-08-20 11:39:19 +02:00
|
|
|
patternMatches = statsPattern.exec(selectedScope)
|
2024-08-20 11:51:38 +02:00
|
|
|
|
2024-08-20 11:39:19 +02:00
|
|
|
if (!patternMatches) {
|
|
|
|
selectedScopeIndex = scopes.findIndex((s) => s == selectedScope);
|
|
|
|
} else {
|
|
|
|
selectedScopeIndex = scopes.findIndex((s) => s == patternMatches[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
$: data = rawData[selectedScopeIndex];
|
2024-08-23 13:53:15 +02:00
|
|
|
$: series = data?.series?.filter(
|
2024-03-09 10:30:40 +01:00
|
|
|
(series) => selectedHost == null || series.hostname == selectedHost,
|
|
|
|
);
|
2022-06-22 11:20:57 +02:00
|
|
|
</script>
|
2024-03-09 10:30:40 +01:00
|
|
|
|
2024-10-02 17:48:46 +02:00
|
|
|
<InputGroup class="mt-2">
|
2024-03-09 10:30:40 +01:00
|
|
|
<InputGroupText style="min-width: 150px;">
|
2024-07-22 15:41:33 +02:00
|
|
|
{metricName} ({unit})
|
2024-03-09 10:30:40 +01:00
|
|
|
</InputGroupText>
|
|
|
|
<select class="form-select" bind:value={selectedScope}>
|
2024-08-16 14:50:31 +02:00
|
|
|
{#each scopes as scope, index}
|
2024-03-09 10:30:40 +01:00
|
|
|
<option value={scope}>{scope}</option>
|
2024-05-02 16:32:01 +02:00
|
|
|
{#if statsSeries[index]}
|
2024-05-08 16:17:42 +02:00
|
|
|
<option value={scope + '-stat'}>stats series ({scope})</option>
|
2024-05-02 16:32:01 +02:00
|
|
|
{/if}
|
2024-03-09 10:30:40 +01:00
|
|
|
{/each}
|
2024-08-23 13:53:15 +02:00
|
|
|
{#if scopes.length == 1 && nativeScope != "node" && !nodeOnly}
|
2024-07-22 15:41:33 +02:00
|
|
|
<option value={"load-all"}>Load all...</option>
|
2022-06-22 11:20:57 +02:00
|
|
|
{/if}
|
2024-03-09 10:30:40 +01:00
|
|
|
</select>
|
|
|
|
{#if job.resources.length > 1}
|
2024-05-02 16:32:01 +02:00
|
|
|
<select class="form-select" bind:value={selectedHost} disabled={patternMatches}>
|
2024-03-09 10:30:40 +01:00
|
|
|
<option value={null}>All Hosts</option>
|
|
|
|
{#each job.resources as { hostname }}
|
|
|
|
<option value={hostname}>{hostname}</option>
|
|
|
|
{/each}
|
|
|
|
</select>
|
|
|
|
{/if}
|
2022-06-22 11:20:57 +02:00
|
|
|
</InputGroup>
|
|
|
|
{#key series}
|
2024-08-16 14:50:31 +02:00
|
|
|
{#if $metricData?.fetching == true}
|
2024-03-09 10:30:40 +01:00
|
|
|
<Spinner />
|
|
|
|
{:else if error != null}
|
|
|
|
<Card body color="danger">{error.message}</Card>
|
2024-05-02 16:32:01 +02:00
|
|
|
{:else if series != null && !patternMatches}
|
|
|
|
<Timeseries
|
2024-09-02 18:22:34 +02:00
|
|
|
on:zoom={({detail}) => { handleZoom(detail) }}
|
2024-07-22 15:41:33 +02:00
|
|
|
cluster={job.cluster}
|
|
|
|
subCluster={job.subCluster}
|
2024-05-02 16:32:01 +02:00
|
|
|
timestep={data.timestep}
|
|
|
|
scope={selectedScope}
|
|
|
|
metric={metricName}
|
|
|
|
{series}
|
|
|
|
{isShared}
|
2024-09-02 18:22:34 +02:00
|
|
|
{zoomState}
|
2024-05-02 16:32:01 +02:00
|
|
|
/>
|
|
|
|
{:else if statsSeries[selectedScopeIndex] != null && patternMatches}
|
2024-03-09 10:30:40 +01:00
|
|
|
<Timeseries
|
2024-09-02 18:22:34 +02:00
|
|
|
on:zoom={({detail}) => { handleZoom(detail) }}
|
2024-07-22 15:41:33 +02:00
|
|
|
cluster={job.cluster}
|
|
|
|
subCluster={job.subCluster}
|
2024-03-09 10:30:40 +01:00
|
|
|
timestep={data.timestep}
|
|
|
|
scope={selectedScope}
|
|
|
|
metric={metricName}
|
|
|
|
{series}
|
|
|
|
{isShared}
|
2024-09-02 18:22:34 +02:00
|
|
|
{zoomState}
|
2024-05-02 16:32:01 +02:00
|
|
|
statisticsSeries={statsSeries[selectedScopeIndex]}
|
|
|
|
useStatsSeries={!!statsSeries[selectedScopeIndex]}
|
2024-03-09 10:30:40 +01:00
|
|
|
/>
|
|
|
|
{/if}
|
2022-06-22 11:20:57 +02:00
|
|
|
{/key}
|