Skip to content

Commit 7003a71

Browse files
authored
Add unionvisor diagnostics (#1732)
- feat(unionvisor): log bundle - feat(unionvisor): better bundle logging - fix(unionvisor): remove trailing } - feat(unionvisor): log running uniond version - feat(unionvisor): log uniond link info
2 parents 0e8e366 + 129d380 commit 7003a71

File tree

4 files changed

+44
-14
lines changed

4 files changed

+44
-14
lines changed

unionvisor/src/bundle.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77

88
use serde::{Deserialize, Serialize};
99
use thiserror::Error;
10-
use tracing::{debug, error, field::display as as_display};
10+
use tracing::{debug, error, field::display as as_display, info};
1111

1212
/// Bundles should have the following structure on the filesystem:
1313
///
@@ -117,12 +117,6 @@ pub struct BundleMeta {
117117
versions_directory: PathBuf,
118118
}
119119

120-
// pub enum BinaryAvailability {
121-
// NotFound,
122-
// PermissionDenied,
123-
// Ok,
124-
// }
125-
126120
impl Bundle {
127121
/// Constructs a new [`Bundle`] based on a path.
128122
/// Will read `bundle/meta.json` and error if invalid.
@@ -149,13 +143,17 @@ impl Bundle {
149143
pub fn path_to(&self, version: impl Into<OsString>) -> UnvalidatedVersionPath {
150144
let version = version.into();
151145
UnvalidatedVersionPath::new(
152-
self.path
153-
.join(&self.meta.versions_directory)
146+
self.versions_path()
154147
.join(version)
155148
.join(&self.meta.binary_name),
156149
)
157150
}
158151

152+
/// Provides the full path the the versions directory
153+
pub fn versions_path(&self) -> PathBuf {
154+
self.path.join(&self.meta.versions_directory)
155+
}
156+
159157
/// Returns a [`PathBuf`] to the Bundle's genesis.json
160158
pub fn genesis_json(&self) -> PathBuf {
161159
self.path.join("genesis.json")
@@ -168,6 +166,19 @@ impl Bundle {
168166
}
169167
}
170168

169+
pub fn log_bundle(bundle: &Bundle) {
170+
let versions = fs::read_dir(bundle.versions_path())
171+
.expect("can't read contents of versions path")
172+
.map(|v| {
173+
v.expect("can't read version in dir")
174+
.path()
175+
.into_os_string()
176+
})
177+
.collect::<Vec<_>>();
178+
179+
info!(target: "unionvisor", ?bundle, genesis=?bundle.genesis_json().into_os_string(), ?versions, "running with bundle" );
180+
}
181+
171182
#[derive(Debug, Error)]
172183
pub enum NewBundleError {
173184
#[error("cannot read bundle/meta.json")]

unionvisor/src/cli.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tracing::{field::display as as_display, info};
1313
use tracing_subscriber::filter::LevelFilter;
1414

1515
use crate::{
16-
bundle::{Bundle, NewBundleError, ValidateVersionPathError},
16+
bundle::{log_bundle, Bundle, NewBundleError, ValidateVersionPathError},
1717
init::{self, SetSeedsError},
1818
logging::LogFormat,
1919
supervisor::{self, RuntimeError},
@@ -208,6 +208,7 @@ impl RunCmd {
208208
fn run(&self, root: impl Into<PathBuf>, logformat: LogFormat) -> Result<(), RunError> {
209209
let root = root.into();
210210
let bundle = Bundle::new(self.bundle.clone())?;
211+
log_bundle(&bundle);
211212
let symlinker = Symlinker::new(root.clone(), bundle);
212213
supervisor::run_and_upgrade(
213214
root,

unionvisor/src/supervisor.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
ffi::{OsStr, OsString},
3-
fs::create_dir_all,
3+
fs::{self, create_dir_all},
44
io,
55
path::{Path, PathBuf},
66
process::{Child, ExitStatus},
@@ -53,6 +53,13 @@ impl Supervisor {
5353
args: I,
5454
) -> Result<(), SpawnError> {
5555
let program = self.symlinker.current_validated()?;
56+
info!(
57+
"running {:?} pointing to {:?}",
58+
program.0.clone().into_os_string(),
59+
fs::read_link(program.0.clone())
60+
.expect("uniond is not a link!")
61+
.into_os_string()
62+
);
5663
let mut command = std::process::Command::new(program.0);
5764
let command = command
5865
.args(vec!["--log_format", logformat.as_str()])
@@ -274,7 +281,10 @@ mod tests {
274281
use tracing_test::traced_test;
275282

276283
use super::*;
277-
use crate::{bundle::Bundle, testdata};
284+
use crate::{
285+
bundle::{log_bundle, Bundle},
286+
testdata,
287+
};
278288

279289
#[test]
280290
#[traced_test]

unionvisor/unionvisor.nix

+10-2
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@
125125
type = types.package;
126126
default = self.packages.${pkgs.system}.bundle-testnet-7;
127127
};
128+
logFormat = mkOption {
129+
type = types.str;
130+
default = "json";
131+
example = "plain";
132+
};
128133
moniker = mkOption { type = types.str; };
129134
network = mkOption {
130135
type = types.str;
@@ -210,11 +215,11 @@
210215
''
211216
${pkgs.coreutils}/bin/mkdir -p /var/lib/unionvisor
212217
cd /var/lib/unionvisor
213-
unionvisor init --moniker ${cfg.moniker} --seeds ${cfg.seeds} --network ${cfg.network} --allow-dirty
218+
unionvisor --log-format ${cfg.logFormat} init --moniker ${cfg.moniker} --seeds ${cfg.seeds} --network ${cfg.network} --allow-dirty
214219
215220
${configSymLinkCommands}
216221
217-
unionvisor run
222+
unionvisor --log-format ${cfg.logFormat} run
218223
'';
219224
};
220225
in
@@ -230,3 +235,6 @@
230235
};
231236
};
232237
}
238+
239+
240+

0 commit comments

Comments
 (0)