forked from marin-community/marin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskDetail.vue
More file actions
464 lines (425 loc) · 18 KB
/
TaskDetail.vue
File metadata and controls
464 lines (425 loc) · 18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<script setup lang="ts">
import { ref, computed, onMounted, watch } from 'vue'
import { RouterLink, useRouter } from 'vue-router'
import { useControllerRpc } from '@/composables/useRpc'
import { useAutoRefresh } from '@/composables/useAutoRefresh'
import { stateToName } from '@/types/status'
import type {
TaskStatus,
TaskStatsSnapshot,
GetTaskStatusResponse,
} from '@/types/rpc'
import { timestampMs, formatBytes, formatRate, formatCpuMillicores, formatDuration, formatRelativeTime } from '@/utils/formatting'
import { controllerRpcCall } from '@/composables/useRpc'
import { useProfileAction } from '@/composables/useProfileAction'
import PageShell from '@/components/layout/PageShell.vue'
import StatusBadge from '@/components/shared/StatusBadge.vue'
import InfoCard from '@/components/shared/InfoCard.vue'
import InfoRow from '@/components/shared/InfoRow.vue'
import ResourceGauge from '@/components/shared/ResourceGauge.vue'
import Sparkline from '@/components/shared/Sparkline.vue'
import ProfileButtons from '@/components/shared/ProfileButtons.vue'
import LogViewer from '@/components/shared/LogViewer.vue'
const props = defineProps<{
jobId: string
taskId: string
}>()
const {
data: taskResponse,
loading,
error,
refresh: fetchTask,
} = useControllerRpc<GetTaskStatusResponse>('GetTaskStatus', () => ({ taskId: props.taskId }))
const task = computed(() => taskResponse.value?.task ?? null)
const jobResources = computed(() => taskResponse.value?.jobResources ?? null)
const normalizedState = computed(() => (task.value ? stateToName(task.value.state) : ''))
const isActive = computed(() => {
const s = normalizedState.value
return s === 'running' || s === 'building' || s === 'assigned'
})
const startedMs = computed(() => timestampMs(task.value?.startedAt))
const finishedMs = computed(() => timestampMs(task.value?.finishedAt))
const duration = computed(() => {
if (!startedMs.value) return '-'
return formatDuration(startedMs.value, finishedMs.value || undefined)
})
const startedDisplay = computed(() =>
startedMs.value ? formatRelativeTime(startedMs.value) : '-'
)
// Resource gauge values from resourceUsage (MB -> bytes for the gauge)
const cpuUsed = computed(() => (task.value?.resourceUsage?.cpuMillicores ?? 0) / 1000)
const memUsedMb = computed(() => {
const raw = task.value?.resourceUsage?.memoryMb
return raw ? parseFloat(raw) : 0
})
const memPeakMb = computed(() => {
const raw = task.value?.resourceUsage?.memoryPeakMb
return raw ? parseFloat(raw) : 0
})
const diskUsedMb = computed(() => {
const raw = task.value?.resourceUsage?.diskMb
return raw ? parseFloat(raw) : 0
})
const cpuHistory = computed(() =>
(task.value?.resourceHistory ?? []).map(r => (r.cpuMillicores ?? 0) / 1000)
)
const memHistory = computed(() =>
(task.value?.resourceHistory ?? []).map(r => r.memoryMb ? parseFloat(r.memoryMb) : 0)
)
const statsHistory = computed(() => task.value?.taskStatsHistory ?? [])
const latestStats = computed(() => statsHistory.value[statsHistory.value.length - 1] ?? null)
// Compute per-second throughput from cumulative deltas, then smooth with a
// 5-point centred moving average to reduce reporting-interval spikes.
function throughputSeries(field: 'itemsProcessed' | 'bytesProcessed'): number[] {
const snaps = statsHistory.value
if (snaps.length < 2) return []
const raw: number[] = []
for (let i = 1; i < snaps.length; i++) {
const prev = snaps[i - 1]
const curr = snaps[i]
const dtMs = parseFloat(curr.timestampMs ?? '0') - parseFloat(prev.timestampMs ?? '0')
if (dtMs <= 0) continue
const dv = parseFloat(curr[field] ?? '0') - parseFloat(prev[field] ?? '0')
raw.push(Math.max(0, dv / (dtMs / 1000)))
}
const window = 5
return raw.map((_, i) => {
const lo = Math.max(0, i - Math.floor(window / 2))
const hi = Math.min(raw.length, lo + window)
const slice = raw.slice(lo, hi)
return slice.reduce((a, b) => a + b, 0) / slice.length
})
}
const itemsThroughput = computed(() => throughputSeries('itemsProcessed'))
const bytesThroughput = computed(() => throughputSeries('bytesProcessed'))
const itemsThroughputMax = computed(() => {
const m = Math.max(...itemsThroughput.value, 0)
return m > 0 ? m.toFixed(1) + '/s' : '0/s'
})
const bytesThroughputMax = computed(() => {
const m = Math.max(...bytesThroughput.value, 0)
return m > 0 ? formatRate(m) : '0 B/s'
})
// Use job-level resource limits for gauge totals when available.
const cpuTotal = computed(() => {
const jobCpu = (jobResources.value?.cpuMillicores ?? 0) / 1000
if (jobCpu > 0) return jobCpu
const maxObserved = Math.max(...cpuHistory.value, cpuUsed.value, 0)
if (maxObserved <= 0) return 1
return Math.max(1, maxObserved * 1.5)
})
const memTotalMb = computed(() => {
const jobMemBytes = jobResources.value?.memoryBytes
if (jobMemBytes) return parseFloat(jobMemBytes) / (1024 * 1024)
const historyMax = memHistory.value.length > 0 ? Math.max(...memHistory.value) : 0
const best = Math.max(historyMax, memPeakMb.value, memUsedMb.value)
if (best <= 0) return 1
return best * 1.2
})
const diskTotalMb = computed(() => {
const jobDiskBytes = jobResources.value?.diskBytes
if (jobDiskBytes) return parseFloat(jobDiskBytes) / (1024 * 1024)
if (diskUsedMb.value <= 0) return 1
return diskUsedMb.value * 2
})
// Build metrics
const buildDuration = computed(() => {
const bm = task.value?.buildMetrics
if (!bm?.buildStarted || !bm?.buildFinished) return null
return formatDuration(timestampMs(bm.buildStarted), timestampMs(bm.buildFinished))
})
// Auto-refresh while task is active
const { active: autoRefreshActive, start: startRefresh, stop: stopRefresh } = useAutoRefresh(
fetchTask,
5_000,
false,
)
watch(isActive, (active) => {
if (active) startRefresh()
else stopRefresh()
})
onMounted(async () => {
await fetchTask()
if (isActive.value) startRefresh()
})
const router = useRouter()
const { profiling, profile } = useProfileAction(controllerRpcCall, () => props.taskId)
function handleProfile(type: 'cpu' | 'memory' | 'threads') {
if (type === 'threads') {
router.push(`/job/${encodeURIComponent(props.jobId)}/task/${encodeURIComponent(props.taskId)}/threads`)
} else {
profile(type)
}
}
const logViewerRef = ref<{ selectedAttemptId: number } | null>(null)
function selectAttempt(attemptId: number) {
if (logViewerRef.value) {
logViewerRef.value.selectedAttemptId = attemptId
}
const logsEl = document.getElementById('task-logs-section')
if (logsEl) logsEl.scrollIntoView({ behavior: 'smooth' })
}
// Re-fetch when navigating between tasks (Vue Router reuses the component).
// Clear stale data first so loading/error states render correctly if the fetch fails.
watch(() => props.taskId, async () => {
taskResponse.value = null
stopRefresh()
await fetchTask()
if (isActive.value) startRefresh()
})
</script>
<template>
<PageShell
:title="`Task ${taskId}`"
:back-to="`/job/${jobId}`"
back-label="Back to Job"
>
<!-- Loading -->
<div
v-if="loading && !task"
class="flex items-center justify-center py-16 text-text-muted text-sm"
>
Loading task...
</div>
<!-- Error -->
<div
v-else-if="error && !task"
class="px-4 py-3 text-sm text-status-danger bg-status-danger-bg rounded-lg border border-status-danger-border"
>
{{ error }}
</div>
<template v-else-if="task">
<!-- Status header cards -->
<div class="grid grid-cols-1 lg:grid-cols-3 gap-4 mb-6">
<!-- Status card -->
<InfoCard title="Status">
<InfoRow label="State">
<StatusBadge :status="task.state" size="sm" />
</InfoRow>
<InfoRow v-if="task.workerId" label="Worker">
<RouterLink
:to="`/worker/${task.workerId}`"
class="font-mono text-accent hover:underline"
>
{{ task.workerId }}
</RouterLink>
</InfoRow>
<InfoRow label="Started">
<span class="font-mono">{{ startedDisplay }}</span>
</InfoRow>
<InfoRow label="Duration">
<span class="font-mono">{{ duration }}</span>
</InfoRow>
<InfoRow v-if="task.currentAttemptId" label="Attempt">
<span class="font-mono">{{ task.currentAttemptId }}</span>
</InfoRow>
<InfoRow v-if="task.exitCode !== undefined" label="Exit Code">
<span
class="font-mono"
:class="task.exitCode === 0 ? 'text-status-success' : 'text-status-danger'"
>
{{ task.exitCode }}
</span>
</InfoRow>
<InfoRow v-if="task.pendingReason" label="Pending Reason">
<span class="text-status-warning">{{ task.pendingReason }}</span>
</InfoRow>
<div v-if="isActive" class="mt-3 pt-3 border-t border-surface-border">
<ProfileButtons :profiling="profiling" @profile="handleProfile" />
</div>
</InfoCard>
<!-- Resources card -->
<InfoCard title="Resources">
<template v-if="task.resourceUsage">
<div class="space-y-3">
<ResourceGauge label="CPU" :used="cpuUsed" :total="cpuTotal" unit="cores" />
<ResourceGauge
label="Memory"
:used="memUsedMb * 1024 * 1024"
:total="memTotalMb * 1024 * 1024"
unit="bytes"
/>
<ResourceGauge
v-if="diskUsedMb > 0"
label="Disk"
:used="diskUsedMb * 1024 * 1024"
:total="diskTotalMb * 1024 * 1024"
unit="bytes"
/>
</div>
<div class="mt-2 text-xs text-text-muted space-y-0.5">
<div v-if="task.resourceUsage.processCount">
Processes: {{ task.resourceUsage.processCount }}
</div>
<div v-if="task.resourceUsage.cpuMillicores">
CPU: {{ formatCpuMillicores(task.resourceUsage.cpuMillicores) }}
</div>
</div>
</template>
<div v-else class="text-sm text-text-muted py-2">No resource data</div>
</InfoCard>
<!-- Build info card -->
<InfoCard title="Build Info">
<template v-if="task.buildMetrics">
<InfoRow label="Image Tag">
<span class="font-mono text-xs break-all">
{{ task.buildMetrics.imageTag ?? '-' }}
</span>
</InfoRow>
<InfoRow v-if="buildDuration" label="Build Time">
<span class="font-mono">{{ buildDuration }}</span>
</InfoRow>
<InfoRow label="From Cache">
<span :class="task.buildMetrics.fromCache ? 'text-status-success' : 'text-text-muted'">
{{ task.buildMetrics.fromCache ? 'Yes' : 'No' }}
</span>
</InfoRow>
</template>
<div v-else class="text-sm text-text-muted py-2">No build data</div>
</InfoCard>
</div>
<!-- Resource sparklines -->
<div v-if="cpuHistory.length > 1" class="grid grid-cols-2 gap-4 mb-6">
<div class="rounded-lg border border-surface-border bg-surface p-3">
<div class="text-xs text-text-secondary mb-2">CPU %</div>
<Sparkline :data="cpuHistory" :width="200" :height="40" fill color="var(--color-accent, #2563eb)" />
<div class="text-xs font-mono text-text-muted mt-1">{{ cpuUsed.toFixed(0) }}%</div>
</div>
<div class="rounded-lg border border-surface-border bg-surface p-3">
<div class="text-xs text-text-secondary mb-2">Memory (MB)</div>
<Sparkline :data="memHistory" :width="200" :height="40" fill color="var(--color-status-purple, #8b5cf6)" />
<div class="text-xs font-mono text-text-muted mt-1">{{ memUsedMb.toFixed(0) }} MB</div>
</div>
</div>
<!-- Task stats -->
<div v-if="statsHistory.length > 0" class="grid grid-cols-2 gap-4 mb-6">
<!-- Left: status text + latest values -->
<div class="rounded-lg border border-surface-border bg-surface p-3 space-y-2">
<div v-if="task.statusMessage" class="text-xs text-text font-mono whitespace-pre-wrap break-all">{{ task.statusMessage }}</div>
<div class="text-xs text-text-muted space-y-1 mt-2">
<div>Items processed: <span class="font-mono text-text">{{ latestStats ? parseInt(latestStats.itemsProcessed ?? '0').toLocaleString() : '—' }}</span></div>
<div>Bytes processed: <span class="font-mono text-text">{{ latestStats ? formatBytes(parseFloat(latestStats.bytesProcessed ?? '0')) : '—' }}</span></div>
</div>
</div>
<!-- Right: throughput charts -->
<div class="space-y-3">
<div class="rounded-lg border border-surface-border bg-surface p-3">
<div class="text-xs text-text-secondary mb-2">Items / sec</div>
<Sparkline
v-if="itemsThroughput.length > 1"
:data="itemsThroughput"
:width="200"
:height="40"
fill
color="var(--color-accent, #2563eb)"
show-y-axis
:y-axis-top-label="itemsThroughputMax"
/>
<div class="text-xs font-mono text-text-muted mt-1">
{{ itemsThroughput.length ? itemsThroughput[itemsThroughput.length - 1].toFixed(1) + ' items/s' : '—' }}
</div>
</div>
<div class="rounded-lg border border-surface-border bg-surface p-3">
<div class="text-xs text-text-secondary mb-2">Bytes / sec</div>
<Sparkline
v-if="bytesThroughput.length > 1"
:data="bytesThroughput"
:width="200"
:height="40"
fill
color="var(--color-status-purple, #8b5cf6)"
show-y-axis
:y-axis-top-label="bytesThroughputMax"
/>
<div class="text-xs font-mono text-text-muted mt-1">
{{ bytesThroughput.length ? formatRate(bytesThroughput[bytesThroughput.length - 1]) : '—' }}
</div>
</div>
</div>
</div>
<!-- Error display -->
<div
v-if="task.error"
class="mb-6 rounded-lg border border-status-danger-border bg-status-danger-bg p-4"
>
<h3 class="text-sm font-semibold text-status-danger mb-2">Error</h3>
<pre class="text-xs font-mono text-status-danger whitespace-pre-wrap break-all">{{ task.error }}</pre>
</div>
<!-- Attempts table -->
<div v-if="task.attempts && task.attempts.length > 0" class="mb-6">
<h3 class="text-sm font-semibold text-text mb-3">
Attempts
<span class="text-text-muted font-normal ml-1">({{ task.attempts.length }})</span>
</h3>
<div class="overflow-x-auto rounded-lg border border-surface-border">
<table class="w-full border-collapse">
<thead>
<tr class="border-b border-surface-border">
<th class="px-3 py-2 text-xs font-semibold uppercase tracking-wider text-text-secondary text-left">
Attempt
</th>
<th class="px-3 py-2 text-xs font-semibold uppercase tracking-wider text-text-secondary text-left">
State
</th>
<th class="px-3 py-2 text-xs font-semibold uppercase tracking-wider text-text-secondary text-left">
Worker
</th>
<th class="px-3 py-2 text-xs font-semibold uppercase tracking-wider text-text-secondary text-left">
Exit Code
</th>
<th class="px-3 py-2 text-xs font-semibold uppercase tracking-wider text-text-secondary text-left">
Duration
</th>
<th class="px-3 py-2 text-xs font-semibold uppercase tracking-wider text-text-secondary text-left">
Error
</th>
</tr>
</thead>
<tbody>
<tr
v-for="attempt in task.attempts"
:key="attempt.attemptId"
class="border-b border-surface-border-subtle hover:bg-surface-raised transition-colors cursor-pointer"
:class="attempt.attemptId === task.currentAttemptId ? 'bg-accent-subtle border-l-2 border-l-accent' : ''"
@click="selectAttempt(attempt.attemptId)"
>
<td class="px-3 py-2 text-[13px] font-mono">
{{ attempt.attemptId }}
<span v-if="attempt.attemptId === task.currentAttemptId" class="ml-1 text-xs text-accent font-semibold">current</span>
</td>
<td class="px-3 py-2 text-[13px]">
<StatusBadge :status="attempt.state" size="sm" />
</td>
<td class="px-3 py-2 text-[13px]">
<RouterLink
v-if="attempt.workerId"
:to="`/worker/${attempt.workerId}`"
class="font-mono text-accent hover:underline"
@click.stop
>
{{ attempt.workerId }}
</RouterLink>
<span v-else class="text-text-muted">-</span>
</td>
<td class="px-3 py-2 text-[13px] font-mono">
{{ attempt.exitCode ?? '-' }}
</td>
<td class="px-3 py-2 text-[13px] font-mono">
{{ formatDuration(timestampMs(attempt.startedAt), timestampMs(attempt.finishedAt) || undefined) }}
</td>
<td class="px-3 py-2 text-[13px] text-status-danger truncate max-w-xs">
{{ attempt.error ?? '-' }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Task logs -->
<div id="task-logs-section" class="mb-6">
<h3 class="text-sm font-semibold text-text mb-3">Logs</h3>
<LogViewer ref="logViewerRef" :task-id="taskId" :attempts="task.attempts" :current-attempt-id="task.currentAttemptId" />
</div>
</template>
</PageShell>
</template>