Send a message when a build starts, and associate a uuid ('attempt-id') with the build run to help log consumers understand builder failures

This commit is contained in:
Graham Christensen 2018-01-20 11:42:27 -05:00
parent e2696fbe5f
commit 58b34d662f
No known key found for this signature in database
GPG key ID: ACA1C1D120C83D5C
5 changed files with 44 additions and 1 deletions

10
ofborg/Cargo.lock generated
View file

@ -14,6 +14,7 @@ dependencies = [
"serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]] [[package]]
@ -686,6 +687,14 @@ name = "utf8-ranges"
version = "1.0.0" version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "uuid"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]] [[package]]
name = "vcpkg" name = "vcpkg"
version = "0.2.2" version = "0.2.2"
@ -817,6 +826,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2" "checksum url 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa35e768d4daf1d85733418a49fb42e10d7f633e394fccab4ab7aba897053fe2"
"checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f" "checksum utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a1ca13c08c41c9c3e04224ed9ff80461d97e121589ff27c753a16cb10830ae0f"
"checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
"checksum uuid 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7cfec50b0842181ba6e713151b72f4ec84a6a7e2c9c8a8a3ffc37bb1cd16b231"
"checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b" "checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b"
"checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"

View file

@ -9,6 +9,7 @@ env_logger = "0.4.3"
# amqp = { path = "./rust-amqp/" } # for testing patches # amqp = { path = "./rust-amqp/" } # for testing patches
amqp = { git = "https://github.com/grahamc/rust-amqp.git" } amqp = { git = "https://github.com/grahamc/rust-amqp.git" }
md5 = "0.3.5" md5 = "0.3.5"
uuid = { version = "0.4", features = ["v4"] }
fs2 = "0.4.2" fs2 = "0.4.2"
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"

View file

@ -14,6 +14,7 @@ extern crate tempfile;
extern crate amqp; extern crate amqp;
extern crate fs2; extern crate fs2;
extern crate md5; extern crate md5;
extern crate uuid;
pub mod acl; pub mod acl;
pub mod checkout; pub mod checkout;

View file

@ -6,4 +6,12 @@ pub struct BuildLogMsg {
pub output: String, pub output: String,
pub identity: String, pub identity: String,
pub system: String, pub system: String,
pub attempt_id: String,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct BuildLogStart {
pub identity: String,
pub system: String,
pub attempt_id: String,
} }

View file

@ -1,6 +1,9 @@
extern crate amqp; extern crate amqp;
extern crate uuid;
extern crate env_logger; extern crate env_logger;
use uuid::Uuid;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::slice::Iter; use std::slice::Iter;
use std::fs::File; use std::fs::File;
@ -48,16 +51,18 @@ struct JobActions<'a, 'b> {
receiver: &'a mut notifyworker::NotificationReceiver, receiver: &'a mut notifyworker::NotificationReceiver,
job: &'b buildjob::BuildJob, job: &'b buildjob::BuildJob,
line_counter: u64, line_counter: u64,
attempt_id: String,
} }
impl<'a, 'b> JobActions<'a, 'b> { impl<'a, 'b> JobActions<'a, 'b> {
fn new(system: &str, identity: &str, job: &'b buildjob::BuildJob, receiver: &'a mut notifyworker::NotificationReceiver) -> JobActions<'a, 'b> { fn new(system: &str, identity: &str, job: &'b buildjob::BuildJob, receiver: &'a mut notifyworker::NotificationReceiver) -> JobActions<'a, 'b> {
return JobActions { return JobActions {
system: system.to_owned(), system: system.to_owned(),
identity: system.to_owned(), identity: identity.to_owned(),
receiver: receiver, receiver: receiver,
job: job, job: job,
line_counter: 0, line_counter: 0,
attempt_id: format!("{}", Uuid::new_v4()),
}; };
} }
@ -87,12 +92,29 @@ impl<'a, 'b> JobActions<'a, 'b> {
self.tell(worker::Action::Ack); self.tell(worker::Action::Ack);
} }
pub fn log_started(&mut self) {
self.line_counter += 1;
let msg = buildlogmsg::BuildLogStart {
identity: self.identity.clone(),
system: self.system.clone(),
attempt_id: self.attempt_id.clone(),
};
self.tell(worker::publish_serde_action(
Some("logs".to_owned()),
Some("build.log".to_owned()),
&msg
));
}
pub fn log_line(&mut self, line: &str) { pub fn log_line(&mut self, line: &str) {
self.line_counter += 1; self.line_counter += 1;
let msg = buildlogmsg::BuildLogMsg { let msg = buildlogmsg::BuildLogMsg {
identity: self.identity.clone(), identity: self.identity.clone(),
system: self.system.clone(), system: self.system.clone(),
attempt_id: self.attempt_id.clone(),
line_number: self.line_counter, line_number: self.line_counter,
output: line.to_owned(), output: line.to_owned(),
}; };
@ -194,6 +216,7 @@ impl notifyworker::SimpleNotifyWorker for BuildWorker {
job.attrs.clone() job.attrs.clone()
); );
actions.log_started();
let acmd = AsyncCmd::new(cmd); let acmd = AsyncCmd::new(cmd);
let mut spawned = acmd.spawn(); let mut spawned = acmd.spawn();