-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add job metrics per invocation #19048
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e5b300b
Add job metrics per invocation
mvdbeek bcf212d
Add basic boxplot
mvdbeek 6b94267
Enable grouping by workflow step
mvdbeek 39a7ed2
Decrease value parsing repetition, add peakMemory
mvdbeek b1691c5
Rerender on resize
mvdbeek 946d2ff
split vega related components into lazy loaded bundle
ElectronicBlueberry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is only needed in a few places, and quite a large package, could we load this on demand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose if you ask then it is possible 😃 ? I don't know how to do that though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can push a commit if you like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To explain what's happening here, to anyone curious:
import { type ...}
toimport type { ... }
. These are not equivalent. The second one let's typescript completely remove the import line, while the first keeps an empty import, in case of import side effects. This would break on demand loadingconst VegaWrapper = () => import("./VegaWrapper.vue");
. This is a way to lazy load vue components and all it's related code (the vega library in this case). The component can be used like before