Skip to content

Commit

Permalink
Add oxlog tool and library (#4810)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone authored Jan 23, 2024
1 parent beb1d11 commit 66afddb
Show file tree
Hide file tree
Showing 11 changed files with 631 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/buildomat/jobs/package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ptime -m cargo run --locked --release --bin omicron-package -- \
-t host target create -i standard -m gimlet -s asic -r multi-sled
ptime -m cargo run --locked --release --bin omicron-package -- \
-t host package
stamp_packages omicron-sled-agent mg-ddm-gz propolis-server overlay
stamp_packages omicron-sled-agent mg-ddm-gz propolis-server overlay oxlog

# Create global zone package @ /work/global-zone-packages.tar.gz
ptime -m ./tools/build-global-zone-packages.sh "$tarball_src_dir" /work
Expand Down
14 changes: 14 additions & 0 deletions Cargo.lock

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

3 changes: 3 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 @@ -93,6 +94,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 Expand Up @@ -252,6 +254,7 @@ nexus-inventory = { path = "nexus/inventory" }
omicron-certificates = { path = "certificates" }
omicron-passwords = { path = "passwords" }
omicron-workspace-hack = "0.1.0"
oxlog = { path = "dev-tools/oxlog" }
nexus-test-interface = { path = "nexus/test-interface" }
nexus-test-utils-macros = { path = "nexus/test-utils-macros" }
nexus-test-utils = { path = "nexus/test-utils" }
Expand Down
16 changes: 16 additions & 0 deletions dev-tools/oxlog/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[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
omicron-workspace-hack.workspace = true

[[bin]]
name = "oxlog"
121 changes: 121 additions & 0 deletions dev-tools/oxlog/src/bin/oxlog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// 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::{Args, Parser, Subcommand};
use oxlog::{Filter, 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,

#[command(flatten)]
filter: FilterArgs,
},
}

#[derive(Args, Debug)]
#[group(required = true, multiple = true)]
struct FilterArgs {
/// Print only the current log file
#[arg(short, long)]
current: bool,

/// Print only the archived 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, filter } => {
let zones = Zones::load()?;
let filter = Filter {
current: filter.current,
archived: filter.archived,
extra: filter.extra,
};
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, filter);
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 filter.current {
if let Some(current) = &svc_logs.current {
if metadata {
print_metadata(current);
} else {
println!("{}", current.path);
}
}
}
if filter.archived {
for f in &svc_logs.archived {
if metadata {
print_metadata(f);
} else {
println!("{}", f.path);
}
}
}
if filter.extra {
for f in &svc_logs.extra {
if metadata {
print_metadata(f);
} else {
println!("{}", f.path);
}
}
}
}
Ok(())
}
}
}
Loading

0 comments on commit 66afddb

Please sign in to comment.