Skip to content

Commit

Permalink
begin restoring gaggle files and logic
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyandrews committed May 10, 2023
1 parent 9a64208 commit c694197
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
21 changes: 21 additions & 0 deletions src/gaggle/manager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//use crate::{GooseAttack, GooseConfiguration, GooseUserCommand, CANCELED, SHUTDOWN_GAGGLE};
use crate::{GooseAttack, GooseError};

impl GooseAttack {
/// Main manager loop.
pub(crate) async fn manager_main(
mut self,
) -> Result<GooseAttack, GooseError> {
// The GooseAttackRunState is used while spawning and running the
// GooseUser threads that generate the load test.
// @TODO: should this be replaced with a GooseAttackManagerState ?
let mut goose_attack_run_state = self
.initialize_attack()
.await
.expect("failed to initialize GooseAttackRunState");

assert!(goose_attack_run_state.controller_channel_rx.is_some());

Ok(self)
}
}
45 changes: 42 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,20 @@ mod test_plan;
mod throttle;
mod user;
pub mod util;
pub mod gaggle {
pub mod manager;
}

use gumdrop::Options;
use lazy_static::lazy_static;
use rand::seq::SliceRandom;
use rand::thread_rng;
use std::collections::{hash_map::DefaultHasher, BTreeMap, HashSet};
use std::hash::{Hash, Hasher};
use std::sync::{atomic::AtomicUsize, Arc, RwLock};
use std::sync::{
atomic::{AtomicUsize, Ordering},
Arc, RwLock,
};
use std::time::{self, Duration};
use std::{fmt, io};
use tokio::fs::File;
Expand Down Expand Up @@ -93,6 +99,15 @@ type UnsequencedTransactions = Vec<Transaction>;
/// Internal representation of sequenced transactions.
type SequencedTransactions = BTreeMap<usize, Vec<Transaction>>;

/// Returns the unique identifier of the running Worker when running in Gaggle mode.
///
/// The first Worker to connect to the Manager is assigned an ID of 1. For each
/// subsequent Worker to connect to the Manager the ID is incremented by 1. This
/// identifier is primarily an aid in tracing logs.
pub fn get_worker_id() -> usize {
WORKER_ID.load(Ordering::Relaxed)
}

/// An enumeration of all errors a [`GooseAttack`](./struct.GooseAttack.html) can return.
#[derive(Debug)]
pub enum GooseError {
Expand Down Expand Up @@ -236,6 +251,10 @@ pub enum AttackMode {
Undefined,
/// A single standalone process performing a load test.
StandAlone,
/// The controlling process in a Gaggle distributed load test.
Manager,
/// One of one or more working processes in a Gaggle distributed load test.
Worker,
}

#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -919,7 +938,13 @@ impl GooseAttack {
self.test_plan = TestPlan::build(&self.configuration);

// With a validated GooseConfiguration, enter a run mode.
self.attack_mode = AttackMode::StandAlone;
self.attack_mode = if self.configuration.manager {
AttackMode::Manager
} else if self.configuration.worker {
AttackMode::Worker
} else {
AttackMode::StandAlone
};

// Confirm there's either a global host, or each scenario has a host defined.
if self.configuration.no_autostart && self.validate_host().is_err() {
Expand All @@ -939,7 +964,21 @@ impl GooseAttack {
self.metrics.hash = s.finish();
debug!("hash: {}", self.metrics.hash);

self = self.start_attack().await?;
self = match self.attack_mode {
AttackMode::Manager => {
self.manager_main().await?;
panic!("attempted to start in AttackMode::Manager");
},
AttackMode::Worker => {
panic!("attempted to start in AttackMode::Worker");
},
AttackMode::StandAlone => {
self.start_attack().await?
},
AttackMode::Undefined => {
panic!("attempted to start in AttackMode::Undefined");
},
};

if self.metrics.display_metrics {
info!(
Expand Down

0 comments on commit c694197

Please sign in to comment.