-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19048 from mvdbeek/invocation_metrics_api
Add job metrics per invocation
- Loading branch information
Showing
12 changed files
with
951 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
client/src/components/WorkflowInvocationState/VegaWrapper.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<template> | ||
<div ref="chartContainer" class="chart"></div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { useResizeObserver } from "@vueuse/core"; | ||
import embed, { type VisualizationSpec } from "vega-embed"; | ||
import { onBeforeUnmount, onMounted, ref, watch } from "vue"; | ||
export interface VisSpec { | ||
spec: VisualizationSpec; | ||
} | ||
const props = defineProps<VisSpec>(); | ||
const chartContainer = ref<HTMLDivElement | null>(null); | ||
let vegaView: any; | ||
async function embedChart() { | ||
if (vegaView) { | ||
vegaView.finalize(); | ||
} | ||
if (chartContainer.value !== null) { | ||
const result = await embed(chartContainer.value, props.spec, { renderer: "svg" }); | ||
vegaView = result.view; | ||
} | ||
} | ||
onMounted(embedChart); | ||
watch(props, embedChart, { immediate: true, deep: true }); | ||
useResizeObserver(chartContainer, () => { | ||
embedChart(); | ||
}); | ||
// Cleanup the chart when the component is unmounted | ||
onBeforeUnmount(() => { | ||
if (vegaView) { | ||
vegaView.finalize(); | ||
} | ||
}); | ||
</script> | ||
|
||
<style scoped> | ||
.chart { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
</style> |
178 changes: 178 additions & 0 deletions
178
client/src/components/WorkflowInvocationState/WorkflowInvocationMetrics.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
<script setup lang="ts"> | ||
import type { VisualizationSpec } from "vega-embed"; | ||
import { computed, ref, watch } from "vue"; | ||
import { type ComputedRef } from "vue"; | ||
import { type components, GalaxyApi } from "@/api"; | ||
import { errorMessageAsString } from "@/utils/simple-error"; | ||
const VegaWrapper = () => import("./VegaWrapper.vue"); | ||
const props = defineProps({ | ||
invocationId: { | ||
type: String, | ||
required: true, | ||
}, | ||
}); | ||
const groupBy = ref<"tool_id" | "step_id">("tool_id"); | ||
const jobMetrics = ref<components["schemas"]["WorkflowJobMetric"][]>(); | ||
const fetchError = ref<string>(); | ||
const attributeToLabel = { | ||
tool_id: "Tool ID", | ||
step_id: "Step", | ||
}; | ||
async function fetchMetrics() { | ||
const { data, error } = await GalaxyApi().GET("/api/invocations/{invocation_id}/metrics", { | ||
params: { | ||
path: { | ||
invocation_id: props.invocationId, | ||
}, | ||
}, | ||
}); | ||
if (error) { | ||
fetchError.value = errorMessageAsString(error); | ||
} else { | ||
jobMetrics.value = data; | ||
} | ||
} | ||
watch(props, () => fetchMetrics(), { immediate: true }); | ||
function itemToX(item: components["schemas"]["WorkflowJobMetric"]) { | ||
if (groupBy.value === "tool_id") { | ||
return item.tool_id; | ||
} else if (groupBy.value === "step_id") { | ||
return `${item.step_index + 1}: ${item.step_label || item.tool_id}`; | ||
} else { | ||
throw Error("Cannot happen"); | ||
} | ||
} | ||
interface boxplotData { | ||
x_title: string; | ||
y_title: string; | ||
values?: { x: string; y: Number }[]; | ||
} | ||
function metricToSpecData( | ||
jobMetrics: components["schemas"]["WorkflowJobMetric"][] | undefined, | ||
metricName: string, | ||
yTitle: string, | ||
transform?: (param: number) => number | ||
) { | ||
const wallclock = jobMetrics?.filter((jobMetric) => jobMetric.name == metricName); | ||
const values = wallclock?.map((item) => { | ||
let y = parseFloat(item.raw_value); | ||
if (transform !== undefined) { | ||
y = transform(y); | ||
} | ||
return { | ||
y, | ||
x: itemToX(item), | ||
}; | ||
}); | ||
return { | ||
x_title: attributeToLabel[groupBy.value], | ||
y_title: yTitle, | ||
values, | ||
}; | ||
} | ||
const wallclock: ComputedRef<boxplotData> = computed(() => { | ||
return metricToSpecData(jobMetrics.value, "runtime_seconds", "Runtime (in Seconds)"); | ||
}); | ||
const coresAllocated: ComputedRef<boxplotData> = computed(() => { | ||
return metricToSpecData(jobMetrics.value, "galaxy_slots", "Cores Allocated"); | ||
}); | ||
const memoryAllocated: ComputedRef<boxplotData> = computed(() => { | ||
return metricToSpecData(jobMetrics.value, "galaxy_memory_mb", "Memory Allocated (in MB)"); | ||
}); | ||
const peakMemory: ComputedRef<boxplotData> = computed(() => { | ||
return metricToSpecData(jobMetrics.value, "memory.peak", "Max memory usage recorded (in MB)", (v) => v / 1024 ** 2); | ||
}); | ||
function itemToSpec(item: boxplotData) { | ||
const spec: VisualizationSpec = { | ||
$schema: "https://vega.github.io/schema/vega-lite/v5.json", | ||
description: "A boxplot with jittered points.", | ||
data: { | ||
values: item.values!, | ||
}, | ||
transform: [ | ||
{ | ||
calculate: "random() - 0.5", | ||
as: "random_jitter", | ||
}, | ||
], | ||
layer: [ | ||
{ | ||
mark: { type: "boxplot", opacity: 0.5 }, | ||
encoding: { | ||
x: { field: "x", type: "nominal" }, | ||
y: { field: "y", type: "quantitative" }, | ||
}, | ||
width: "container", | ||
}, | ||
{ | ||
mark: { | ||
type: "point", | ||
opacity: 0.7, | ||
}, | ||
encoding: { | ||
x: { | ||
field: "x", | ||
type: "nominal", | ||
title: item.x_title, | ||
axis: { | ||
labelAngle: -45, | ||
labelAlign: "right", | ||
}, | ||
}, | ||
xOffset: { field: "random_jitter", type: "quantitative", scale: { domain: [-2, 2] } }, | ||
y: { | ||
field: "y", | ||
type: "quantitative", | ||
scale: { zero: false }, | ||
title: item.y_title, | ||
}, | ||
}, | ||
width: "container", | ||
}, | ||
], | ||
}; | ||
return spec; | ||
} | ||
const specs = computed(() => { | ||
const items = [wallclock.value, coresAllocated.value, memoryAllocated.value, peakMemory.value].filter( | ||
(item) => item.values?.length | ||
); | ||
const specs = Object.fromEntries(items.map((item) => [item.y_title, itemToSpec(item)])); | ||
return specs; | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div> | ||
<b-tabs lazy> | ||
<b-tab title="Summary by Tool" @click="groupBy = 'tool_id'"> | ||
<div v-for="(spec, key) in specs" :key="key"> | ||
<h2 class="h-l truncate text-center">{{ key }}</h2> | ||
<VegaWrapper :spec="spec" /> | ||
</div> | ||
</b-tab> | ||
<b-tab title="Summary by Workflow Step" @click="groupBy = 'step_id'"> | ||
<div v-for="(spec, key) in specs" :key="key"> | ||
<h2 class="h-l truncate text-center">{{ key }}</h2> | ||
<VegaWrapper :spec="spec" /> | ||
</div> | ||
</b-tab> | ||
</b-tabs> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.