Skip to content

Commit d3e88d9

Browse files
authored
[Ballista] Add executor last seen info to the ui (#895)
1 parent e4b0a7e commit d3e88d9

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

ballista/rust/scheduler/src/api/handlers.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,40 @@
1111
// limitations under the License.
1212

1313
use crate::SchedulerServer;
14-
use ballista_core::{serde::scheduler::ExecutorMeta, BALLISTA_VERSION};
14+
use ballista_core::BALLISTA_VERSION;
1515
use warp::Rejection;
1616

1717
#[derive(Debug, serde::Serialize)]
1818
struct StateResponse {
19-
executors: Vec<ExecutorMeta>,
19+
executors: Vec<ExecutorMetaResponse>,
2020
started: u128,
2121
version: &'static str,
2222
}
2323

24+
#[derive(Debug, serde::Serialize)]
25+
pub struct ExecutorMetaResponse {
26+
pub id: String,
27+
pub host: String,
28+
pub port: u16,
29+
pub last_seen: u128,
30+
}
31+
2432
pub(crate) async fn scheduler_state(
2533
data_server: SchedulerServer,
2634
) -> Result<impl warp::Reply, Rejection> {
2735
// TODO: Display last seen information in UI
28-
let executors: Vec<ExecutorMeta> = data_server
36+
let executors: Vec<ExecutorMetaResponse> = data_server
2937
.state
3038
.get_executors_metadata()
3139
.await
3240
.unwrap_or_default()
3341
.into_iter()
34-
.map(|(metadata, _duration)| metadata)
42+
.map(|(metadata, duration)| ExecutorMetaResponse {
43+
id: metadata.id,
44+
host: metadata.host,
45+
port: metadata.port,
46+
last_seen: duration.as_millis(),
47+
})
3548
.collect();
3649
let response = StateResponse {
3750
executors,

ballista/ui/scheduler/src/components/DataTable.tsx

+19
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,25 @@ interface DataTableProps {
6060
maxW?: number;
6161
pb?: number;
6262
}
63+
64+
export const ElapsedCell: (props: any) => React.ReactNode = (props: any) => {
65+
const time = new Date(new Date().getTime() - props.value);
66+
return (
67+
<TimeAgo
68+
date={time}
69+
formatter={(
70+
value: number,
71+
unit: TimeAgo.Unit,
72+
suffix: TimeAgo.Suffix
73+
) => {
74+
if (unit === "second") return "just now";
75+
const plural: string = value !== 1 ? "s" : "";
76+
return `${value} ${unit}${plural} ${suffix}`;
77+
}}
78+
/>
79+
);
80+
};
81+
6382
export const DateCell: (props: any) => React.ReactNode = (props: any) => {
6483
return (
6584
<TimeAgo

ballista/ui/scheduler/src/components/NodesList.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
import React from "react";
1919
import { Box } from "@chakra-ui/react";
20-
import { Column, DateCell, DataTable } from "./DataTable";
20+
import { Column, ElapsedCell, DataTable } from "./DataTable";
2121

2222
export enum NodeStatus {
2323
RUNNING = "RUNNING",
@@ -50,9 +50,9 @@ const columns: Column<any>[] = [
5050
accessor: "status",
5151
},
5252
{
53-
Header: "Started",
54-
accessor: "started",
55-
Cell: DateCell,
53+
Header: "Last Seen",
54+
accessor: "last_seen",
55+
Cell: ElapsedCell,
5656
},
5757
];
5858

0 commit comments

Comments
 (0)