From 852d036288c0251435f42a667b6135e1f6b76efc Mon Sep 17 00:00:00 2001 From: Siegfried Weber Date: Tue, 31 Aug 2021 15:01:48 +0200 Subject: [PATCH] Set annotation featureRestartCount The annotation featureRestartCount is set to "true" if the restart count in the container status can be set properly. This is the case if systemd version 235 or newer is used. If an older systemd version is used then featureRestartCount is set to "false". --- CHANGELOG.md | 3 ++ Cargo.lock | 13 +++---- Cargo.toml | 4 +-- .../ROOT/pages/monitoring/restarts.adoc | 17 +++++++++ src/provider/states/pod/starting.rs | 35 +++++++++++-------- src/provider/systemdmanager/service.rs | 3 ++ 6 files changed, 53 insertions(+), 22 deletions(-) create mode 100644 docs/modules/ROOT/pages/monitoring/restarts.adoc diff --git a/CHANGELOG.md b/CHANGELOG.md index b2cb914f..e75ddd78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ - Check added on startup if the configured directories exist and are writable by the Stackable agent ([#273]). - Missing directories are created ([#274]). +- Annotation `featureRestartCount` added to the pods to indicate if the + restart count is set properly ([#289]). ### Changed - Lazy validation of repository URLs changed to eager validation @@ -35,6 +37,7 @@ [#273]: https://github.com/stackabletech/agent/pull/273 [#274]: https://github.com/stackabletech/agent/pull/274 [#276]: https://github.com/stackabletech/agent/pull/276 +[#289]: https://github.com/stackabletech/agent/pull/289 ## 0.5.0 - 2021-07-26 diff --git a/Cargo.lock b/Cargo.lock index 8195fe6e..54359774 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3895,7 +3895,7 @@ dependencies = [ [[package]] name = "zbus" version = "2.0.0-beta.6" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=0a8a4268be0f844ab4bca429f27766347dc3af58#0a8a4268be0f844ab4bca429f27766347dc3af58" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=ff08cbbbcd3eead16464012b92e3862d4dcb6f16#ff08cbbbcd3eead16464012b92e3862d4dcb6f16" dependencies = [ "async-broadcast", "async-channel", @@ -3907,6 +3907,7 @@ dependencies = [ "byteorder", "derivative", "enumflags2", + "event-listener", "futures-core", "futures-sink", "futures-util", @@ -3914,7 +3915,6 @@ dependencies = [ "nix 0.21.1", "once_cell", "rand 0.8.4", - "scoped-tls", "serde", "serde_repr", "sha1", @@ -3928,7 +3928,7 @@ dependencies = [ [[package]] name = "zbus_macros" version = "2.0.0-beta.6" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=0a8a4268be0f844ab4bca429f27766347dc3af58#0a8a4268be0f844ab4bca429f27766347dc3af58" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=ff08cbbbcd3eead16464012b92e3862d4dcb6f16#ff08cbbbcd3eead16464012b92e3862d4dcb6f16" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -3940,7 +3940,7 @@ dependencies = [ [[package]] name = "zbus_names" version = "1.0.0" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=0a8a4268be0f844ab4bca429f27766347dc3af58#0a8a4268be0f844ab4bca429f27766347dc3af58" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=ff08cbbbcd3eead16464012b92e3862d4dcb6f16#ff08cbbbcd3eead16464012b92e3862d4dcb6f16" dependencies = [ "serde", "static_assertions", @@ -3950,10 +3950,11 @@ dependencies = [ [[package]] name = "zvariant" version = "2.8.0" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=0a8a4268be0f844ab4bca429f27766347dc3af58#0a8a4268be0f844ab4bca429f27766347dc3af58" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=ff08cbbbcd3eead16464012b92e3862d4dcb6f16#ff08cbbbcd3eead16464012b92e3862d4dcb6f16" dependencies = [ "byteorder", "enumflags2", + "libc", "serde", "static_assertions", "zvariant_derive", @@ -3962,7 +3963,7 @@ dependencies = [ [[package]] name = "zvariant_derive" version = "2.8.0" -source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=0a8a4268be0f844ab4bca429f27766347dc3af58#0a8a4268be0f844ab4bca429f27766347dc3af58" +source = "git+https://gitlab.freedesktop.org/dbus/zbus?rev=ff08cbbbcd3eead16464012b92e3862d4dcb6f16#ff08cbbbcd3eead16464012b92e3862d4dcb6f16" dependencies = [ "proc-macro-crate", "proc-macro2", diff --git a/Cargo.toml b/Cargo.toml index 1a2d45c0..aaf97833 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,8 +50,8 @@ tar = "0.4" thiserror = "1.0" tokio = { version = "1.11", features = ["macros", "rt-multi-thread", "time"] } url = "2.2" -zbus = { git = "https://gitlab.freedesktop.org/dbus/zbus", rev = "0a8a4268be0f844ab4bca429f27766347dc3af58" } # version 2.0.0-beta.6 + merge request !354 (fixes a race condition) -zvariant = { git = "https://gitlab.freedesktop.org/dbus/zbus", rev = "0a8a4268be0f844ab4bca429f27766347dc3af58" } # version 2.8.0 which is compatible with the zbus version +zbus = { git = "https://gitlab.freedesktop.org/dbus/zbus", rev = "ff08cbbbcd3eead16464012b92e3862d4dcb6f16" } # version 2.0.0-beta.6 + merge request !354 (fixes a race condition) + commit 6cdfe48cda5e0bf7b0dd8675be7a84439678afa9 (fixes another race condition) +zvariant = { git = "https://gitlab.freedesktop.org/dbus/zbus", rev = "ff08cbbbcd3eead16464012b92e3862d4dcb6f16" } # version 2.8.0 which is compatible with the zbus version [dev-dependencies] indoc = "1.0" diff --git a/docs/modules/ROOT/pages/monitoring/restarts.adoc b/docs/modules/ROOT/pages/monitoring/restarts.adoc new file mode 100644 index 00000000..15bc4a94 --- /dev/null +++ b/docs/modules/ROOT/pages/monitoring/restarts.adoc @@ -0,0 +1,17 @@ += Restarts + +The restart count is stored in the container status if systemd version +235 or newer is running on the node which is the case for Debian 10 and +CentOS 8 but not for CentOS 7. The annotation `featureRestartCount` +indicates whether or not the restart count is set properly. + + $ kubectl get pod + NAME READY STATUS RESTARTS AGE + 1/1 Running 4 10m + + $ kubectl describe pod + Name: + Annotations: featureRestartCount: true + Containers: + : + Restart Count: 4 diff --git a/src/provider/states/pod/starting.rs b/src/provider/states/pod/starting.rs index e3b4a89b..f18a6506 100644 --- a/src/provider/states/pod/starting.rs +++ b/src/provider/states/pod/starting.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use super::running::Running; use crate::provider::{ kubernetes::status::patch_container_status, systemdmanager::service::ServiceState, PodHandle, @@ -79,13 +81,17 @@ async fn start_service_units( ); } - add_annotation( - &client, - pod, + let mut annotations = HashMap::new(); + annotations.insert( "featureLogs", - &systemd_service.invocation_id().await.is_ok().to_string(), - ) - .await?; + systemd_service.invocation_id().await.is_ok().to_string(), + ); + annotations.insert( + "featureRestartCount", + systemd_service.restart_count().await.is_ok().to_string(), + ); + + add_annotations(&client, pod, &annotations).await?; patch_container_status(&client, pod, &container_key, &Status::running()).await; } @@ -93,17 +99,20 @@ async fn start_service_units( Ok(()) } -/// Adds an annotation to the given pod. +/// Adds annotations to the given pod. /// /// If there is already an annotation with the given key then the value /// is replaced. /// The function returns when the patch is sent. It does not await the /// changes to be visible to the watching clients. -async fn add_annotation(client: &Client, pod: &Pod, key: &str, value: &str) -> kube::Result { +async fn add_annotations( + client: &Client, + pod: &Pod, + annotations: &HashMap<&str, String>, +) -> kube::Result { debug!( - "Adding annotation [{}: {}] to pod [{:?}]", - key, - value, + "Adding annotations [{:?}] to pod [{:?}]", + annotations, PodKey::from(pod) ); @@ -111,9 +120,7 @@ async fn add_annotation(client: &Client, pod: &Pod, key: &str, value: &str) -> k let patch = json!({ "metadata": { - "annotations": { - key: value - } + "annotations": annotations } }); diff --git a/src/provider/systemdmanager/service.rs b/src/provider/systemdmanager/service.rs index 2804be85..c6a68c21 100644 --- a/src/provider/systemdmanager/service.rs +++ b/src/provider/systemdmanager/service.rs @@ -112,6 +112,9 @@ impl SystemdService { Ok(service_state) } + /// Retrieves the current restart count. + /// + /// The restart counter was introduced in systemd version 235. pub async fn restart_count(&self) -> anyhow::Result { self.service_proxy .nrestarts()