Skip to content

Commit

Permalink
WIP: Add oxlog tool and library
Browse files Browse the repository at this point in the history
This still needs a bit of work before it is ready to go.
  • Loading branch information
andrewjstone committed Jan 12, 2024
1 parent 0528456 commit 40c9538
Show file tree
Hide file tree
Showing 5 changed files with 455 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ members = [
"dev-tools/crdb-seed",
"dev-tools/omdb",
"dev-tools/omicron-dev",
"dev-tools/oxlog",
"dev-tools/thing-flinger",
"dev-tools/xtask",
"dns-server",
Expand Down Expand Up @@ -91,6 +92,7 @@ default-members = [
"dev-tools/crdb-seed",
"dev-tools/omdb",
"dev-tools/omicron-dev",
"dev-tools/oxlog",
"dev-tools/thing-flinger",
# Do not include xtask in the list of default members, because this causes
# hakari to not work as well and build times to be longer.
Expand Down
18 changes: 18 additions & 0 deletions dev-tools/oxlog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "oxlog"
version = "0.1.0"
edition = "2021"
license = "MPL-2.0"

[dependencies]
anyhow.workspace = true
camino.workspace = true
chrono.workspace = true
clap.workspace = true
uuid.workspace = true

# Disable doc builds by default for our binaries to work around issue
# rust-lang/cargo#8373. These docs would not be very useful anyway.
[[bin]]
name = "oxlog"
doc = false
116 changes: 116 additions & 0 deletions dev-tools/oxlog/src/bin/oxlog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Tool for discovering oxide related logfiles on sleds
use clap::{Parser, Subcommand};
use oxlog::{LogFile, Zones};

#[derive(Debug, Parser)]
#[command(version)]
struct Cli {
#[command(subcommand)]
command: Commands,
}

#[derive(Debug, Subcommand)]
enum Commands {
/// List all zones found on the filesystem
Zones,

/// List logs for a given service
Logs {
// The name of the zone
zone: String,

/// The name of the service to list logs for
service: Option<String>,

/// Print available metadata
#[arg(short, long)]
metadata: bool,

/// Print only the current log file
#[arg(short, long)]
current: bool,

/// Print only the archive log files
#[arg(short, long)]
archived: bool,

// Print only the extra log files
#[arg(short, long)]
extra: bool,
},
}

fn main() -> Result<(), anyhow::Error> {
let cli = Cli::parse();

match cli.command {
Commands::Zones => {
for zone in Zones::load()?.zones.keys() {
println!("{zone}");
}
Ok(())
}
Commands::Logs {
zone,
service,
metadata,
current,
archived,
extra,
} => {
let zones = Zones::load()?;
let print_metadata = |f: &LogFile| {
println!(
"{}\t{}\t{}",
f.path,
f.size.map_or_else(|| "-".to_string(), |s| s.to_string()),
f.modified
.map_or_else(|| "-".to_string(), |s| s.to_rfc3339())
);
};

let logs = zones.zone_logs(&zone);
for (svc_name, mut svc_logs) in logs {
if let Some(service) = &service {
if svc_name != service.as_str() {
continue;
}
}
svc_logs.archived.sort();
if current {
if let Some(current) = &svc_logs.current {
if metadata {
print_metadata(current);
} else {
println!("{}", current.path);
}
}
}
if archived {
for f in &svc_logs.archived {
if metadata {
print_metadata(f);
} else {
println!("{}", f.path);
}
}
}
if extra {
for f in &svc_logs.extra {
if metadata {
print_metadata(f);
} else {
println!("{}", f.path);
}
}
}
}
Ok(())
}
}
}
Loading

0 comments on commit 40c9538

Please sign in to comment.