mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 08:47:12 +03:00
c2c904f933
Summary: Basically every single Mononoke binary starts with the same preamble: - Init mononoke - Init caching - Init logging - Init tunables Some of them forget to do it, some don't, etc. This is a mess. To make things messier, our initialization consists of a bunch of lazy statics interacting with each other (init logging & init configerator are kinda intertwined due to the fact that configerator wants a logger but dynamic observability wants a logger), and methods you must only call once. This diff attempts to clean this up by moving all this initialization into the construction of MononokeMatches. I didn't change all the accessor methods (though I did update those that would otherwise return things instantiated at startup). I'm planning to do a bit more on top of this, as my actual goal here is to make it easier to thread arguments from MononokeMatches to RepoFactory, and to do so I'd like to just pass my MononokeEnvironment as an input to RepoFactory. Reviewed By: HarveyHunt Differential Revision: D27767698 fbshipit-source-id: 00d66b07b8c69f072b92d3d3919393300dd7a392
96 lines
2.7 KiB
Rust
96 lines
2.7 KiB
Rust
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This software may be used and distributed according to the terms of the
|
|
* GNU General Public License version 2.
|
|
*/
|
|
|
|
use anyhow::{bail, Result};
|
|
use fbinit::FacebookInit;
|
|
use itertools::Itertools;
|
|
use std::collections::BTreeMap;
|
|
|
|
use cmdlib::args;
|
|
|
|
#[fbinit::main]
|
|
fn main(fb: FacebookInit) -> Result<()> {
|
|
let matches = args::MononokeAppBuilder::new("Lint Mononoke config files")
|
|
.with_advanced_args_hidden()
|
|
.build()
|
|
.about("Check Mononoke server configs for syntax and sanity.")
|
|
.args_from_usage(
|
|
r#"
|
|
-q --quiet 'Only print errors'
|
|
-v --verbose 'Dump content of configs'
|
|
"#,
|
|
)
|
|
.get_matches(fb)?;
|
|
|
|
let quiet = matches.is_present("quiet");
|
|
let verbose = matches.is_present("verbose");
|
|
let config_store = matches.config_store();
|
|
|
|
// Most of the work is done here - this validates that the files are present,
|
|
// are correctly formed, and have the right fields (not too many, not too few).
|
|
let configs = match args::load_repo_configs(config_store, &matches) {
|
|
Err(err) => {
|
|
eprintln!("Error loading configs: {:#?}", err);
|
|
return Err(err);
|
|
}
|
|
Ok(configs) => configs,
|
|
};
|
|
|
|
if verbose {
|
|
println!("Configs:\n{:#?}", configs)
|
|
}
|
|
|
|
// Keep track of what repo ids we've seen
|
|
let mut repoids = BTreeMap::<_, Vec<_>>::new();
|
|
// Have we seen something suspect?
|
|
let mut bad = false;
|
|
|
|
for (name, config) in &configs.repos {
|
|
let (isbad, locality) = match (
|
|
config.storage_config.metadata.is_local(),
|
|
config.storage_config.blobstore.is_local(),
|
|
) {
|
|
(true, true) => (false, "local"),
|
|
(false, false) => (false, "remote"),
|
|
(true, false) => (true, "MIXED - local DB, remote blobstore"),
|
|
(false, true) => (true, "MIXED - remote DB, local blobstore"),
|
|
};
|
|
|
|
bad |= isbad;
|
|
|
|
repoids
|
|
.entry(config.repoid)
|
|
.and_modify(|names| names.push(name.as_str()))
|
|
.or_insert(vec![name.as_str()]);
|
|
|
|
if isbad || !quiet {
|
|
println!(
|
|
"Repo {}: {} - enabled: {:?} locality: {}",
|
|
config.repoid, name, config.enabled, locality
|
|
);
|
|
}
|
|
}
|
|
|
|
for (id, names) in repoids {
|
|
assert!(!names.is_empty());
|
|
if names.len() > 1 {
|
|
eprintln!(
|
|
"ERROR: Repo Id {} used for repos: {}",
|
|
id,
|
|
names.into_iter().join(", ")
|
|
);
|
|
bad = true;
|
|
}
|
|
}
|
|
|
|
if bad {
|
|
bail!("Anomaly detected")
|
|
} else {
|
|
Ok(())
|
|
}
|
|
}
|