Skip to content

Commit

Permalink
Merged PR 922856: Log an error when an image pull fails
Browse files Browse the repository at this point in the history
We don't log anything when an image pull fails which makes it hard to diagnose why iotedged is not making progress.
  • Loading branch information
dsajanice committed Jun 26, 2018
1 parent 3bb45e0 commit 3140695
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 14 deletions.
66 changes: 55 additions & 11 deletions edgelet/edgelet-docker/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use base64;
use futures::future;
use futures::prelude::*;
use hyper::{Body, Chunk as HyperChunk, Client};
use log::Level;
use serde_json;
use tokio_core::reactor::Handle;
use url::Url;
Expand All @@ -22,6 +23,7 @@ use edgelet_core::{
LogOptions, Module, ModuleRegistry, ModuleRuntime, ModuleSpec, SystemInfo as CoreSystemInfo,
};
use edgelet_http::UrlConnector;
use edgelet_utils::log_failure;

use error::{Error, Result};
use module::{DockerModule, MODULE_TYPE as DOCKER_MODULE_TYPE};
Expand Down Expand Up @@ -119,7 +121,11 @@ impl ModuleRegistry for DockerModuleRuntime {
let ok = self.client
.image_api()
.image_create(config.image(), "", "", "", "", &creds, "")
.map_err(Error::from);
.map_err(|err| {
let e = Error::from(err);
log_failure(Level::Warn, &e);
e
});
future::Either::A(ok)
})
.unwrap_or_else(|e| future::Either::B(future::err(Error::from(e))));
Expand All @@ -133,7 +139,11 @@ impl ModuleRegistry for DockerModuleRuntime {
.image_api()
.image_delete(fensure_not_empty!(name), false, false)
.map(|_| ())
.map_err(Error::from),
.map_err(|err| {
let e = Error::from(err);
log_failure(Level::Warn, &e);
e
}),
)
}
}
Expand Down Expand Up @@ -178,7 +188,11 @@ impl ModuleRuntime for DockerModuleRuntime {
future::Either::B(future::ok(()))
}
})
.map_err(Error::from);
.map_err(|err| {
let e = Error::from(err);
log_failure(Level::Warn, &e);
e
});
future::Either::A(fut)
})
.unwrap_or_else(|| future::Either::B(future::ok(())));
Expand Down Expand Up @@ -226,7 +240,10 @@ impl ModuleRuntime for DockerModuleRuntime {

match result {
Ok(f) => Box::new(f),
Err(err) => Box::new(future::err(err)),
Err(err) => {
log_failure(Level::Warn, &err);
Box::new(future::err(err))
}
}
}

Expand All @@ -236,7 +253,11 @@ impl ModuleRuntime for DockerModuleRuntime {
self.client
.container_api()
.container_start(fensure_not_empty!(id), "")
.map_err(Error::from)
.map_err(|err| {
let e = Error::from(err);
log_failure(Level::Warn, &e);
e
})
.map(|_| ()),
)
}
Expand All @@ -252,7 +273,11 @@ impl ModuleRuntime for DockerModuleRuntime {
.map(|s| s.as_secs() as i32)
.unwrap_or(WAIT_BEFORE_KILL_SECONDS),
)
.map_err(Error::from)
.map_err(|err| {
let e = Error::from(err);
log_failure(Level::Warn, &e);
e
})
.map(|_| ()),
)
}
Expand All @@ -274,7 +299,11 @@ impl ModuleRuntime for DockerModuleRuntime {
.to_string(),
)
})
.map_err(Error::from),
.map_err(|err| {
let e = Error::from(err);
log_failure(Level::Warn, &e);
e
}),
)
}

Expand All @@ -284,7 +313,11 @@ impl ModuleRuntime for DockerModuleRuntime {
self.client
.container_api()
.container_restart(fensure_not_empty!(id), WAIT_BEFORE_KILL_SECONDS)
.map_err(Error::from)
.map_err(|err| {
let e = Error::from(err);
log_failure(Level::Warn, &e);
e
})
.map(|_| ()),
)
}
Expand All @@ -300,7 +333,11 @@ impl ModuleRuntime for DockerModuleRuntime {
/* force */ true,
/* remove link */ false,
)
.map_err(Error::from)
.map_err(|err| {
let e = Error::from(err);
log_failure(Level::Warn, &e);
e
})
.map(|_| ()),
)
}
Expand Down Expand Up @@ -352,7 +389,10 @@ impl ModuleRuntime for DockerModuleRuntime {

match result {
Ok(f) => Box::new(f),
Err(err) => Box::new(future::err(err)),
Err(err) => {
log_failure(Level::Warn, &err);
Box::new(future::err(err))
}
}
}

Expand All @@ -362,7 +402,11 @@ impl ModuleRuntime for DockerModuleRuntime {
.container_api()
.container_logs(id, options.follow(), true, true, 0, false, tail)
.map(Logs)
.map_err(Error::from);
.map_err(|err| {
let e = Error::from(err);
log_failure(Level::Warn, &e);
e
});
Box::new(result)
}

Expand Down
6 changes: 3 additions & 3 deletions edgelet/iotedged/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn init() {
writeln!(
fmt,
"<{}>{} [{}] - [{}] {}",
syslog_level(&record.level()),
syslog_level(record.level()),
timestamp,
level,
record.target(),
Expand All @@ -41,7 +41,7 @@ pub fn init() {
writeln!(
fmt,
"<{}>{} [{}] - {}",
syslog_level(&record.level()),
syslog_level(record.level()),
timestamp,
level,
record.args()
Expand All @@ -66,7 +66,7 @@ pub fn init_win_log() {
.expect("Could not initialize Windows EventLogger");
}

fn syslog_level(level: &Level) -> i8 {
fn syslog_level(level: Level) -> i8 {
match level {
Level::Error => 3,
Level::Warn => 4,
Expand Down

0 comments on commit 3140695

Please sign in to comment.