Skip to content

Commit 9874a54

Browse files
Improve ICMP probe to ping all addresses in the same poll session
Signed-off-by: Valerian Saliou <valerian@valeriansaliou.name>
1 parent acf0a2b commit 9874a54

1 file changed

Lines changed: 42 additions & 21 deletions

File tree

src/prober/manager.rs

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,30 +183,47 @@ fn proceed_replica_probe_icmp(host: &str) -> (bool, Option<Duration>) {
183183
let address_values: Vec<SocketAddr> = address.collect();
184184

185185
if !address_values.is_empty() {
186+
debug!(
187+
"prober poll will fire for icmp host: {} ({} targets)",
188+
host,
189+
address_values.len()
190+
);
191+
192+
// As ICMP pings require a lower-than-usual timeout, an hard-coded ICMP \
193+
// timeout value is used by default, though the configured dead delay value \
194+
// is preferred in the event it is lower than the hard-coded value (unlikely \
195+
// though possible in some setups).
196+
let pinger_timeout = min(
197+
PROBE_ICMP_TIMEOUT_MILLISECONDS,
198+
APP_CONF.metrics.poll_delay_dead * 1000,
199+
);
200+
201+
let (pinger, results) =
202+
Pinger::new(Some(pinger_timeout), None).expect("failed to create icmp pinger");
203+
186204
// Probe all returned addresses (sequentially)
187-
for address_value in address_values {
205+
for address_value in &address_values {
188206
let address_ip = address_value.ip();
189207

190-
debug!("prober poll will fire for icmp target: {}", address_ip);
191-
192-
// As ICMP pings require a lower-than-usual timeout, an hard-coded ICMP \
193-
// timeout value is used by default, though the configured dead delay value \
194-
// is preferred in the event it is lower than the hard-coded value (unlikely \
195-
// though possible in some setups).
196-
let pinger_timeout = min(
197-
PROBE_ICMP_TIMEOUT_MILLISECONDS,
198-
APP_CONF.metrics.poll_delay_dead * 1000,
208+
debug!(
209+
"prober poll will send icmp ping to target: {} from host: {}",
210+
address_ip, host
199211
);
200212

201-
let (pinger, results) = Pinger::new(Some(pinger_timeout), None)
202-
.expect("failed to create icmp pinger");
203-
204213
pinger.add_ipaddr(&address_ip.to_string());
205-
pinger.ping_once();
214+
}
215+
216+
pinger.ping_once();
206217

218+
for _ in &address_values {
207219
match results.recv() {
208220
Ok(result) => match result {
209221
PingResult::Receive { addr, rtt } => {
222+
debug!(
223+
"got prober poll result for icmp target: {} from host: {}",
224+
addr, host
225+
);
226+
210227
// Do not return (consider address as reachable)
211228
// Notice: update maximum observed round-trip-time, if higher than \
212229
// last highest observed.
@@ -221,19 +238,19 @@ fn proceed_replica_probe_icmp(host: &str) -> (bool, Option<Duration>) {
221238
None => Some(rtt),
222239
};
223240
}
224-
PingResult::Idle { addr: _ } => {
225-
debug!("prober poll host idle for icmp target: {}", address_ip);
241+
PingResult::Idle { addr } => {
242+
debug!(
243+
"prober poll host idle for icmp target: {} from host: {}",
244+
addr, host
245+
);
226246

227247
// Consider ICMP idle hosts as a failure (ie. routable, but \
228248
// unreachable)
229249
return (false, None);
230250
}
231251
},
232252
Err(err) => {
233-
debug!(
234-
"prober poll error for icmp target: {} (error: {})",
235-
address_ip, err
236-
);
253+
debug!("prober poll error for icmp host: {} (error: {})", host, err);
237254

238255
// Consider ICMP errors as a failure
239256
return (false, None);
@@ -277,7 +294,11 @@ fn proceed_replica_probe_tcp(host: &str, port: u16) -> (bool, Option<Duration>)
277294
&address_value,
278295
Duration::from_secs(APP_CONF.metrics.poll_delay_dead),
279296
) {
280-
Ok(_) => (true, None),
297+
Ok(_) => {
298+
debug!("prober poll success for tcp target: {}", address_value);
299+
300+
(true, None)
301+
}
281302
Err(err) => {
282303
debug!(
283304
"prober poll error for tcp target: {} (error: {})",

0 commit comments

Comments
 (0)