Skip to content

Commit

Permalink
refactor(scaler): rename BackoffAwareScaler to BackoffWrapper
Browse files Browse the repository at this point in the history
Signed-off-by: Brooks Townsend <[email protected]>
  • Loading branch information
brooksmtownsend committed Aug 12, 2024
1 parent 7e03d06 commit 78291c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
18 changes: 9 additions & 9 deletions crates/wadm/src/scaler/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use super::{
link::{LinkScaler, LinkScalerConfig},
provider::{ProviderSpreadConfig, ProviderSpreadScaler},
},
BackoffScaler,
BackoffWrapper,
};

pub type BoxedScaler = Box<dyn Scaler + Send + Sync + 'static>;
Expand Down Expand Up @@ -504,7 +504,7 @@ where
// wrapped ones (which is good from a Rust API point of view). If
// this starts to become a problem, we can revisit how we handle
// this (probably by requiring that this struct always wraps any
// scaler in the backoff scaler and using custom methods from that
// scaler in the backoff wrapper and using custom methods from that
// type)
Notifications::RegisterExpectedEvents{ name, scaler_id, triggering_event } => {
trace!(%name, "Computing and registering expected events for manifest");
Expand Down Expand Up @@ -606,7 +606,7 @@ where
config_names.append(&mut secret_names.clone());
match (trt.trait_type.as_str(), &trt.properties) {
(SPREADSCALER_TRAIT, TraitProperty::SpreadScaler(p)) => {
Some(Box::new(BackoffScaler::new(
Some(Box::new(BackoffWrapper::new(
ComponentSpreadScaler::new(
snapshot_data.clone(),
props.image.to_owned(),
Expand All @@ -626,7 +626,7 @@ where
)) as BoxedScaler)
}
(DAEMONSCALER_TRAIT, TraitProperty::SpreadScaler(p)) => {
Some(Box::new(BackoffScaler::new(
Some(Box::new(BackoffWrapper::new(
ComponentDaemonScaler::new(
snapshot_data.clone(),
props.image.to_owned(),
Expand Down Expand Up @@ -682,7 +682,7 @@ where
| Properties::Component {
properties: ComponentProperties { id, .. },
} if component.name == p.target.name => {
Some(Box::new(BackoffScaler::new(
Some(Box::new(BackoffWrapper::new(
LinkScaler::new(
snapshot_data.clone(),
LinkScalerConfig {
Expand Down Expand Up @@ -740,7 +740,7 @@ where
);
config_names.append(&mut secret_names.clone());

Some(Box::new(BackoffScaler::new(
Some(Box::new(BackoffWrapper::new(
ProviderSpreadScaler::new(
snapshot_data.clone(),
ProviderSpreadConfig {
Expand Down Expand Up @@ -773,7 +773,7 @@ where
policies,
);
config_names.append(&mut secret_names.clone());
Some(Box::new(BackoffScaler::new(
Some(Box::new(BackoffWrapper::new(
ProviderDaemonScaler::new(
snapshot_data.clone(),
ProviderSpreadConfig {
Expand Down Expand Up @@ -834,7 +834,7 @@ where
Properties::Component { properties: cappy }
if component.name == p.target.name =>
{
Some(Box::new(BackoffScaler::new(
Some(Box::new(BackoffWrapper::new(
LinkScaler::new(
snapshot_data.clone(),
LinkScalerConfig {
Expand Down Expand Up @@ -883,7 +883,7 @@ where
secrets_to_scalers(snapshot_data.clone(), name, &props.secrets, policies);
config_names.append(&mut secret_names.clone());

scalers.push(Box::new(BackoffScaler::new(
scalers.push(Box::new(BackoffWrapper::new(
ProviderSpreadScaler::new(
snapshot_data.clone(),
ProviderSpreadConfig {
Expand Down
16 changes: 8 additions & 8 deletions crates/wadm/src/scaler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub trait Scaler {
async fn cleanup(&self) -> Result<Vec<Command>>;
}

/// The BackoffScaler is a wrapper around a scaler that is responsible for
/// The BackoffWrapper is a wrapper around a scaler that is responsible for
/// ensuring that a particular scaler doesn't get overwhelmed with events and has the
/// necessary prerequisites to reconcile.
///
Expand All @@ -95,7 +95,7 @@ pub trait Scaler {
/// and links to start is that their configuration is available. Scalers will not be
/// able to issue commands until the configuration exists.
/// 2. `expected_events`: For scalers that issue commands that should result in events,
/// the BackoffScaler is responsible for ensuring that the scaler doesn't continually
/// the BackoffWrapper is responsible for ensuring that the scaler doesn't continually
/// issue commands that it's already expecting events for. Commonly this will allow a host
/// to download larger images from an OCI repository without being bombarded with repeat requests.
/// 3. `backoff_status`: If a scaler receives an event that it was expecting, but it was a failure
Expand All @@ -109,7 +109,7 @@ pub trait Scaler {
/// The `notifier` is used to publish notifications to add, remove, or recompute
/// expected events with scalers on other wadm instances, as only one wadm instance
/// at a time will handle a specific event.
pub(crate) struct BackoffScaler<T, P, C> {
pub(crate) struct BackoffWrapper<T, P, C> {
scaler: T,
notifier: P,
notify_subject: String,
Expand All @@ -123,21 +123,21 @@ pub(crate) struct BackoffScaler<T, P, C> {
event_cleaner: Mutex<Option<JoinHandle<()>>>,
/// The amount of time to wait before cleaning up the expected events list
cleanup_timeout: std::time::Duration,
/// The status of the backoff scaler, set when the scaler is backing off due to a
/// The status of the scaler, set when the scaler is backing off due to a
/// failure event.
backoff_status: Arc<RwLock<Option<StatusInfo>>>,
// TODO(#253): Figure out where/when/how to store the backoff and exponentially repeat it
/// Responsible for cleaning up the backoff status after a specified duration
status_cleaner: Mutex<Option<JoinHandle<()>>>,
}

impl<T, P, C> BackoffScaler<T, P, C>
impl<T, P, C> BackoffWrapper<T, P, C>
where
T: Scaler + Send + Sync,
P: Publisher + Send + Sync + 'static,
C: ConfigSource + SecretSource + Send + Sync + Clone + 'static,
{
/// Wraps the given scaler in a new backoff scaler. `cleanup_timeout` can be set to a
/// Wraps the given scaler in a new BackoffWrapper. `cleanup_timeout` can be set to a
/// desired waiting time, otherwise it will default to 30s
pub fn new(
scaler: T,
Expand Down Expand Up @@ -466,7 +466,7 @@ where
}

#[async_trait]
/// The [`Scaler`] trait implementation for the [`BackoffScaler`] is mostly a simple wrapper,
/// The [`Scaler`] trait implementation for the [`BackoffWrapper`] is mostly a simple wrapper,
/// with three exceptions, which allow scalers to sync state between different wadm instances.
///
/// * `handle_event` calls an internal method that uses a notifier to publish notifications to
Expand All @@ -477,7 +477,7 @@ where
/// reconciliation commands in order to "back off".
/// * `status` will first check to see if the scaler is in a backing off state, and if so, return
/// the backoff status. Otherwise, it will return the status of the scaler.
impl<T, P, C> Scaler for BackoffScaler<T, P, C>
impl<T, P, C> Scaler for BackoffWrapper<T, P, C>
where
T: Scaler + Send + Sync,
P: Publisher + Send + Sync + 'static,
Expand Down

0 comments on commit 78291c7

Please sign in to comment.