Skip to content

Commit ddc6019

Browse files
Add support for new dead_match parameter
1 parent 0f4243f commit ddc6019

2 files changed

Lines changed: 39 additions & 12 deletions

File tree

src/probe/map.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub struct MapServiceNodeHTTPStatus {
7575
#[derive(Deserialize)]
7676
pub struct MapServiceNodeHTTPBody {
7777
pub healthy_match: Option<String>,
78+
pub dead_match: Option<String>,
7879
}
7980

8081
#[derive(Debug)]

src/probe/poll.rs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,17 +316,23 @@ fn proceed_replica_request_http(
316316
debug!("prober poll will fire for http target: {}", &url);
317317

318318
// Unpack HTTP body match
319-
let http_body_healthy_match = http.as_ref().and_then(|ref http_inner| {
319+
let (mut http_body_healthy_match, mut http_body_dead_match) = (None, None);
320+
321+
if let Some(ref http_inner) = http {
320322
if let Some(ref http_inner_body_inner) = http_inner.body {
321323
if let Some(ref healthy_match_inner) = http_inner_body_inner.healthy_match {
322324
if healthy_match_inner.is_empty() == false {
323-
return Some(healthy_match_inner.to_owned());
325+
http_body_healthy_match = Some(healthy_match_inner.to_owned());
324326
}
325327
}
326-
}
327328

328-
None
329-
});
329+
if let Some(ref dead_match_inner) = http_inner_body_inner.dead_match {
330+
if dead_match_inner.is_empty() == false {
331+
http_body_dead_match = Some(dead_match_inner.to_owned());
332+
}
333+
}
334+
}
335+
}
330336

331337
// Unpack dead timeout
332338
let dead_timeout = acquire_dead_timeout(metrics);
@@ -341,11 +347,13 @@ fn proceed_replica_request_http(
341347
.connect_timeout(Some(dead_timeout))
342348
.read_timeout(Some(dead_timeout))
343349
.write_timeout(Some(dead_timeout))
344-
.method(if http_body_healthy_match.is_some() == true {
345-
Method::GET
346-
} else {
347-
Method::HEAD
348-
})
350+
.method(
351+
if http_body_healthy_match.is_some() == true || http_body_dead_match.is_some() == true {
352+
Method::GET
353+
} else {
354+
Method::HEAD
355+
},
356+
)
349357
.header("User-Agent", &*POLL_HTTP_HEADER_USERAGENT)
350358
.send(&mut response_body);
351359

@@ -376,11 +384,29 @@ fn proceed_replica_request_http(
376384

377385
// Consider as UP?
378386
if status_code >= http_healthy_above && status_code < http_healthy_below {
379-
// Check response body for match? (if configured)
387+
// Check response body for dead match? (if configured)
388+
if let Some(ref http_body_dead_match_inner) = http_body_dead_match {
389+
if !response_body.is_empty() {
390+
debug!(
391+
"checking prober poll result response text for url: {} for dead match",
392+
&url
393+
);
394+
395+
// Matches? Consider as DOWN.
396+
let text_search = TwoWaySearcher::new(http_body_dead_match_inner.as_bytes())
397+
.search_in(&response_body);
398+
399+
if text_search.is_some() {
400+
return (false, None);
401+
}
402+
}
403+
}
404+
405+
// Check response body for healthy match? (if configured)
380406
if let Some(ref http_body_healthy_match_inner) = http_body_healthy_match {
381407
if !response_body.is_empty() {
382408
debug!(
383-
"checking prober poll result response text for url: {} for any match",
409+
"checking prober poll result response text for url: {} for healthy match",
384410
&url
385411
);
386412

0 commit comments

Comments
 (0)