Skip to content

Commit edb9c07

Browse files
authored
Merge pull request #2263 from Jamesbarford/fix/collector-ui
Fix; collector offline status
2 parents ae6803a + 33704e2 commit edb9c07

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

site/frontend/src/pages/status_new/collector.vue

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
<script setup lang="ts">
2-
import {ref, Ref} from "vue";
1+
<script setup lang="tsx">
2+
import {h, ref, Ref} from "vue";
3+
import {parseISO, differenceInHours} from "date-fns";
34
import {formatISODate} from "../../utils/formatting";
45
import {CollectorConfig, BenchmarkJobStatus} from "./data";
56
67
const props = defineProps<{
78
collector: CollectorConfig;
89
}>();
910
10-
function statusClass(c: CollectorConfig): string {
11-
return c.isActive ? "active" : "inactive";
12-
}
13-
1411
const FILTERS: BenchmarkJobStatus[] = [
1512
"InProgress",
1613
"Queued",
@@ -40,6 +37,37 @@ function formatJobStatus(status: BenchmarkJobStatus): string {
4037
return "Unknown";
4138
}
4239
}
40+
41+
function ActiveStatus({collector}: {collector: CollectorConfig}) {
42+
const now = new Date();
43+
const maxInactivityHours = 1;
44+
const lastHeartBeatAt = parseISO(collector.lastHeartbeatAt);
45+
const hourDiff = differenceInHours(now, lastHeartBeatAt);
46+
let statusText = "Active";
47+
let statusClass = "active";
48+
49+
switch (collector.isActive) {
50+
case false:
51+
if (hourDiff >= maxInactivityHours) {
52+
statusText = "Offline";
53+
statusClass = "offline";
54+
} else {
55+
statusText = "Active";
56+
statusClass = "active";
57+
}
58+
break;
59+
case true:
60+
statusText = "Inactive";
61+
statusClass = "inactive";
62+
break;
63+
}
64+
65+
return (
66+
<span class={`collector-sm-padding-left-right status ${statusClass}`}>
67+
{statusText}
68+
</span>
69+
);
70+
}
4371
</script>
4472

4573
<template>
@@ -54,12 +82,7 @@ function formatJobStatus(status: BenchmarkJobStatus): string {
5482
class="collector-sm-padding-left-right collector-left-divider"
5583
>{{ collector.target }}</span
5684
>
57-
<span
58-
class="collector-sm-padding-left-right status"
59-
:class="statusClass(collector)"
60-
>
61-
{{ collector.isActive ? "Active" : "Inactive" }}
62-
</span>
85+
<ActiveStatus :collector="collector" />
6386
</span>
6487
</div>
6588
</div>
@@ -235,6 +258,11 @@ $sm-radius: 8px;
235258
font-weight: bold;
236259
}
237260
.status.inactive {
261+
background: #ccc;
262+
color: white;
263+
font-weight: bold;
264+
}
265+
.status.offline {
238266
background: red;
239267
color: white;
240268
font-weight: bold;

0 commit comments

Comments
 (0)