summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChinmay Garg <chinmaygarg@fb.com>2022-02-25 13:52:38 -0800
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2022-02-25 13:52:38 -0800
commit932cd978d34c752861147d7580da7d21a10a2f93 (patch)
treedaeb27a8c4c860ca707b93d143b253a0b494cc8f
parent9be9bc8651f2baf1f29ba7113568e62f6ec35968 (diff)
Adding option for snapshot file in replay
Summary: Adding a new option in `below replay` to be able to accept the compressed file from the `snapshot` and run replay using the files. **Usage** ``` below replay -- --snapshot <snapshot_file> --time <timestamp> ``` Reviewed By: brianc118 Differential Revision: D34410231 fbshipit-source-id: 17af3214ed0a38fca86ac7dffb5b75d78b24363b
-rw-r--r--below/src/main.rs40
1 files changed, 34 insertions, 6 deletions
diff --git a/below/src/main.rs b/below/src/main.rs
index eda9ad7f..552d9179 100644
--- a/below/src/main.rs
+++ b/below/src/main.rs
@@ -37,7 +37,7 @@ use structopt::{
clap::{AppSettings, Shell},
StructOpt,
};
-use tar::Builder as TarBuilder;
+use tar::{Archive, Builder as TarBuilder};
use tempdir::TempDir;
use users::{get_current_uid, get_user_by_uid};
@@ -209,6 +209,10 @@ enum Command {
/// * 09/01/2020 17:00: below replay -r yy -t "09/03/2020 17:00"
#[structopt(short = "r", verbatim_doc_comment)]
yesterdays: Option<String>,
+ /// Replay from a snapshot file generated by the snapshot
+ /// command instead of from the store directory.
+ #[structopt(long)]
+ snapshot: Option<String>,
},
/// Debugging facilities (for development use)
Debug {
@@ -620,11 +624,13 @@ fn real_main(init: init::InitToken) {
ref host,
ref port,
ref yesterdays,
+ ref snapshot,
} => {
let time = time.clone();
let host = host.clone();
let port = port.clone();
let days_adjuster = yesterdays.clone();
+ let snapshot = snapshot.clone();
run(
init,
debug,
@@ -632,7 +638,16 @@ fn real_main(init: init::InitToken) {
Service::Off,
RedirectLogOnFail::Off,
|_, below_config, logger, errs| {
- replay(logger, errs, time, below_config, host, port, days_adjuster)
+ replay(
+ logger,
+ errs,
+ time,
+ below_config,
+ host,
+ port,
+ days_adjuster,
+ snapshot,
+ )
},
)
}
@@ -747,14 +762,27 @@ fn replay(
host: Option<String>,
port: Option<u16>,
days_adjuster: Option<String>,
+ snapshot: Option<String>,
) -> Result<()> {
let timestamp =
cliutil::system_time_from_date_and_adjuster(time.as_str(), days_adjuster.as_deref())?;
- let mut advance = if let Some(host) = host {
- new_advance_remote(logger.clone(), host, port, timestamp)?
- } else {
- new_advance_local(logger.clone(), below_config.store_dir.clone(), timestamp)
+ let mut advance = match (host, snapshot) {
+ (None, None) => {
+ new_advance_local(logger.clone(), below_config.store_dir.clone(), timestamp)
+ }
+ (Some(host), None) => new_advance_remote(logger.clone(), host, port, timestamp)?,
+ (None, Some(snapshot)) => {
+ let mut tarball =
+ Archive::new(fs::File::open(&snapshot).context("Failed to open snapshot file")?);
+ let mut snapshot_dir = TempDir::new("snapshot_replay")?.into_path();
+ tarball.unpack(&snapshot_dir)?;
+ snapshot_dir.push(snapshot);
+ new_advance_local(logger.clone(), snapshot_dir, timestamp)
+ }
+ (Some(_), Some(_)) => {
+ bail!("--host and --snapshot are incompatible options")
+ }
};
// Fill the last_sample for forward iteration. If no previous sample exists,