Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ members = [
"src/health_monitoring_lib",
"examples/rust_supervised_app",
]
default-members = ["src/health_monitoring_lib"]

[workspace.package]
edition = "2021"
Expand Down
5 changes: 3 additions & 2 deletions examples/rust_supervised_app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,14 @@ fn main_logic(args: &Args, stop: Arc<AtomicBool>) -> Result<(), Box<dyn std::err
.add_deadline_monitor(MonitorTag::from("mon1"), builder)
.with_supervisor_api_cycle(std::time::Duration::from_millis(50))
.with_internal_processing_cycle(std::time::Duration::from_millis(50))
.build();
.build()
.expect("Failed to build health monitor");

let mon = hm
.get_deadline_monitor(MonitorTag::from("mon1"))
.expect("Failed to get monitor");

hm.start();
hm.start().expect("Failed to start health monitor");

if !lifecycle_client_rs::report_execution_state_running() {
error!("Rust app FAILED to report execution state!");
Expand Down
3 changes: 3 additions & 0 deletions src/health_monitoring_lib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CC_HDRS = [
rust_library(
name = "health_monitoring_lib",
srcs = glob(["rust/**/*.rs"]),
crate_features = ["score_supervisor_api_client"],
crate_root = "rust/lib.rs",
proc_macro_deps = PROC_MACRO_DEPS,
visibility = ["//visibility:public"],
Expand All @@ -65,6 +66,7 @@ cc_library(
rust_static_library(
name = "health_monitoring_lib_ffi",
srcs = glob(["rust/**/*.rs"]),
crate_features = ["score_supervisor_api_client"],
crate_name = "health_monitoring_lib",
crate_root = "rust/lib.rs",
proc_macro_deps = [
Expand Down Expand Up @@ -100,6 +102,7 @@ cc_library(
rust_test(
name = "tests",
crate = ":health_monitoring_lib",
crate_features = ["stub_supervisor_api_client"],
rustc_flags = [
"-C",
"link-arg=-lm",
Expand Down
6 changes: 3 additions & 3 deletions src/health_monitoring_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition.workspace = true
authors.workspace = true
license-file.workspace = true


[lib]
path = "rust/lib.rs"

Expand All @@ -18,11 +17,12 @@ workspace = true
score_log.workspace = true
score_testing_macros.workspace = true
containers.workspace = true
monitor_rs.workspace = true
monitor_rs = { workspace = true, optional = true }

[dev-dependencies]
stdout_logger.workspace = true

[features]
default = []
default = ["stub_supervisor_api_client"]
stub_supervisor_api_client = []
score_supervisor_api_client = ["monitor_rs"]
30 changes: 27 additions & 3 deletions src/health_monitoring_lib/rust/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

use crate::deadline::DeadlineEvaluationError;
use crate::log::ScoreDebug;
use crate::tag::MonitorTag;
use core::hash::Hash;
use core::time::Duration;
Expand All @@ -30,15 +32,37 @@ impl TimeRange {
}
}

/// The monitor has an evaluation handle available.
pub(crate) trait HasEvalHandle {
/// Get an evaluation handle for this monitor.
///
/// # NOTE
///
/// This method is intended to be called from a background thread periodically.
fn get_eval_handle(&self) -> MonitorEvalHandle;
}

/// Errors that can occur during monitor evaluation.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, crate::log::ScoreDebug)]
/// Contains failing monitor type.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, ScoreDebug)]
#[allow(dead_code)]
pub(crate) enum MonitorEvaluationError {
TooEarly,
TooLate,
Deadline(DeadlineEvaluationError),
Heartbeat,
Logic,
}

impl From<DeadlineEvaluationError> for MonitorEvaluationError {
fn from(value: DeadlineEvaluationError) -> Self {
MonitorEvaluationError::Deadline(value)
}
}

/// Trait for evaluating monitors and reporting errors to be used by HealthMonitor.
pub(crate) trait MonitorEvaluator {
/// Run monitor evaluation.
///
/// - `on_error` - error handling, containing tag of failing object and error code.
fn evaluate(&self, on_error: &mut dyn FnMut(&MonitorTag, MonitorEvaluationError));
}

Expand Down
Loading
Loading