-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Rust HealthCheck strategy (#5117)
Similar to the python functionality, this just bumps the file timestamp in a regular interval.
- Loading branch information
Showing
8 changed files
with
148 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -153,6 +153,7 @@ fn create_factory( | |
concurrency, | ||
None, | ||
true, | ||
None, | ||
); | ||
Box::new(factory) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
rust_snuba/rust_arroyo/src/processing/strategies/healthcheck.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use std::path::PathBuf; | ||
use std::time::{Duration, SystemTime}; | ||
|
||
use crate::processing::strategies::{ | ||
CommitRequest, InvalidMessage, ProcessingStrategy, SubmitError, | ||
}; | ||
use crate::types::Message; | ||
use crate::utils::metrics::{get_metrics, BoxMetrics}; | ||
|
||
const TOUCH_INTERVAL: Duration = Duration::from_secs(1); | ||
|
||
pub struct HealthCheck<Next> { | ||
next_step: Next, | ||
path: PathBuf, | ||
interval: Duration, | ||
deadline: SystemTime, | ||
metrics: BoxMetrics, | ||
} | ||
|
||
impl<Next> HealthCheck<Next> { | ||
pub fn new(next_step: Next, path: impl Into<PathBuf>) -> Self { | ||
let interval = TOUCH_INTERVAL; | ||
let deadline = SystemTime::now() + interval; | ||
|
||
Self { | ||
next_step, | ||
path: path.into(), | ||
interval, | ||
deadline, | ||
metrics: get_metrics(), | ||
} | ||
} | ||
|
||
fn maybe_touch_file(&mut self) { | ||
let now = SystemTime::now(); | ||
if now < self.deadline { | ||
return; | ||
} | ||
if let Err(err) = filetime::set_file_mtime(&self.path, filetime::FileTime::now()) { | ||
let error: &dyn std::error::Error = &err; | ||
tracing::error!(error); | ||
} | ||
|
||
self.metrics | ||
.increment("arroyo.processing.strategies.healthcheck.touch", 1, None); | ||
self.deadline = now + self.interval; | ||
} | ||
} | ||
|
||
impl<TPayload, Next> ProcessingStrategy<TPayload> for HealthCheck<Next> | ||
where | ||
Next: ProcessingStrategy<TPayload> + 'static, | ||
{ | ||
fn poll(&mut self) -> Result<Option<CommitRequest>, InvalidMessage> { | ||
self.maybe_touch_file(); | ||
|
||
self.next_step.poll() | ||
} | ||
|
||
fn submit(&mut self, message: Message<TPayload>) -> Result<(), SubmitError<TPayload>> { | ||
self.next_step.submit(message) | ||
} | ||
|
||
fn close(&mut self) { | ||
self.next_step.close() | ||
} | ||
|
||
fn terminate(&mut self) { | ||
self.next_step.terminate() | ||
} | ||
|
||
fn join(&mut self, timeout: Option<Duration>) -> Result<Option<CommitRequest>, InvalidMessage> { | ||
self.next_step.join(timeout) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters