Skip to content

Commit

Permalink
feat: use health_check_interval in place of static duration
Browse files Browse the repository at this point in the history
  • Loading branch information
jdockerty committed Nov 14, 2023
1 parent 505e8dc commit 11f1edf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use std::{
use tracing::{debug, error, info};

pub fn http_health(conf: Arc<Config>, sender: SendTargets) {
let duration = Duration::from_secs(5);
let health_client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(1))
.build()
Expand Down Expand Up @@ -65,7 +64,7 @@ pub fn http_health(conf: Arc<Config>, sender: SendTargets) {
}
debug!("[HTTP] Sending targets to channel");
sender.send(healthy_targets).unwrap();
thread::sleep(duration);
thread::sleep(conf.health_check_interval());
}
} else {
info!("No targets configured, unable to health check.");
Expand All @@ -74,8 +73,6 @@ pub fn http_health(conf: Arc<Config>, sender: SendTargets) {

/// Run health checks against the configured TCP targets.
pub fn tcp_health(conf: Arc<Config>, sender: SendTargets) {
let duration = Duration::from_secs(5);

if let Some(targets) = &conf.targets {
info!("Starting TCP health checks");
loop {
Expand Down Expand Up @@ -111,7 +108,7 @@ pub fn tcp_health(conf: Arc<Config>, sender: SendTargets) {
}
debug!("Sending targets to channel");
sender.send(healthy_targets).unwrap();
thread::sleep(duration);
thread::sleep(conf.health_check_interval());
}
} else {
info!("No targets configured, unable to health check.");
Expand Down
6 changes: 3 additions & 3 deletions tests/lb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use assert_cmd::prelude::*;
use gruglb;
use std::process::Command;
use std::sync::{Arc, Mutex};
use std::{thread, time::Duration};
use std::thread;

mod common;

Expand Down Expand Up @@ -41,11 +41,11 @@ fn register_healthy_targets() {
let test_config = common::test_targets_config();

let (send, recv) = common::get_send_recv();
let lb = gruglb::lb::new(test_config);
let lb = gruglb::lb::new(test_config.clone());
let _ = lb.run(send, recv);

// Wait for some set duration so that the health checks are conducted.
thread::sleep(Duration::from_secs(10));
thread::sleep(test_config.health_check_interval());

let tcp_healthy_backends = lb
.current_healthy_targets
Expand Down

0 comments on commit 11f1edf

Please sign in to comment.