Skip to content

Commit

Permalink
Rename event-log toplevel command to journal
Browse files Browse the repository at this point in the history
  • Loading branch information
Kobzol committed Oct 14, 2024
1 parent df2fc20 commit 11d1604
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
4 changes: 2 additions & 2 deletions benchmarks/src/environment/hq.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def assign_workers(workers: List[HqWorkerConfig], nodes: List[str]) -> Dict[str,

def postprocess_events(binary_path: Path, event_log_path: Path, event_log_json_path: Path, workdir: Path):
with open(event_log_json_path, "w") as f:
subprocess.run([str(binary_path), "event-log", "export", str(event_log_path)], stdout=f, check=True)
subprocess.run([str(binary_path), "journal", "export", str(event_log_path)], stdout=f, check=True)
export_hq_events_to_chrome(event_log_json_path, workdir / "events-chrome.json")


Expand Down Expand Up @@ -184,7 +184,7 @@ def start_server(self):
self.postprocessing_fns.append(
lambda: postprocess_events(self.binary_path, event_log_path, event_log_json_path, workdir)
)
args += ["--event-log-path", str(event_log_path)]
args += ["--journal", str(event_log_path)]

args = StartProcessArgs(
args=args,
Expand Down
4 changes: 2 additions & 2 deletions crates/hyperqueue/src/bin/hq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use cli_table::ColorChoice;
use colored::Colorize;

use hyperqueue::client::commands::autoalloc::command_autoalloc;
use hyperqueue::client::commands::event::command_event_log;
use hyperqueue::client::commands::job::{
cancel_job, close_job, forget_job, output_job_cat, output_job_detail, output_job_list,
output_job_summary, JobCancelOpts, JobCatOpts, JobCloseOpts, JobForgetOpts, JobInfoOpts,
JobListOpts, JobTaskIdsOpts,
};
use hyperqueue::client::commands::journal::command_journal;
use hyperqueue::client::commands::outputlog::command_reader;
use hyperqueue::client::commands::server::command_server;
use hyperqueue::client::commands::submit::command::{open_job, SubmitJobConfOpts};
Expand Down Expand Up @@ -476,7 +476,7 @@ async fn main() -> hyperqueue::Result<()> {
SubCommand::Dashboard(opts) => command_dashboard_start(&gsettings, opts).await,
SubCommand::OutputLog(opts) => command_reader(&gsettings, opts),
SubCommand::AutoAlloc(opts) => command_autoalloc(&gsettings, opts).await,
SubCommand::EventLog(opts) => command_event_log(&gsettings, opts).await,
SubCommand::Journal(opts) => command_journal(&gsettings, opts).await,
SubCommand::GenerateCompletion(opts) => generate_completion(opts),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mod output;

use crate::client::commands::event::output::format_event;
use crate::client::commands::journal::output::format_event;
use crate::client::globalsettings::GlobalSettings;
use crate::common::utils::str::pluralize;
use crate::server::bootstrap::get_client_session;
Expand All @@ -12,37 +12,34 @@ use std::io::{BufWriter, Write};
use std::path::PathBuf;

#[derive(Parser)]
pub struct EventLogOpts {
/// Manage event log files.
pub struct JournalOpts {
/// Manage events and journal data.
#[clap(subcommand)]
command: EventCommand,
command: JournalCommand,
}

#[derive(Parser)]
enum EventCommand {
/// Export events from a log file to NDJSON (line-delimited JSON).
enum JournalCommand {
/// Export events from a journal to NDJSON (line-delimited JSON).
/// Events will be exported to `stdout`, you can redirect it e.g. to a file.
Export(ExportOpts),

/// Live stream events from server
/// Live stream events from the server.
Stream,
}

#[derive(Parser)]
struct ExportOpts {
/// Path to a file containing the event log.
/// The file had to be created with `hq server start --event-log-path=<PATH>`.
/// Path to a journal.
/// It had to be created with `hq server start --journal=<PATH>`.
#[arg(value_hint = ValueHint::FilePath)]
logfile: PathBuf,
journal: PathBuf,
}

pub async fn command_event_log(
gsettings: &GlobalSettings,
opts: EventLogOpts,
) -> anyhow::Result<()> {
pub async fn command_journal(gsettings: &GlobalSettings, opts: JournalOpts) -> anyhow::Result<()> {
match opts.command {
EventCommand::Export(opts) => export_json(opts),
EventCommand::Stream => stream_json(gsettings).await,
JournalCommand::Export(opts) => export_json(opts),
JournalCommand::Stream => stream_json(gsettings).await,
}
}

Expand All @@ -68,10 +65,10 @@ async fn stream_json(gsettings: &GlobalSettings) -> anyhow::Result<()> {
}

fn export_json(opts: ExportOpts) -> anyhow::Result<()> {
let mut file = JournalReader::open(&opts.logfile).map_err(|error| {
let mut file = JournalReader::open(&opts.journal).map_err(|error| {
anyhow!(
"Cannot open event log file at `{}`: {error:?}",
opts.logfile.display()
opts.journal.display()
)
})?;

Expand Down
2 changes: 1 addition & 1 deletion crates/hyperqueue/src/client/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub mod autoalloc;
pub mod event;
pub mod job;
pub mod journal;
pub mod outputlog;
pub mod server;
pub mod submit;
Expand Down
6 changes: 3 additions & 3 deletions crates/hyperqueue/src/common/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use clap_complete::Shell;
use tako::WorkerId;

use crate::client::commands::autoalloc::AutoAllocOpts;
use crate::client::commands::event::EventLogOpts;
use crate::client::commands::job::{
JobCancelOpts, JobCatOpts, JobCloseOpts, JobForgetOpts, JobInfoOpts, JobListOpts,
JobTaskIdsOpts,
};
use crate::client::commands::journal::JournalOpts;
use crate::client::commands::outputlog::OutputLogOpts;
use crate::client::commands::server::ServerOpts;
use crate::client::commands::submit::command::SubmitJobConfOpts;
Expand Down Expand Up @@ -203,8 +203,8 @@ pub enum SubCommand {
/// Automatic allocation management
#[command(name = "alloc")]
AutoAlloc(AutoAllocOpts),
/// Event log management
EventLog(EventLogOpts),
/// Event and journal management
Journal(JournalOpts),
/// Start the HyperQueue CLI dashboard
#[cfg(feature = "dashboard")]
Dashboard(DashboardOpts),
Expand Down
6 changes: 3 additions & 3 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_worker_stream_events1(hq_env: HqEnv, tmp_path):
hq_bin = get_hq_binary()
out_txt = tmp_path.joinpath("out.txt")
with open(out_txt, "w") as out:
p = subprocess.Popen([hq_bin, "--server-dir", hq_env.server_dir, "event-log", "stream"], stdout=out)
p = subprocess.Popen([hq_bin, "--server-dir", hq_env.server_dir, "journal", "stream"], stdout=out)
time.sleep(0.6)
hq_env.command(["submit", "--", "hostname"])
time.sleep(0.6)
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_worker_stream_events2(hq_env: HqEnv, tmp_path):
hq_bin = get_hq_binary()
out_txt = tmp_path.joinpath("out.txt")
with open(out_txt, "w") as out:
p = subprocess.Popen([hq_bin, "--server-dir", hq_env.server_dir, "event-log", "stream"], stdout=out)
p = subprocess.Popen([hq_bin, "--server-dir", hq_env.server_dir, "journal", "stream"], stdout=out)
time.sleep(0.6)
hq_env.command(["submit", "--", "hostname"])
time.sleep(0.6)
Expand Down Expand Up @@ -208,7 +208,7 @@ def get_events(hq_env: HqEnv, callback):
process.wait(timeout=5)
hq_env.processes.clear()

output = hq_env.command(["event-log", "export", log_path], ignore_stderr=True)
output = hq_env.command(["journal", "export", log_path], ignore_stderr=True)
events = []
for line in output.splitlines(keepends=False):
events.append(json.loads(line))
Expand Down

0 comments on commit 11d1604

Please sign in to comment.