Skip to content

Commit

Permalink
Merge pull request #100 from tmknight/dev/0.13.4
Browse files Browse the repository at this point in the history
v0.13.4
  • Loading branch information
tmknight authored May 27, 2024
2 parents 4b6bc29 + 41b36fe commit 213cbe7
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 27 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

## 0.13.3
## 0.13.4

### Fixed

- Ensure log length assessment does not underflow and compensate for empty log
- Other code cleanup

### Security

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "docker-autoheal"
version = "0.13.3"
version = "0.13.4"
authors = ["Travis M Knight"]
license = "GPL-3.0"
description = "A cross-platform tool to monitor and remediate unhealthy Docker containers"
Expand Down
2 changes: 1 addition & 1 deletion src/execute/looper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ pub async fn start_loop(
} else if autoheal_monitor_enable && (autoheal_restart_enable || log_all) {
// Determine failing streak of the unhealthy container
let inspection = inspect_container(docker_clone.clone(), name, &id).await;
fail_reason = inspection.failing_reason.clone();
fail_reason.clone_from(&inspection.failing_reason);
exit_code = inspection.exit_code;
if inspection.failed {
// Remediate
Expand Down
37 changes: 15 additions & 22 deletions src/inquire/inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,24 @@ pub async fn inspect_container(docker: Docker, name: &str, id: &str) -> Result {
}
};
// Get last 'output' and 'exitcode' from state:health
let default_reason = String::from("unknown");
let mut failing_reason = default_reason.clone();
let mut failing_reason = "unknown".to_string();
let mut exit_code: i64 = -1;
match container_inspect
.state
.as_ref()
.and_then(|s| s.health.as_ref().and_then(|h| h.log.clone()))
{
Some(log) => {
let last = log.len() - 1;
let reason = log[last].clone().output.unwrap_or(default_reason);
failing_reason = reason.clone();
exit_code = log[last].clone().exit_code.unwrap_or(-1);
}
None => {
// Log that we had an error
let msg0 = format!(
"[{} ({})] Could not reliably determine container failing reason",
name, id
);
log_message(&msg0, ERROR).await;
if let Some(log) = container_inspect.state.as_ref().and_then(|s| s.health.as_ref().and_then(|h| h.log.clone())) {
if let Some(last) = log.last() {
failing_reason = last.output.clone().unwrap_or(failing_reason);
exit_code = last.exit_code.unwrap_or(exit_code);
} else {
failing_reason = "log is empty".to_string();
}
};
} else {
let msg0 = format!(
"[{} ({})] Could not reliably determine container failing reason",
name, id
);
log_message(&msg0, ERROR).await;
}
Result {
failed: !matches!(failing_streak, 0),
failed: failing_streak != 0,
failing_streak,
failing_reason,
exit_code,
Expand Down
2 changes: 1 addition & 1 deletion src/inquire/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub async fn containers_list(docker: Docker) -> Vec<ContainerSummary> {
// Build container assessment criteria
let mut filters = HashMap::new();
filters.insert("health", vec!["unhealthy"]);
filters.insert("status", vec!["running", "exited", "dead"]);
filters.insert("status", vec!["running", "dead"]);

// Gather all containers that are unhealthy
let container_options = Some(ListContainersOptions {
Expand Down

0 comments on commit 213cbe7

Please sign in to comment.