Skip to content

Commit 21d7e93

Browse files
committed
oxlog: Glob match zone names for 'logs' subcommand
`oxlog logs` currently requires a precise match for the zone name. This is inconvenient when attempting to search across multiple zones with similar names. For example, when searching all Crucible downstairs, or using Pilot to query Nexus logs on multiple sleds. Use the `glob` crate to pattern match against the zone string provided, potentially allowing the logs from multiple zones to be returned. Example usage: $ oxlog logs 'nexus_*' --current
1 parent 267d3d8 commit 21d7e93

File tree

3 files changed

+36
-29
lines changed

3 files changed

+36
-29
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev-tools/oxlog/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ anyhow.workspace = true
1212
camino.workspace = true
1313
chrono.workspace = true
1414
clap.workspace = true
15+
glob.workspace = true
1516
jiff.workspace = true
1617
sigpipe.workspace = true
1718
uuid.workspace = true

dev-tools/oxlog/src/bin/oxlog.rs

+34-29
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ fn main() -> Result<(), anyhow::Error> {
120120
}
121121
Commands::Logs { zone, service, metadata, filter, before, after } => {
122122
let zones = Zones::load()?;
123+
let pattern = glob::Pattern::new(&zone)?;
123124
let date_range = match (before, after) {
124125
(None, None) => None,
125126
_ => Some(DateRange::new(
@@ -145,37 +146,41 @@ fn main() -> Result<(), anyhow::Error> {
145146
);
146147
};
147148

148-
let logs = zones.zone_logs(&zone, filter);
149-
for (svc_name, svc_logs) in logs {
150-
if let Some(service) = &service {
151-
if svc_name != service.as_str() {
152-
continue;
153-
}
154-
}
155-
if filter.current {
156-
if let Some(current) = &svc_logs.current {
157-
if metadata {
158-
print_metadata(current);
159-
} else {
160-
println!("{}", current.path);
149+
for zone_name in zones.zones.keys() {
150+
if pattern.matches(zone_name) {
151+
let logs = zones.zone_logs(&zone, filter);
152+
for (svc_name, svc_logs) in logs {
153+
if let Some(service) = &service {
154+
if svc_name != service.as_str() {
155+
continue;
156+
}
161157
}
162-
}
163-
}
164-
if filter.archived {
165-
for f in &svc_logs.archived {
166-
if metadata {
167-
print_metadata(f);
168-
} else {
169-
println!("{}", f.path);
158+
if filter.current {
159+
if let Some(current) = &svc_logs.current {
160+
if metadata {
161+
print_metadata(current);
162+
} else {
163+
println!("{}", current.path);
164+
}
165+
}
170166
}
171-
}
172-
}
173-
if filter.extra {
174-
for f in &svc_logs.extra {
175-
if metadata {
176-
print_metadata(f);
177-
} else {
178-
println!("{}", f.path);
167+
if filter.archived {
168+
for f in &svc_logs.archived {
169+
if metadata {
170+
print_metadata(f);
171+
} else {
172+
println!("{}", f.path);
173+
}
174+
}
175+
}
176+
if filter.extra {
177+
for f in &svc_logs.extra {
178+
if metadata {
179+
print_metadata(f);
180+
} else {
181+
println!("{}", f.path);
182+
}
183+
}
179184
}
180185
}
181186
}

0 commit comments

Comments
 (0)