fix(detmir): stabilize rust health gates

This commit is contained in:
igor04091968
2026-06-02 19:15:17 +03:00
parent 63774cb8c4
commit e1f78b7735
4 changed files with 40 additions and 7 deletions
+1 -1
View File
@@ -307,7 +307,7 @@ fn latest_bucket_event(client: &Client, api_base: &str, bucket_id: &str) -> Resu
.filter(|item| item.is_object()) .filter(|item| item.is_object())
.cloned() .cloned()
.collect::<Vec<_>>(); .collect::<Vec<_>>();
objects.sort_by(|left, right| event_effective_ts(right).cmp(&event_effective_ts(left))); objects.sort_by_key(|item| std::cmp::Reverse(event_effective_ts(item)));
Ok(objects.into_iter().next()) Ok(objects.into_iter().next())
} }
+2 -2
View File
@@ -227,7 +227,7 @@ fn read_context(
.pointer("/data/active") .pointer("/data/active")
.and_then(Value::as_bool) .and_then(Value::as_bool)
.unwrap_or(false); .unwrap_or(false);
if age >= 0 && age < 900 && !active { if (0..900).contains(&age) && !active {
state.host_inactive = true; state.host_inactive = true;
} }
} }
@@ -248,7 +248,7 @@ fn read_context(
.and_then(Value::as_array) .and_then(Value::as_array)
.map(Vec::len) .map(Vec::len)
.unwrap_or(0); .unwrap_or(0);
if age >= 0 && age < 300 && status == "ok" && problems == 0 { if (0..300).contains(&age) && status == "ok" && problems == 0 {
state.guard_healthy = true; state.guard_healthy = true;
} }
} }
+29 -2
View File
@@ -755,6 +755,15 @@ fn counter_delta(
} }
} }
fn transport_counter_key(prefix: &str, bucket_id: &str, data: &Value, metric: &str) -> String {
format!(
"{prefix}:{bucket_id}:{}:{}:{}:{metric}",
value_str(data.get("hostname")),
int_or_zero(data.get("sessionId")),
value_str(data.get("username"))
)
}
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
struct RuntimeThresholds { struct RuntimeThresholds {
sample_limit: i64, sample_limit: i64,
@@ -858,7 +867,7 @@ fn check_file_operations_runtime(
let send_failures = int_or_zero(health_data.get("sendFailures")); let send_failures = int_or_zero(health_data.get("sendFailures"));
let (previous, delta) = counter_delta( let (previous, delta) = counter_delta(
counter_state.as_deref_mut(), counter_state.as_deref_mut(),
&format!("file-operations:{bucket_id}:sendFailures"), &transport_counter_key("file-operations", bucket_id, health_data, "sendFailures"),
send_failures, send_failures,
); );
let health_item = json!({ let health_item = json!({
@@ -996,7 +1005,7 @@ fn check_endpoint_self_test_metrics(
let send_failures = int_or_zero(data.get("sendFailures")); let send_failures = int_or_zero(data.get("sendFailures"));
let (previous, delta) = counter_delta( let (previous, delta) = counter_delta(
counter_state.as_deref_mut(), counter_state.as_deref_mut(),
&format!("endpoint-self-test:{bucket_id}:sendFailures"), &transport_counter_key("endpoint-self-test", &bucket_id, data, "sendFailures"),
send_failures, send_failures,
); );
let item = json!({ let item = json!({
@@ -1501,6 +1510,24 @@ mod tests {
assert_eq!(counter_delta(Some(&mut state), "k", 1), (Some(13), 0)); assert_eq!(counter_delta(Some(&mut state), "k", 1), (Some(13), 0));
} }
#[test]
fn transport_counter_key_separates_sessions() {
let data = json!({
"hostname": "SHARKON2025",
"sessionId": 4,
"username": "USER4"
});
assert_eq!(
transport_counter_key(
"file-operations",
"aw-file-operations_SHARKON2025",
&data,
"sendFailures"
),
"file-operations:aw-file-operations_SHARKON2025:SHARKON2025:4:USER4:sendFailures"
);
}
#[test] #[test]
fn text_excerpt_truncates_like_python() { fn text_excerpt_truncates_like_python() {
let text = json!("one two three"); let text = json!("one two three");
@@ -151,12 +151,18 @@ fn process_one(zip_path: &Path) -> Result<ProcessResult> {
} }
archive_sidecars(&report_dir, &sidecars)?; archive_sidecars(&report_dir, &sidecars)?;
archive_drop_package(&report_dir, zip_path)?; archive_drop_package(&report_dir, zip_path)?;
if sidecars.case_id.is_some() && !Path::new(CASE_ALERT).is_file() { if let Some(case_id) = sidecars.case_id {
if Path::new(CASE_ALERT).is_file() {
return Ok(ProcessResult {
latest_intake: latest,
case_alert,
});
}
run_checked( run_checked(
Path::new(LINKER), Path::new(LINKER),
&[ &[
"--case-id".to_string(), "--case-id".to_string(),
sidecars.case_id.unwrap().to_string(), case_id.to_string(),
"--mode".to_string(), "--mode".to_string(),
mode, mode,
"--link-source".to_string(), "--link-source".to_string(),