Skip to content

Commit

Permalink
fix: rename --lines to --events
Browse files Browse the repository at this point in the history
  • Loading branch information
starpit committed Apr 8, 2023
1 parent da7715a commit 5ffce16
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export type State = {
agoInterval: ReturnType<typeof setInterval>

/** Lines of raw output to be displayed */
lines: UpdatePayload["lines"]
events: UpdatePayload["events"]

/** Controller that allows us to shut down gracefully */
watchers: { quit: () => void }[]
Expand Down Expand Up @@ -87,7 +87,7 @@ export default class Dashboard extends React.PureComponent<Props, State> {
this.setState((curState) => ({
firstUpdate: (curState && curState.firstUpdate) || Date.now(), // TODO pull from the events
lastUpdate: Date.now(), // TODO pull from the events
lines: !model.lines || model.lines.length === 0 ? curState?.lines : model.lines,
events: !model.events || model.events.length === 0 ? curState?.events : model.events,
workers: !curState?.workers
? [model.workers]
: [...curState.workers.slice(0, gridIdx), model.workers, ...curState.workers.slice(gridIdx + 1)],
Expand All @@ -101,9 +101,9 @@ export default class Dashboard extends React.PureComponent<Props, State> {
return this.props.grids.filter((_) => _ !== null) as GridSpec[]
}

/** @return current `lines` model */
private get lines(): UpdatePayload["lines"] {
return this.state?.lines
/** @return current `events` model */
private get events(): UpdatePayload["events"] {
return this.state?.events
}

/** @return first update time */
Expand Down Expand Up @@ -182,12 +182,12 @@ export default class Dashboard extends React.PureComponent<Props, State> {
return this.ago(Date.now() - millis)
}

/** Render log lines */
/** Render log lines and events */
private footer() {
if (!this.lines) {
if (!this.events) {
return <React.Fragment />
} else {
const rows = this.lines.map(({ line, timestamp }) => {
const rows = this.events.map(({ line, timestamp }) => {
// the controller (controller/dashboard/utilization/Live)
// leaves a {timestamp} breadcrumb in the raw line text, so
// that we,as the view, can inject a "5m ago" text, while
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export type UpdatePayload = {
/** Per-worker status info */
workers: Worker[]

/** Lines of raw output to be displayed */
lines?: { line: string; timestamp: number }[]
/** Lines of raw event lines to be displayed */
events?: { line: string; timestamp: number }[]
}

/** Callback from controller when it has updated data */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async function gridFor(
profile: string,
jobId: string,
historyConfig: HistoryConfig,
opts: Pick<Options, "demo" | "theme" | "lines">
opts: Pick<Options, "demo" | "theme" | "events">
): Promise<GridSpec> {
const tails = await tailf(kind, profile, jobId)
return kind === "status" ? status(tails, historyConfig, opts) : utilization(kind, tails, historyConfig, opts)
Expand All @@ -100,7 +100,7 @@ async function allGridsFor(
profile: string,
jobId: string,
historyConfig: HistoryConfig,
opts: Pick<Options, "demo" | "theme" | "lines">
opts: Pick<Options, "demo" | "theme" | "events">
) {
const usesGpus = opts.demo || (await import("../env.js").then((_) => _.usesGpus(profile, jobId)))

Expand All @@ -124,7 +124,7 @@ async function allGridsFor(
}

export default async function dashboard(args: Arguments<Options>, cmd: "db" | "dashboard") {
const { demo, theme, lines } = args.parsedOptions
const { demo, theme, events } = args.parsedOptions

const scale = args.parsedOptions.s || 1

Expand All @@ -144,9 +144,9 @@ export default async function dashboard(args: Arguments<Options>, cmd: "db" | "d
historyConfig: HistoryConfig
): Promise<null | GridSpec | (null | GridSpec)[]> => {
if (kind === "all") {
return allGridsFor(profile, jobId, historyConfig, { demo, theme, lines })
return allGridsFor(profile, jobId, historyConfig, { demo, theme, events })
} else if (isSupportedGrid(kind)) {
return gridFor(kind, profile, jobId, historyConfig, { demo, theme, lines })
return gridFor(kind, profile, jobId, historyConfig, { demo, theme, events })
} else {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ type Options = {
/** Theme to use for worker status */
theme: string

/** Number of lines of log messages to show [default: 8] */
lines: number
/** Number of lines of events to show [default: 8] */
events: number
}

export default Options

export const flags = {
boolean: ["demo"],
alias: { lines: ["l"], theme: ["t"], demo: ["d"], scale: ["s"] },
alias: { events: ["e"], theme: ["t"], demo: ["d"], scale: ["s"] },
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { OnData, Worker } from "../../../components/Dashboard/types.js"

import { rankFor, stateFor } from "./states.js"

type Line = { line: string; stateRank: number; timestamp: number }
type Event = { line: string; stateRank: number; timestamp: number }

/**
* Maintain a model of live data from a given set of file streams
Expand All @@ -37,11 +37,11 @@ export default class Live {
/** Model of status per worker */
private readonly workers: Record<string, Worker> = {}

/** Number of lines of output to retain. TODO this depends on height of terminal? */
/** Number of lines of event output to retain. TODO this depends on height of terminal? */
private static readonly MAX_HEAP = 1000

/** Model of the lines of output */
private readonly lines = new Heap<Line>((a, b) => {
private readonly events = new Heap<Event>((a, b) => {
if (a.line === b.line) {
return a.timestamp - b.timestamp
}
Expand All @@ -59,7 +59,7 @@ export default class Live {
private readonly tails: Promise<Tail>[],
cb: OnData,
styleOf: Record<WorkerState, TextProps>,
private readonly opts: Pick<Options, "lines">
private readonly opts: Pick<Options, "events">
) {
tails.map((tailf) => {
tailf.then(({ stream }) => {
Expand All @@ -77,7 +77,7 @@ export default class Live {

if (!name || !timestamp) {
// console.error("Bad status record", line)
// this.pushLineAndPublish(data, metric, timestamp, cb)
// this.pushEventAndPublish(data, metric, timestamp, cb)
return
} else if (!metric) {
// ignoring this line
Expand Down Expand Up @@ -111,7 +111,7 @@ export default class Live {

// inform the UI that we have updates
cb({
lines: this.pushLine(data, metric, timestamp),
events: this.pushEvent(data, metric, timestamp),
workers: Object.values(this.workers),
})
}
Expand All @@ -130,9 +130,9 @@ export default class Live {
})
}

private readonly lookup: Record<string, Line> = {}
/** Add `line` to our circular buffer `this.lines` */
private pushLine(line: string, metric: WorkerState, timestamp: number) {
private readonly lookup: Record<string, Event> = {}
/** Add `line` to our heap `this.events` */
private pushEvent(line: string, metric: WorkerState, timestamp: number) {
const key = line
.replace(/\s*(\d\d\d\d-\d\d-\d\dT\d\d:\d\d:\d\d(\.\d+)?Z)\s*/, "{timestamp}")
.replace(/pod\/torchx-\S+ /, "") // worker name in torchx
Expand All @@ -150,29 +150,29 @@ export default class Live {
const already = this.lookup[rec.line]
if (already) {
already.timestamp = timestamp
this.lines.updateItem(already)
this.events.updateItem(already)
} else {
this.lookup[rec.line] = rec
if (this.lines.size() >= Live.MAX_HEAP) {
this.lines.replace(rec)
if (this.events.size() >= Live.MAX_HEAP) {
this.events.replace(rec)
} else {
this.lines.push(rec)
this.events.push(rec)
}
}

if (this.opts.lines === 0) {
if (this.opts.events === 0) {
return []
} else {
return this.lines
return this.events
.toArray()
.slice(0, this.opts.lines || 8)
.slice(0, this.opts.events || 8)
.sort((a, b) => a.timestamp - b.timestamp)
}
}

/** `pushLine` and then pass the updated model to `cb` */
private pushLineAndPublish(line: string, metric: WorkerState, timestamp: number, cb: OnData) {
cb({ lines: this.pushLine(line, metric, timestamp), workers: Object.values(this.workers) })
/** `pushEvent` and then pass the updated model to `cb` */
private pushEventAndPublish(line: string, metric: WorkerState, timestamp: number, cb: OnData) {
cb({ events: this.pushEvent(line, metric, timestamp), workers: Object.values(this.workers) })
}

private asMillisSinceEpoch(timestamp: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { isValidStatusTheme, statusThemes } from "./theme.js"
export default function statusDashboard(
tails: Promise<Tail>[],
historyConfig: HistoryConfig,
opts: Pick<Options, "demo" | "theme" | "lines">
opts: Pick<Options, "demo" | "theme" | "events">
): GridSpec {
const { theme: themeS = "colorbrewer6" } = opts
if (!isValidStatusTheme(themeS)) {
Expand Down

0 comments on commit 5ffce16

Please sign in to comment.