diff --git a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/index.ts b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/index.ts index 1908e410..a1b8f80f 100644 --- a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/index.ts +++ b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/index.ts @@ -89,12 +89,10 @@ async function gridFor( profile: string, jobId: string, historyConfig: HistoryConfig, - opts: Pick + opts: Pick ): Promise { const tails = await tailf(kind, profile, jobId) - return kind === "status" - ? status(tails, historyConfig, { demo: opts.demo, theme: opts.theme }) - : utilization(kind, tails, historyConfig, opts) + return kind === "status" ? status(tails, historyConfig, opts) : utilization(kind, tails, historyConfig, opts) } /** @return all relevant grid models for `jobId` in `profile` */ @@ -102,7 +100,7 @@ async function allGridsFor( profile: string, jobId: string, historyConfig: HistoryConfig, - opts: Pick + opts: Pick ) { const usesGpus = opts.demo || (await import("../env.js").then((_) => _.usesGpus(profile, jobId))) @@ -126,9 +124,8 @@ async function allGridsFor( } export default async function dashboard(args: Arguments, cmd: "db" | "dashboard") { - const { theme } = args.parsedOptions + const { demo, theme, lines } = args.parsedOptions - const { demo } = args.parsedOptions const scale = args.parsedOptions.s || 1 const jobIdOffset = args.argvNoOptions[args.argvNoOptions.indexOf(cmd) + 2] ? 2 : 1 @@ -147,9 +144,9 @@ export default async function dashboard(args: Arguments, cmd: "db" | "d historyConfig: HistoryConfig ): Promise => { if (kind === "all") { - return allGridsFor(profile, jobId, historyConfig, { demo, theme }) + return allGridsFor(profile, jobId, historyConfig, { demo, theme, lines }) } else if (isSupportedGrid(kind)) { - return gridFor(kind, profile, jobId, historyConfig, { demo, theme }) + return gridFor(kind, profile, jobId, historyConfig, { demo, theme, lines }) } else { return null } diff --git a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/options.ts b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/options.ts index e16cc0fa..dd8d4c22 100644 --- a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/options.ts +++ b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/options.ts @@ -15,14 +15,22 @@ */ type Options = { + /** Run in blinking lights mode */ demo: boolean + + /** Scale up the grid? */ scale: number + + /** Theme to use for worker status */ theme: string - themeDefault: string + + /** Number of lines of log messages to show [default: 8] */ + lines: number } export default Options export const flags = { boolean: ["demo"], + alias: { lines: ["l"], theme: ["t"], demo: ["d"], scale: ["s"] }, } diff --git a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/status/Live.ts b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/status/Live.ts index 52f65463..9355b818 100644 --- a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/status/Live.ts +++ b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/status/Live.ts @@ -18,6 +18,7 @@ import Heap from "heap" import stripAnsi from "strip-ansi" import type { TextProps } from "ink" +import type Options from "../options.js" import type { Tail } from "../tailf.js" import type HistoryConfig from "../history.js" import type { WorkerState } from "./states.js" @@ -57,7 +58,8 @@ export default class Live { historyConfig: HistoryConfig, private readonly tails: Promise[], cb: OnData, - styleOf: Record + styleOf: Record, + private readonly opts: Pick ) { tails.map((tailf) => { tailf.then(({ stream }) => { @@ -158,10 +160,14 @@ export default class Live { } } - return this.lines - .toArray() - .slice(0, 6) - .sort((a, b) => a.timestamp - b.timestamp) + if (this.opts.lines === 0) { + return [] + } else { + return this.lines + .toArray() + .slice(0, this.opts.lines || 8) + .sort((a, b) => a.timestamp - b.timestamp) + } } /** `pushLine` and then pass the updated model to `cb` */ diff --git a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/status/index.ts b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/status/index.ts index 1988a5fd..47a577cb 100644 --- a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/status/index.ts +++ b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/status/index.ts @@ -30,9 +30,9 @@ import { isValidStatusTheme, statusThemes } from "./theme.js" export default function statusDashboard( tails: Promise[], historyConfig: HistoryConfig, - opts: Pick & Partial> + opts: Pick ): GridSpec { - const { theme: themeS = opts.themeDefault || "colorbrewer6" } = opts + const { theme: themeS = "colorbrewer6" } = opts if (!isValidStatusTheme(themeS)) { throw new Error("Invalid theme: " + themeS) } @@ -52,7 +52,7 @@ export default function statusDashboard( if (opts.demo) { return new Demo(historyConfig, cb, styleOf) } else { - return new Live(historyConfig, tails, cb, styleOf) + return new Live(historyConfig, tails, cb, styleOf, opts) } } diff --git a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/utilization/index.ts b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/utilization/index.ts index db6e6348..a581c210 100644 --- a/plugins/plugin-codeflare-dashboard/src/controller/dashboard/utilization/index.ts +++ b/plugins/plugin-codeflare-dashboard/src/controller/dashboard/utilization/index.ts @@ -44,9 +44,9 @@ export default function utilizationDashboard( kind: SupportedUtilizationGrid, tails: Promise[], historyConfig: HistoryConfig, - opts: Pick & Partial> + opts: Pick ): GridSpec { - const themeS = opts.themeDefault || defaultUtilizationThemes[kind] + const themeS = defaultUtilizationThemes[kind] if (!isValidTheme(themeS)) { throw new Error("Invalid theme: " + themeS) }