Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Jan 12, 2024
1 parent 4140aaf commit a8039a1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 4 deletions.
8 changes: 7 additions & 1 deletion dev-tools/oxlog/src/bin/oxlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ fn main() -> Result<(), anyhow::Error> {
println!("{}", current.path);
}
}
// }
for f in &svc_logs.archived {
if metadata {
print_metadata(f);
} else {
println!("{}", f.path);
}
}
for f in &svc_logs.extra {
if metadata {
print_metadata(f);
} else {
println!("{}", f.path);
}
}
}
});
}
Expand Down
61 changes: 58 additions & 3 deletions dev-tools/oxlog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ impl LogFile {
pub struct SvcLogs {
pub current: Option<LogFile>,
pub archived: Vec<LogFile>,

// Logs in non-standard places and logs that aren't necessarily oxide logs
pub extra: Vec<LogFile>,
}

// These probably don't warrant newtypes. They are just to make the nested
Expand Down Expand Up @@ -123,11 +126,10 @@ impl Logs {
self.load_svc_logs("/var/svc/log", "global");
}

// TODO: For CRDB logs, we also want to look in /data/logs in the zones
fn load_service_zone_logs(&mut self) -> Result<(), anyhow::Error> {
let pools = Pools::read()?;

// Load the current logs
// Load the current and extra logs
for uuid in &pools.external {
let zones_path: Utf8PathBuf =
["/pool/ext", &uuid.to_string(), "crypt/zone"].iter().collect();
Expand All @@ -144,10 +146,20 @@ impl Logs {
// not utf8
continue;
};

// Load the current logs
let mut dir = zones_path.clone();
dir.push(zone);
dir.push("root/var/svc/log");
self.load_svc_logs(dir.as_str(), zone);

// Load the extra logs
if zone == "oxz_cockroachdb" {
let mut dir = zones_path.clone();
dir.push(zone);
dir.push("root/data/logs");
self.load_extra_logs(dir, zone, "cockroachdb");
}
}
}

Expand Down Expand Up @@ -179,6 +191,49 @@ impl Logs {
Ok(())
}

fn load_extra_logs(
&mut self,
dir: Utf8PathBuf,
zone: &str,
svc_name: &str,
) {
let Ok(entries) = read_dir(dir.as_path()) else {
return;
};
for entry in entries {
let Ok(entry) = entry else {
continue;
};
let filename = entry.file_name();
let Some(filename) = filename.to_str() else {
continue;
};
let mut path = dir.clone();
path.push(filename);
let mut logfile = LogFile::new(path);
if let Ok(metadata) = entry.metadata() {
if metadata.len() == 0 {
// skip 0 size files
continue;
}
logfile.size = Some(metadata.len());
if let Ok(modified) = metadata.modified() {
logfile.modified = Some(modified.into());
}
}

// We only insert extra files if we have already collected
// related current and archived files.
// This should always be the case unless the files are
// for zones that no longer exist.
self.svcs.get_mut(svc_name).map(|logs_by_zone| {
logs_by_zone.get_mut(zone).map(|svc_logs| {
svc_logs.extra.push(logfile);
})
});
}
}

fn load_svc_logs(&mut self, dir: &str, zone: &str) {
let dir = Utf8PathBuf::from(dir);
// Only scrimlets have switch zones
Expand Down Expand Up @@ -235,7 +290,7 @@ impl Logs {
} else {
(None, vec![logfile])
};
SvcLogs { current, archived }
SvcLogs { current, archived, extra: vec![] }
});
}
}
Expand Down

0 comments on commit a8039a1

Please sign in to comment.