Skip to content

Commit bc9e234

Browse files
committed
feat: change codeflare attach to codeflare dashboard --attach/-a
Also add `codeflare db` as a synonym for `codeflare dashboard`. Also adds `codeflare -q` to start a run in quiet mode -- no logs tee'd to the console.
1 parent a6958f3 commit bc9e234

File tree

7 files changed

+65
-25
lines changed

7 files changed

+65
-25
lines changed

bin/codeflare

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fi
111111
# indicated by the -u option)
112112
do_cli=1
113113
use_docker=0
114-
while getopts "dnVus:" opt
114+
while getopts "qadnVus:" opt
115115
do
116116
case $opt in
117117
d) use_docker=1; continue;;

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/plugin-codeflare/src/controller/attach.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,38 @@
1616

1717
import { dir } from "tmp"
1818
import { cli } from "madwizard/dist/fe/cli"
19+
import { MadWizardOptions } from "madwizard"
1920
import { Arguments, KResponse } from "@kui-shell/core"
2021

2122
export default async function attach(args: Arguments) {
2223
return new Promise<KResponse>((resolve, reject) => {
23-
dir(async (err, logdir) => {
24+
dir({ prefix: "logdir-stage" }, async (err, logdir) => {
2425
if (err) {
2526
reject(err)
2627
}
2728

28-
process.env.LOGDIR_STAGE = logdir
29-
await cli(["codeflare", "guide", "ml/ray/aggregator"], undefined, { store: process.env.GUIDEBOOK_STORE })
30-
resolve(args.REPL.qexec(`codeflare dashboard ${logdir}`))
29+
try {
30+
const options: MadWizardOptions = { store: process.env.GUIDEBOOK_STORE, clean: false }
31+
32+
// TODO: update madwizard to accept env in the options
33+
process.env.LOGDIR_STAGE = logdir // stage log files here
34+
process.env.NO_WAIT = "true" // don't wait for job termination
35+
process.env.QUIET_CONSOLE = "true" // don't tee logs to the console
36+
37+
/* const cleanup = */ await cli(["codeflare", "guide", "ml/ray/aggregator"], undefined, options)
38+
/* if (typeof cleanup === 'function') {
39+
onQuit(cleanup)
40+
} */
41+
42+
await args.REPL.qexec(`codeflare dashboardui -f ${logdir}`)
43+
44+
// TODO: when job completes, auto-exit
45+
46+
resolve(true)
47+
} catch (err) {
48+
console.error(err)
49+
reject(err)
50+
}
3151
})
3252
})
3353
}

plugins/plugin-codeflare/src/controller/dashboard.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { Arguments, CommandOptions, Registrar } from "@kui-shell/core"
17+
import { Arguments, CommandOptions, Registrar, encodeComponent, unparse } from "@kui-shell/core"
1818

1919
import "../../web/scss/components/Dashboard/_index.scss"
2020

@@ -23,22 +23,31 @@ export interface FollowOptions {
2323
follow: boolean
2424
}
2525

26+
type DashboardOptions = FollowOptions & {
27+
a: boolean
28+
attach: boolean
29+
}
30+
2631
export const followFlags: CommandOptions["flags"] = {
27-
boolean: ["f", "follow"],
28-
alias: { follow: ["f"] },
32+
boolean: ["f", "follow", "a", "attach"],
33+
alias: { follow: ["f"], attach: ["a"] },
2934
}
3035

31-
function dashboardcli(args: Arguments) {
36+
function dashboardcli(args: Arguments<DashboardOptions>) {
37+
if (args.parsedOptions.attach) {
38+
// attach to a running job
39+
return import("./attach").then((_) => _.default(args))
40+
}
41+
3242
const filepath = args.argvNoOptions[1]
3343
if (!filepath) {
3444
throw new Error("Usage: codeflare dashboard <filepath>")
3545
}
3646

37-
const restIdx = args.command.indexOf("dashboard") + "dashboard".length
38-
return args.REPL.qexec(`codeflare dashboardui ${args.command.slice(restIdx)}`)
47+
return args.REPL.qexec(`codeflare dashboardui ${encodeComponent(filepath)} ${unparse(args.parsedOptions)}`)
3948
}
4049

41-
async function dashboardui(args: Arguments<FollowOptions>) {
50+
async function dashboardui(args: Arguments<DashboardOptions>) {
4251
const { setTabReadonly } = await import("@kui-shell/plugin-madwizard")
4352
setTabReadonly(args)
4453

@@ -52,8 +61,10 @@ async function dashboardui(args: Arguments<FollowOptions>) {
5261
export default function registerDashboardCommands(registrar: Registrar) {
5362
const flags = followFlags
5463

55-
registrar.listen("/dashboard", dashboardcli, { flags, outputOnly: true })
64+
;["dashboard", "db"].forEach((db) => registrar.listen(`/${db}`, dashboardcli, { flags, outputOnly: true }))
65+
5666
registrar.listen("/codeflare/dashboardui", dashboardui, {
67+
hidden: true,
5768
needsUI: true,
5869
outputOnly: true,
5970
flags,

plugins/plugin-codeflare/src/controller/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@ import description from "./description"
2626
function help() {
2727
return `Usage:
2828
codeflare [run] [<task>] [-s /path/to/store] [-u]
29-
codeflare attach
3029
codeflare dashboard /path/to/logdir
3130
codeflare chart gpu /path/to/logdir`
3231
}
3332

3433
/** Register Kui Commands */
3534
export default function registerCodeflareCommands(registrar: Registrar) {
3635
tailf(registrar)
37-
registrar.listen("/attach", (args) => import("./attach").then((_) => _.default(args)))
3836
browse(registrar)
3937
charts(registrar)
4038
events(registrar)

plugins/plugin-madwizard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
"access": "public"
2424
},
2525
"dependencies": {
26-
"madwizard": "^0.11.0"
26+
"madwizard": "^0.12.0"
2727
}
2828
}

plugins/plugin-madwizard/src/plugin.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ interface Options extends ParsedOptions {
2525

2626
/** do not load prior choices (the default "profile") */
2727
n: boolean
28+
29+
/** Do not tee logs to the console */
30+
q: boolean
31+
quiet: boolean
2832
}
2933

3034
// TODO export this from madwizard
@@ -43,6 +47,12 @@ function withFilepath(
4347
if (!parsedOptions.u) {
4448
// CLI path
4549
const { cli } = await import("madwizard/dist/fe/cli/index.js")
50+
51+
if (parsedOptions.q) {
52+
// TODO add this to madwizard?
53+
process.env.QUIET_CONSOLE = "true"
54+
}
55+
4656
await cli(
4757
["madwizard", task, ...argvNoOptions.slice(1), ...(parsedOptions.n ? ["--no-profile"] : [])],
4858
undefined,
@@ -65,7 +75,8 @@ function withFilepath(
6575
/** Register Kui Commands */
6676
export default function registerMadwizardCommands(registrar: Registrar) {
6777
const flags = {
68-
boolean: ["u", "V", "n"],
78+
boolean: ["u", "V", "n", "q"],
79+
alias: { quiet: ["q"] },
6980
}
7081

7182
registrar.listen(

0 commit comments

Comments
 (0)