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
|
|
|
|
- `width Number`: Nested plot width
|
|
|
|
- `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-16 14:50:31 +02:00
|
|
|
import {
|
|
|
|
queryStore,
|
|
|
|
gql,
|
|
|
|
getContextClient
|
|
|
|
} from "@urql/svelte";
|
|
|
|
// import { createEventDispatcher } from "svelte";
|
2024-03-09 10:30:40 +01:00
|
|
|
import {
|
|
|
|
InputGroup,
|
|
|
|
InputGroupText,
|
|
|
|
Spinner,
|
|
|
|
Card,
|
|
|
|
} from "@sveltestrap/sveltestrap";
|
2024-08-16 16:35:17 +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 width;
|
|
|
|
export let rawData;
|
|
|
|
export let isShared = false;
|
2022-06-22 11:20:57 +02:00
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
let selectedHost = null,
|
|
|
|
plot,
|
|
|
|
error = null;
|
|
|
|
let selectedScope = minScope(scopes);
|
2024-08-20 11:39:19 +02:00
|
|
|
let selectedResolution;
|
|
|
|
let pendingResolution = 600;
|
|
|
|
let selectedScopeIndex = scopes.findIndex((s) => s == minScope(scopes));
|
|
|
|
const statsPattern = /(.*)-stat$/;
|
|
|
|
let patternMatches = false;
|
|
|
|
let statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null);
|
2024-05-02 16:32:01 +02:00
|
|
|
|
2024-08-16 14:50:31 +02:00
|
|
|
// const dispatch = createEventDispatcher();
|
2024-08-20 11:39:19 +02:00
|
|
|
const unit = (metricUnit?.prefix ? metricUnit.prefix : "") + (metricUnit?.base ? metricUnit.base : "");
|
|
|
|
const resolutions = [600, 240, 60] // DEV: Make configable
|
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
|
|
|
|
median
|
|
|
|
max
|
|
|
|
}
|
|
|
|
series {
|
|
|
|
hostname
|
|
|
|
id
|
|
|
|
data
|
|
|
|
statistics {
|
|
|
|
min
|
|
|
|
avg
|
|
|
|
max
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
|
|
|
let metricData;
|
|
|
|
let selectedScopes = [...scopes]
|
|
|
|
const dbid = job.id;
|
|
|
|
const selectedMetrics = [metricName]
|
|
|
|
|
2024-08-20 11:39:19 +02:00
|
|
|
$: if (selectedScope == "load-all" || pendingResolution) {
|
|
|
|
|
|
|
|
if (selectedScope == "load-all") {
|
|
|
|
console.log('Triggered load-all')
|
|
|
|
selectedScopes = [...scopes, "socket", "core"]
|
2024-05-02 16:32:01 +02:00
|
|
|
} else {
|
2024-08-20 11:39:19 +02:00
|
|
|
console.log("Triggered scope switch:", selectedScope, pendingResolution)
|
2024-05-02 16:32:01 +02:00
|
|
|
}
|
2024-08-20 11:39:19 +02:00
|
|
|
|
|
|
|
// What if accelerator scope / native core scopes?
|
|
|
|
if ((selectedResolution !== pendingResolution) && selectedScopes.length >= 2) {
|
|
|
|
selectedScope = String("node")
|
|
|
|
selectedScopes = ["node"]
|
|
|
|
console.log("New Resolution: Reset to node scope")
|
|
|
|
} else {
|
|
|
|
console.log("New Resolution: No change in Res or just node scope")
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!selectedResolution) {
|
|
|
|
selectedResolution = Number(pendingResolution)
|
|
|
|
} else {
|
|
|
|
selectedResolution = Number(pendingResolution)
|
|
|
|
|
|
|
|
metricData = queryStore({
|
|
|
|
client: client,
|
|
|
|
query: subQuery,
|
|
|
|
variables: { dbid, selectedMetrics, selectedScopes, selectedResolution },
|
|
|
|
// requestPolicy: "network-only",
|
|
|
|
});
|
|
|
|
|
|
|
|
if ($metricData && !$metricData.fetching) {
|
|
|
|
console.log('Trigger Data Handling')
|
|
|
|
|
|
|
|
rawData = $metricData.data.singleUpdate.map((x) => x.metric)
|
|
|
|
scopes = $metricData.data.singleUpdate.map((x) => x.scope)
|
|
|
|
statsSeries = rawData.map((data) => data?.statisticsSeries ? data.statisticsSeries : null)
|
|
|
|
|
|
|
|
// Handle Selected Scope on load-all
|
|
|
|
if (selectedScope == "load-all") {
|
|
|
|
selectedScope = minScope(scopes)
|
|
|
|
console.log('Set New SelectedScope after Load-All', selectedScope, scopes)
|
|
|
|
} else {
|
|
|
|
console.log('Set New SelectedScope', selectedScope)
|
|
|
|
}
|
|
|
|
|
|
|
|
patternMatches = statsPattern.exec(selectedScope)
|
|
|
|
if (!patternMatches) {
|
|
|
|
selectedScopeIndex = scopes.findIndex((s) => s == selectedScope);
|
|
|
|
console.log("Selected Index # from Array", selectedScopeIndex, scopes)
|
|
|
|
} else {
|
|
|
|
selectedScopeIndex = scopes.findIndex((s) => s == patternMatches[1]);
|
|
|
|
console.log("Selected Stats Index # from Array", selectedScopeIndex, scopes)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
$: data = rawData[selectedScopeIndex];
|
2024-08-20 11:39:19 +02:00
|
|
|
|
2024-03-09 10:30:40 +01:00
|
|
|
$: series = data?.series.filter(
|
|
|
|
(series) => selectedHost == null || series.hostname == selectedHost,
|
|
|
|
);
|
2022-06-22 11:20:57 +02:00
|
|
|
</script>
|
2024-03-09 10:30:40 +01:00
|
|
|
|
2022-06-22 11:20:57 +02:00
|
|
|
<InputGroup>
|
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-16 14:50:31 +02:00
|
|
|
{#if scopes.length == 1 && nativeScope != "node"}
|
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}
|
2024-08-20 11:39:19 +02:00
|
|
|
<select class="form-select" bind:value={pendingResolution}>
|
2024-08-08 12:28:36 +02:00
|
|
|
{#each resolutions as res}
|
|
|
|
<option value={res}>Timestep: {res}</option>
|
|
|
|
{/each}
|
|
|
|
</select>
|
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
|
|
|
|
bind:this={plot}
|
|
|
|
{width}
|
|
|
|
height={300}
|
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}
|
|
|
|
resources={job.resources}
|
|
|
|
/>
|
|
|
|
{:else if statsSeries[selectedScopeIndex] != null && patternMatches}
|
2024-03-09 10:30:40 +01:00
|
|
|
<Timeseries
|
|
|
|
bind:this={plot}
|
|
|
|
{width}
|
|
|
|
height={300}
|
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}
|
|
|
|
resources={job.resources}
|
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}
|