async fn coordinated_omission_mitigation(
        &self,
        request_metric: &SwanlingRequestMetric,
    ) -> Result<u64, SwanlingTaskError> {
        if let Some(co_mitigation) = self.config.co_mitigation.as_ref() {
            // Return immediately if coordinated omission mitigation is disabled.
            if co_mitigation == &SwanlingCoordinatedOmissionMitigation::Disabled {
                return Ok(0);
            }

            // Grab a read-only copy of the `requests_cadence` object to view the current
            // request cadence.
            let request_cadence = self.request_cadence.read().await;

            // Generate an info level alert if this specific request took longer than the normal
            // cadence, as that means this specific request will likely trigger Coordinated
            // Omission Mitigation.
            if request_cadence.counter > 3
                && request_metric.response_time > request_cadence.user_cadence
            {
                let task_name = if !self.weighted_tasks.is_empty() {
                    let position = self.position.load(Ordering::SeqCst);
                    if !self.weighted_tasks[position].1.is_empty() {
                        format!(", task name: \"{}\"", self.weighted_tasks[position].1)
                    } else {
                        "".to_string()
                    }
                } else {
                    "".to_string()
                };
                info!(
                    "{:.3}s into swanling attack: \"{} {}\" [{}] took abnormally long ({} ms){}",
                    request_metric.elapsed as f64 / 1_000.0,
                    request_metric.method,
                    request_metric.url,
                    request_metric.status_code,
                    request_metric.response_time,
                    task_name,
                );
            }

            // Check if Coordinated Omission Mitigation has been triggered.
            if request_cadence.coordinated_omission_mitigation > 0 {
                // Base our coordinated omission generated request metric on the actual
                // metric that triggered this logic.
                let mut coordinated_omission_request_metric = request_metric.clone();
                // Record data points specific to coordinated_omission.
                coordinated_omission_request_metric.coordinated_omission_elapsed =
                    request_cadence.coordinated_omission_mitigation;
                // Record data points specific to coordinated_omission.
                coordinated_omission_request_metric.user_cadence = request_cadence.user_cadence;
                // Send the coordinated omission mitigation generated metrics to the parent.
                self.send_request_metric_to_parent(coordinated_omission_request_metric)?;
            }
            Ok(request_cadence.user_cadence)
        } else {
            // A setting for coordinated omission mitigation is required, defaults to Average.
            unreachable!();
        }
    }
/// If Coordinated Omission Mitigation is enabled, compares how long has passed since the last
/// loop through all SwanlingTasks by the current SwanlingUser. Through this mechanism, Swanling is
/// able to detect stalls on the upstream server being load tested, backfilling requests based
/// on what statistically should have happened. Can be disabled with `--co-mitigation disabled`.
If Coordinated Omission Mitigation is enabled, compares how long has passed since the last
loop through all SwanlingTasks by the current SwanlingUser. Through this mechanism, Swanling is
able to detect stalls on the upstream server being load tested, backfilling requests based
on what statistically should have happened. Can be disabled with `--co-mitigation disabled`.
If Coordinated Omission Mitigation is enabled compares how long has passed since the last loop through all SwanlingTasks by the current SwanlingUser . Through this mechanism Swanling is able to detect stalls on the upstream server being load tested backfilling requests based on what statistically should have happened . Can be disabled with ` -- co - mitigation disabled ` .
async fn coordinated_omission_mitigation(
        &self,
        request_metric: &SwanlingRequestMetric,
    ) -> Result<u64, SwanlingTaskError> {
        if let Some(co_mitigation) = self.config.co_mitigation.as_ref() {
            // Return immediately if coordinated omission mitigation is disabled.
            if co_mitigation == &SwanlingCoordinatedOmissionMitigation::Disabled {
                return Ok(0);
            }
            // Grab a read-only copy of the `requests_cadence` object to view the current
            // request cadence.
            let request_cadence = self.request_cadence.read().await;
            // Generate an info level alert if this specific request took longer than the normal
            // cadence, as that means this specific request will likely trigger Coordinated
            // Omission Mitigation.
            if request_cadence.counter > 3
                && request_metric.response_time > request_cadence.user_cadence
            {
                let task_name = if !self.weighted_tasks.is_empty() {
                    let position = self.position.load(Ordering::SeqCst);
                    if !self.weighted_tasks[position].1.is_empty() {
                        format!(", task name: \"{}\"", self.weighted_tasks[position].1)
                    } else {
                        "".to_string()
                    }
                } else {
                    "".to_string()
                };
                info!(
                    "{:.3}s into swanling attack: \"{} {}\" [{}] took abnormally long ({} ms){}",
                    request_metric.elapsed as f64 / 1_000.0,
                    request_metric.method,
                    request_metric.url,
                    request_metric.status_code,
                    request_metric.response_time,
                    task_name,
                );
            }
            // Check if Coordinated Omission Mitigation has been triggered.
            if request_cadence.coordinated_omission_mitigation > 0 {
                // Base our coordinated omission generated request metric on the actual
                // metric that triggered this logic.
                let mut coordinated_omission_request_metric = request_metric.clone();
                // Record data points specific to coordinated_omission.
                coordinated_omission_request_metric.coordinated_omission_elapsed =
                    request_cadence.coordinated_omission_mitigation;
                // Record data points specific to coordinated_omission.
                coordinated_omission_request_metric.user_cadence = request_cadence.user_cadence;
                // Send the coordinated omission mitigation generated metrics to the parent.
                self.send_request_metric_to_parent(coordinated_omission_request_metric)?;
            }
            Ok(request_cadence.user_cadence)
        } else {
            // A setting for coordinated omission mitigation is required, defaults to Average.
            unreachable!();
        }
    }
async fn coordinated_omission_mitigation ( & self , request_metric : & SwanlingRequestMetric , ) -> Result < u64 , SwanlingTaskError > { if let Some ( co_mitigation ) = self . config . co_mitigation . as_ref ( ) { // Return immediately if coordinated omission mitigation is disabled. if co_mitigation == & SwanlingCoordinatedOmissionMitigation :: Disabled { return Ok ( 0 ) ; } // Grab a read-only copy of the `requests_cadence` object to view the current // request cadence. let request_cadence = self . request_cadence . read ( ) . await ; // Generate an info level alert if this specific request took longer than the normal // cadence, as that means this specific request will likely trigger Coordinated // Omission Mitigation. if request_cadence . counter > 3 && request_metric . response_time > request_cadence . user_cadence { let task_name = if ! self . weighted_tasks . is_empty ( ) { let position = self . position . load ( Ordering :: SeqCst ) ; if ! self . weighted_tasks [ position ] . 1 . is_empty ( ) { format ! ( " \" \" " self weighted_tasks [ position ] 1 ) } else { " " . to_string ( ) } } else { " " . to_string ( ) } ; info ! ( " \" \" " request_metric elapsed as f64 1_000.0 request_metric method request_metric url request_metric status_code request_metric response_time task_name ) ; } // Check if Coordinated Omission Mitigation has been triggered. if request_cadence . coordinated_omission_mitigation > 0 { // Base our coordinated omission generated request metric on the actual // metric that triggered this logic. let mut coordinated_omission_request_metric = request_metric . clone ( ) ; // Record data points specific to coordinated_omission. coordinated_omission_request_metric . coordinated_omission_elapsed = request_cadence . coordinated_omission_mitigation ; // Record data points specific to coordinated_omission. coordinated_omission_request_metric . user_cadence = request_cadence . user_cadence ; // Send the coordinated omission mitigation generated metrics to the parent. self . send_request_metric_to_parent ( coordinated_omission_request_metric ) ? ; } Ok ( request_cadence . user_cadence ) } else { // A setting for coordinated omission mitigation is required, defaults to Average. unreachable ! ( ) ; } }
If Coordinated Omission Mitigation is enabled, compares how long has passed since the last
loop through all SwanlingTasks by the current SwanlingUser.
If Coordinated Omission Mitigation is enabled compares how long has passed since the last loop through all SwanlingTasks by the current SwanlingUser .
&self
request_metric
&SwanlingRequestMetric