Skip to content

Commit

Permalink
Return different process exit codes from iotedged after configured re…
Browse files Browse the repository at this point in the history
…try count has been exceeded (#1190)
  • Loading branch information
shantanu1singh authored and arsing committed May 21, 2019
1 parent 49ab97e commit 62f3d44
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 68 deletions.
78 changes: 19 additions & 59 deletions edgelet/Cargo.lock

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

27 changes: 27 additions & 0 deletions edgelet/contrib/config/linux/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ agent:

hostname: "<ADD HOSTNAME HERE>"

###############################################################################
# Watchdog settings
###############################################################################
#
# The IoT edge daemon has a watchdog that periodically checks the health of the
# Edge Agent module and restarts it if it's down.
#
# max_retries - Configures the number of retry attempts that the IoT edge daemon
# should make for failed operations before failing with a fatal error.
#
# If this configuration is not specified, the daemon keeps retrying
# on errors and doesn't fail fatally.
#
# On a fatal failure, the daemon returns an exit code which
# signifies the kind of error encountered. Currently, the following
# error codes are returned by the daemon -
#
# 150 - Invalid Device ID specified.
# 151 - Invalid IoT hub configuration.
# 152 - Invalid SAS token used to call IoT hub.
# This could signal an invalid SAS key.
# 1 - All other errors.
###############################################################################

#watchdog:
# max_retries: 2

###############################################################################
# Connect settings
###############################################################################
Expand Down
27 changes: 27 additions & 0 deletions edgelet/contrib/config/linux/debian/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ agent:

hostname: "<ADD HOSTNAME HERE>"

###############################################################################
# Watchdog settings
###############################################################################
#
# The IoT edge daemon has a watchdog that periodically checks the health of the
# Edge Agent module and restarts it if it's down.
#
# max_retries - Configures the number of retry attempts that the IoT edge daemon
# should make for failed operations before failing with a fatal error.
#
# If this configuration is not specified, the daemon keeps retrying
# on errors and doesn't fail fatally.
#
# On a fatal failure, the daemon returns an exit code which
# signifies the kind of error encountered. Currently, the following
# error codes are returned by the daemon -
#
# 150 - Invalid Device ID specified.
# 151 - Invalid IoT hub configuration.
# 152 - Invalid SAS token used to call IoT hub.
# This could signal an invalid SAS key.
# 1 - All other errors.
###############################################################################

#watchdog:
# max_retries: 2

###############################################################################
# Connect settings
###############################################################################
Expand Down
27 changes: 27 additions & 0 deletions edgelet/contrib/config/windows/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,33 @@ agent:

hostname: "<ADD HOSTNAME HERE>"

###############################################################################
# Watchdog settings
###############################################################################
#
# The IoT edge daemon has a watchdog that periodically checks the health of the
# Edge Agent module and restarts it if it's down.
#
# max_retries - Configures the number of retry attempts that the IoT edge daemon
# should make for failed operations before failing with a fatal error.
#
# If this configuration is not specified, the daemon keeps retrying
# on errors and doesn't fail fatally.
#
# On a fatal failure, the daemon returns an exit code which
# signifies the kind of error encountered. Currently, the following
# error codes are returned by the daemon -
#
# 150 - Invalid Device ID specified.
# 151 - Invalid IoT hub configuration.
# 152 - Invalid SAS token used to call IoT hub.
# This could signal an invalid SAS key.
# 1 - All other errors.
###############################################################################

#watchdog:
# max_retries: 2

###############################################################################
# Connect settings
###############################################################################
Expand Down
30 changes: 30 additions & 0 deletions edgelet/edgelet-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use sha2::{Digest, Sha256};
use url::Url;

use edgelet_core::crypto::MemoryKey;
use edgelet_core::watchdog::RetryLimit;
use edgelet_core::ModuleSpec;
use edgelet_utils::log_failure;

Expand Down Expand Up @@ -358,6 +359,18 @@ impl Certificates {
}
}

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct WatchdogSettings {
#[serde(default)]
max_retries: RetryLimit,
}

impl WatchdogSettings {
pub fn max_retries(&self) -> &RetryLimit {
&self.max_retries
}
}

#[derive(Debug, Deserialize, Serialize)]
pub struct Settings<T> {
provisioning: Provisioning,
Expand All @@ -368,6 +381,8 @@ pub struct Settings<T> {
homedir: PathBuf,
moby_runtime: MobyRuntime,
certificates: Option<Certificates>,
#[serde(default)]
watchdog: WatchdogSettings,
}

impl<T> Settings<T>
Expand Down Expand Up @@ -432,6 +447,10 @@ where
self.certificates.as_ref()
}

pub fn watchdog(&self) -> &WatchdogSettings {
&self.watchdog
}

pub fn diff_with_cached(&self, path: &Path) -> bool {
fn diff_with_cached_inner<T>(
cached_settings: &Settings<T>,
Expand Down Expand Up @@ -510,6 +529,7 @@ mod tests {
use super::*;
use config::{Config, File, FileFormat};
use edgelet_docker::DockerConfig;
use std::cmp::Ordering;
use std::fs::File as FsFile;
use std::io::Write;
use tempdir::TempDir;
Expand Down Expand Up @@ -830,4 +850,14 @@ mod tests {
let create_options = settings.agent().config().create_options();
assert_eq!(create_options.hostname(), Some("VAluE3"));
}

#[test]
fn watchdog_settings_are_read() {
let settings = Settings::<DockerConfig>::new(Some(Path::new(GOOD_SETTINGS)));
println!("{:?}", settings);
assert!(settings.is_ok());
let s = settings.unwrap();
let watchdog_settings = s.watchdog();
assert_eq!(watchdog_settings.max_retries().compare(3), Ordering::Equal);
}
}
3 changes: 3 additions & 0 deletions edgelet/edgelet-config/test/linux/sample_settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ agent:
auth: {}
hostname: "localhost"

watchdog:
max_retries: 3

# Sets the connection uris for clients
connect:
workload_uri: "http://localhost:8081"
Expand Down
3 changes: 3 additions & 0 deletions edgelet/edgelet-config/test/linux/sample_settings1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ agent:
auth: {}
hostname: "localhost"

watchdog:
max_retries: 3

# Sets the connection uris for clients
connect:
workload_uri: "http://localhost:8081"
Expand Down
3 changes: 3 additions & 0 deletions edgelet/edgelet-config/test/linux/sample_settings2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ agent:
auth: {}
hostname: "localhost"

watchdog:
max_retries: 3

# Sets the connection uris for clients
connect:
workload_uri: "http://localhost:8081"
Expand Down
Loading

0 comments on commit 62f3d44

Please sign in to comment.