kanidm/orca/src/opt.rs

135 lines
3.7 KiB
Rust
Raw Normal View History

use std::str::FromStr;
2022-06-11 07:24:29 +02:00
#[derive(Debug, Parser)]
struct CommonOpt {
2022-06-11 07:24:29 +02:00
#[clap(short, long)]
/// Enable debug logging
pub debug: bool,
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Parser)]
struct PreProcOpt {
2022-06-11 07:24:29 +02:00
#[clap(flatten)]
pub copt: CommonOpt,
2022-06-11 07:24:29 +02:00
#[clap(parse(from_os_str), short, long = "input")]
/// Path to unprocessed data in json format.
pub input_path: PathBuf,
2022-06-11 07:24:29 +02:00
#[clap(parse(from_os_str), short, long = "output")]
/// Path to write the processed output.
pub output_path: PathBuf,
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Parser)]
struct SetupOpt {
2022-06-11 07:24:29 +02:00
#[clap(flatten)]
pub copt: CommonOpt,
2022-06-11 07:24:29 +02:00
#[clap(name = "target")]
/// Which service to target during this operation.
/// Valid values are "ds" or "kanidm"
pub target: TargetOpt,
2022-06-11 07:24:29 +02:00
#[clap(parse(from_os_str), short, long = "profile")]
/// Path to the test profile.
pub profile_path: PathBuf,
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Parser)]
struct RunOpt {
2022-06-11 07:24:29 +02:00
#[clap(flatten)]
pub copt: CommonOpt,
2022-06-11 07:24:29 +02:00
#[clap(name = "target")]
/// Which service to target during this operation.
/// Valid values are "ds" or "kanidm"
pub target: TargetOpt,
2022-06-11 07:24:29 +02:00
#[clap(name = "test_type")]
/// Which type of test to run against this system
pub test_type: TestTypeOpt,
2022-06-11 07:24:29 +02:00
#[clap(parse(from_os_str), short, long = "profile")]
/// Path to the test profile.
pub profile_path: PathBuf,
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Subcommand)]
pub(crate) enum TargetOpt {
2022-06-11 07:24:29 +02:00
#[clap(name = "ds")]
/// Run against the ldap/ds profile
Ds,
2022-06-11 07:24:29 +02:00
#[clap(name = "kanidm")]
/// Run against the kanidm http profile
Kanidm,
2022-06-11 07:24:29 +02:00
#[clap(name = "kanidm_ldap")]
/// Run against the kanidm ldap profile
KanidmLdap,
}
impl FromStr for TargetOpt {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"ds" => Ok(TargetOpt::Ds),
"kanidm" => Ok(TargetOpt::Kanidm),
"kanidm_ldap" => Ok(TargetOpt::KanidmLdap),
_ => Err("Invalid target type. Must be ds, kanidm, or kanidm_ldap"),
}
}
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Subcommand)]
pub(crate) enum TestTypeOpt {
2022-06-11 07:24:29 +02:00
#[clap(name = "search-basic")]
/// Perform a basic search-only test
SearchBasic,
}
impl FromStr for TestTypeOpt {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"search-basic" => Ok(TestTypeOpt::SearchBasic),
_ => Err("Invalid test type."),
}
}
}
impl std::fmt::Display for TestTypeOpt {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self {
TestTypeOpt::SearchBasic => write!(f, "search-basic"),
}
}
}
2022-06-11 07:24:29 +02:00
#[derive(Debug, Parser)]
#[clap(
name = "orca",
about = "Orca Load Testing Utility
2022-05-03 05:24:39 +02:00
Orca works in a few steps.
1. Create an orca config which defines the targets you want to be able to setup and load test. See example_profiles/small/orca.toml
2. (Optional) preprocess an anonymised 389-ds access log (created from an external tool) into an orca data set.
3. 'orca setup' the kanidm/389-ds instance from the orca data set. You can see an example of this in example_profiles/small/data.json. This will reset the database, and add tons of entries etc. For example:
orca setup kanidm -p ./example_profiles/small/orca.toml
4. 'orca run' one of the metrics, based on that data set. For example:
2022-05-03 05:24:39 +02:00
orca run -p example_profiles/small/orca.toml kanidm search-basic
2022-06-11 07:24:29 +02:00
"
)]
enum OrcaOpt {
2022-06-11 07:24:29 +02:00
#[clap(name = "preprocess")]
/// Preprocess a dataset that can be used for testing
PreProc(PreProcOpt),
2022-06-11 07:24:29 +02:00
#[clap(name = "setup")]
/// Setup a server as defined by a test profile
Setup(SetupOpt),
2022-06-11 07:24:29 +02:00
#[clap(name = "run")]
2022-05-03 05:24:39 +02:00
/// Run the load test as defined by the test profile
Run(RunOpt),
}