log -> tracing

This commit is contained in:
Daiderd Jordan 2020-05-01 18:47:44 +02:00
parent a2e5dad97c
commit 35e08cb5d1
No known key found for this signature in database
GPG key ID: D02435D05B810C96
32 changed files with 91 additions and 48 deletions

View file

@ -4,6 +4,8 @@ use std::process::{Child, Command, ExitStatus, Stdio};
use std::sync::mpsc::{self, sync_channel, Receiver, SyncSender}; use std::sync::mpsc::{self, sync_channel, Receiver, SyncSender};
use std::thread::{self, JoinHandle}; use std::thread::{self, JoinHandle};
use tracing::{debug, error, info};
// Specifically set to fall under 1/2 of the AMQP library's // Specifically set to fall under 1/2 of the AMQP library's
// SyncSender limitation. // SyncSender limitation.
const OUT_CHANNEL_BUFFER_SIZE: usize = 30; const OUT_CHANNEL_BUFFER_SIZE: usize = 30;

View file

@ -1,4 +1,3 @@
use log::{info, log};
use ofborg::commentparser; use ofborg::commentparser;
use ofborg::config; use ofborg::config;
use ofborg::easyamqp; use ofborg::easyamqp;
@ -8,6 +7,8 @@ use ofborg::worker;
use std::env; use std::env;
use tracing::info;
fn main() { fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref()); let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log(); ofborg::setup_log();

View file

@ -3,7 +3,7 @@ use std::error::Error;
use std::path::Path; use std::path::Path;
use async_std::task; use async_std::task;
use log::{info, log, warn}; use tracing::{info, warn};
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
use ofborg::easylapin; use ofborg::easylapin;

View file

@ -1,5 +1,4 @@
use amqp::Basic; use amqp::Basic;
use log::{info, log};
use ofborg::config; use ofborg::config;
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
use ofborg::tasks; use ofborg::tasks;
@ -7,6 +6,8 @@ use ofborg::worker;
use std::env; use std::env;
use tracing::info;
fn main() { fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref()); let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log(); ofborg::setup_log();

View file

@ -1,5 +1,3 @@
use amqp::Basic;
use log::{info, log};
use ofborg::config; use ofborg::config;
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
use ofborg::tasks; use ofborg::tasks;
@ -7,6 +5,9 @@ use ofborg::worker;
use std::env; use std::env;
use amqp::Basic;
use tracing::info;
fn main() { fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref()); let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log(); ofborg::setup_log();

View file

@ -1,5 +1,3 @@
use amqp::Basic;
use log::{info, log};
use ofborg::config; use ofborg::config;
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
use ofborg::tasks; use ofborg::tasks;
@ -7,6 +5,9 @@ use ofborg::worker;
use std::env; use std::env;
use amqp::Basic;
use tracing::info;
fn main() { fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref()); let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log(); ofborg::setup_log();

View file

@ -1,4 +1,3 @@
use log::{info, log};
use ofborg::config; use ofborg::config;
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
use ofborg::tasks; use ofborg::tasks;
@ -7,6 +6,8 @@ use ofborg::worker;
use std::env; use std::env;
use std::path::PathBuf; use std::path::PathBuf;
use tracing::info;
fn main() { fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref()); let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log(); ofborg::setup_log();

View file

@ -1,4 +1,3 @@
use log::{info, log};
use ofborg::config; use ofborg::config;
use ofborg::easyamqp; use ofborg::easyamqp;
use ofborg::message::{buildjob, Pr, Repo}; use ofborg::message::{buildjob, Pr, Repo};
@ -9,6 +8,8 @@ use std::env;
use std::thread; use std::thread;
use std::time::Duration; use std::time::Duration;
use tracing::info;
fn main() { fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref()); let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log(); ofborg::setup_log();

View file

@ -1,5 +1,3 @@
use amqp::Basic;
use log::{error, info, log};
use ofborg::checkout; use ofborg::checkout;
use ofborg::config; use ofborg::config;
use ofborg::easyamqp::{self, ChannelExt, ConsumerExt}; use ofborg::easyamqp::{self, ChannelExt, ConsumerExt};
@ -11,6 +9,9 @@ use std::env;
use std::path::Path; use std::path::Path;
use std::process; use std::process;
use amqp::Basic;
use tracing::{error, info};
fn main() { fn main() {
let memory_info = sys_info::mem_info().expect("Unable to get memory information from OS"); let memory_info = sys_info::mem_info().expect("Unable to get memory information from OS");

View file

@ -1,12 +1,13 @@
use amqp::Basic;
use hyper::server::{Request, Response, Server};
use log::{info, log};
use ofborg::easyamqp::{ChannelExt, ConsumerExt}; use ofborg::easyamqp::{ChannelExt, ConsumerExt};
use ofborg::{config, easyamqp, stats, tasks, worker}; use ofborg::{config, easyamqp, stats, tasks, worker};
use std::env; use std::env;
use std::thread; use std::thread;
use amqp::Basic;
use hyper::server::{Request, Response, Server};
use tracing::info;
fn main() { fn main() {
let cfg = config::load(env::args().nth(1).unwrap().as_ref()); let cfg = config::load(env::args().nth(1).unwrap().as_ref());
ofborg::setup_log(); ofborg::setup_log();

View file

@ -6,6 +6,8 @@ use std::io::{Error, ErrorKind};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use tracing::info;
pub struct CachedCloner { pub struct CachedCloner {
root: PathBuf, root: PathBuf,
} }

View file

@ -6,6 +6,8 @@ use std::io::{Error, ErrorKind};
use std::path::PathBuf; use std::path::PathBuf;
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use tracing::{debug, info, warn};
pub struct Lock { pub struct Lock {
lock: Option<fs::File>, lock: Option<fs::File>,
} }

View file

@ -1,4 +1,5 @@
use nom::types::CompleteStr; use nom::types::CompleteStr;
use tracing::warn;
pub fn parse(text: &str) -> Option<Vec<Instruction>> { pub fn parse(text: &str) -> Option<Vec<Instruction>> {
let instructions: Vec<Instruction> = text let instructions: Vec<Instruction> = text

View file

@ -1,3 +1,5 @@
use tracing::warn;
pub struct CommitStatus<'a> { pub struct CommitStatus<'a> {
api: hubcaps::statuses::Statuses<'a>, api: hubcaps::statuses::Statuses<'a>,
sha: String, sha: String,

View file

@ -1,16 +1,17 @@
use crate::acl; use crate::acl;
use crate::nix::Nix; use crate::nix::Nix;
use hubcaps::{Credentials, Github, InstallationTokenGenerator, JWTCredentials};
use hyper::net::HttpsConnector;
use hyper::Client;
use hyper_native_tls::NativeTlsClient;
use std::collections::HashMap; use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use std::io::Read; use std::io::Read;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use hubcaps::{Credentials, Github, InstallationTokenGenerator, JWTCredentials};
use hyper::net::HttpsConnector;
use hyper::Client;
use hyper_native_tls::NativeTlsClient;
use tracing::{debug, error, info, warn};
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct Config { pub struct Config {
pub runner: RunnerConfig, pub runner: RunnerConfig,

View file

@ -2,6 +2,7 @@ use crate::config::RabbitMQConfig;
use crate::ofborg; use crate::ofborg;
use amqp::Basic; use amqp::Basic;
use tracing::info;
pub struct ConsumeConfig { pub struct ConsumeConfig {
/// Specifies the name of the queue to consume from. /// Specifies the name of the queue to consume from.

View file

@ -21,6 +21,7 @@ use lapin::types::{AMQPValue, FieldTable};
use lapin::{ use lapin::{
BasicProperties, Channel, CloseOnDrop, Connection, ConnectionProperties, ExchangeKind, BasicProperties, Channel, CloseOnDrop, Connection, ConnectionProperties, ExchangeKind,
}; };
use tracing::debug;
pub fn from_config(cfg: &RabbitMQConfig) -> Result<CloseOnDrop<Connection>, lapin::Error> { pub fn from_config(cfg: &RabbitMQConfig) -> Result<CloseOnDrop<Connection>, lapin::Error> {
let mut props = FieldTable::default(); let mut props = FieldTable::default();
@ -146,7 +147,7 @@ impl<W: SimpleNotifyWorker + 'static> ConsumerExt<W> for NotifyChannel {
let mut chan = self.0; let mut chan = self.0;
Ok(Box::pin(async move { Ok(Box::pin(async move {
while let Some(Ok(deliver)) = consumer.next().await { while let Some(Ok(deliver)) = consumer.next().await {
log::debug!("delivery {}", deliver.delivery_tag); debug!("delivery {}", deliver.delivery_tag);
let mut receiver = ChannelNotificationReceiver { let mut receiver = ChannelNotificationReceiver {
channel: &mut chan, channel: &mut chan,
deliver: &deliver, deliver: &deliver,
@ -174,25 +175,25 @@ async fn action_deliver(
) -> Result<(), lapin::Error> { ) -> Result<(), lapin::Error> {
match action { match action {
Action::Ack => { Action::Ack => {
log::debug!("action ack"); debug!("action ack");
chan.basic_ack(deliver.delivery_tag, BasicAckOptions::default()) chan.basic_ack(deliver.delivery_tag, BasicAckOptions::default())
.await .await
} }
Action::NackRequeue => { Action::NackRequeue => {
log::debug!("action nack requeue"); debug!("action nack requeue");
let mut opts = BasicNackOptions::default(); let mut opts = BasicNackOptions::default();
opts.requeue = true; opts.requeue = true;
chan.basic_nack(deliver.delivery_tag, opts).await chan.basic_nack(deliver.delivery_tag, opts).await
} }
Action::NackDump => { Action::NackDump => {
log::debug!("action nack dump"); debug!("action nack dump");
chan.basic_nack(deliver.delivery_tag, BasicNackOptions::default()) chan.basic_nack(deliver.delivery_tag, BasicNackOptions::default())
.await .await
} }
Action::Publish(mut msg) => { Action::Publish(mut msg) => {
let exch = msg.exchange.take().unwrap_or_else(|| "".to_owned()); let exch = msg.exchange.take().unwrap_or_else(|| "".to_owned());
let key = msg.routing_key.take().unwrap_or_else(|| "".to_owned()); let key = msg.routing_key.take().unwrap_or_else(|| "".to_owned());
log::debug!("action publish {}", exch); debug!("action publish {}", exch);
let mut props = BasicProperties::default().with_delivery_mode(2); // persistent. let mut props = BasicProperties::default().with_delivery_mode(2); // persistent.

View file

@ -8,13 +8,11 @@
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
#[macro_use]
extern crate log;
#[macro_use] #[macro_use]
extern crate nom; extern crate nom;
use std::env; use tracing_subscriber::prelude::*;
use tracing_subscriber::EnvFilter;
pub mod acl; pub mod acl;
pub mod asynccmd; pub mod asynccmd;
@ -90,11 +88,15 @@ pub mod ofborg {
} }
pub fn setup_log() { pub fn setup_log() {
if env::var("RUST_LOG").is_err() { let fmt_layer = tracing_subscriber::fmt::layer();
env::set_var("RUST_LOG", "info"); let filter_layer = EnvFilter::try_from_default_env()
env_logger::init().unwrap(); .or_else(|_| EnvFilter::try_new("info"))
info!("Defaulting RUST_LOG environment variable to info"); .unwrap();
} else {
env_logger::init().unwrap(); tracing_subscriber::registry()
} .with(filter_layer)
.with(fmt_layer)
.init();
tracing::info!("Logging configured");
} }

View file

@ -8,6 +8,8 @@ use std::fs::{self, File};
use std::io::{self, BufRead, BufReader, Read, Seek, SeekFrom, Write}; use std::io::{self, BufRead, BufReader, Read, Seek, SeekFrom, Write};
use std::path::PathBuf; use std::path::PathBuf;
use tracing::warn;
pub struct HydraNixEnv { pub struct HydraNixEnv {
path: PathBuf, path: PathBuf,
nix: nix::Nix, nix: nix::Nix,

View file

@ -6,6 +6,8 @@ use std::collections::{HashMap, HashSet};
use std::io::BufRead; use std::io::BufRead;
use std::path::PathBuf; use std::path::PathBuf;
use tracing::{debug, info, trace};
pub struct OutPathDiff { pub struct OutPathDiff {
calculator: HydraNixEnv, calculator: HydraNixEnv,
pub original: Option<(PackageOutPaths, EvaluationStats)>, pub original: Option<(PackageOutPaths, EvaluationStats)>,

View file

@ -4,6 +4,8 @@ use crate::tasks;
use std::collections::HashMap; use std::collections::HashMap;
use tracing::info;
pub struct StdenvTagger { pub struct StdenvTagger {
possible: Vec<String>, possible: Vec<String>,
selected: Vec<String>, selected: Vec<String>,

View file

@ -6,10 +6,11 @@ use crate::nix;
use crate::notifyworker; use crate::notifyworker;
use crate::worker; use crate::worker;
use uuid::Uuid;
use std::collections::VecDeque; use std::collections::VecDeque;
use uuid::Uuid;
use tracing::{error, info};
pub struct BuildWorker { pub struct BuildWorker {
cloner: checkout::CachedCloner, cloner: checkout::CachedCloner,
nix: nix::Nix, nix: nix::Nix,

View file

@ -16,16 +16,17 @@ use crate::tasks::eval::{
}; };
use crate::tasks::evaluate::{make_gist, update_labels}; use crate::tasks::evaluate::{make_gist, update_labels};
use std::collections::HashMap;
use std::path::Path;
use chrono::Utc; use chrono::Utc;
use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output}; use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output};
use hubcaps::gists::Gists; use hubcaps::gists::Gists;
use hubcaps::issues::{Issue, IssueRef}; use hubcaps::issues::{Issue, IssueRef};
use hubcaps::repositories::Repository; use hubcaps::repositories::Repository;
use tracing::warn;
use uuid::Uuid; use uuid::Uuid;
use std::collections::HashMap;
use std::path::Path;
pub struct NixpkgsStrategy<'a> { pub struct NixpkgsStrategy<'a> {
job: &'a EvaluationJob, job: &'a EvaluationJob,
pull: &'a hubcaps::pulls::PullRequest<'a>, pull: &'a hubcaps::pulls::PullRequest<'a>,

View file

@ -3,6 +3,8 @@ use crate::nix;
use std::path::PathBuf; use std::path::PathBuf;
use tracing::{info, warn};
enum StdenvFrom { enum StdenvFrom {
Before, Before,
After, After,

View file

@ -11,15 +11,16 @@ use crate::systems;
use crate::tasks::eval; use crate::tasks::eval;
use crate::worker; use crate::worker;
use hubcaps::checks::CheckRunOptions;
use hubcaps::gists::Gists;
use hubcaps::issues::Issue;
use std::collections::HashMap; use std::collections::HashMap;
use std::path::Path; use std::path::Path;
use std::sync::RwLock; use std::sync::RwLock;
use std::time::Instant; use std::time::Instant;
use hubcaps::checks::CheckRunOptions;
use hubcaps::gists::Gists;
use hubcaps::issues::Issue;
use tracing::{error, info, warn};
pub struct EvaluationWorker<E> { pub struct EvaluationWorker<E> {
cloner: checkout::CachedCloner, cloner: checkout::CachedCloner,
nix: nix::Nix, nix: nix::Nix,

View file

@ -3,6 +3,8 @@ use crate::ghevent;
use crate::message::{evaluationjob, Pr, Repo}; use crate::message::{evaluationjob, Pr, Repo};
use crate::worker; use crate::worker;
use tracing::info;
pub struct EvaluationFilterWorker { pub struct EvaluationFilterWorker {
acl: acl::ACL, acl: acl::ACL,
} }

View file

@ -4,6 +4,7 @@ use crate::ghevent;
use crate::message::{buildjob, evaluationjob, Pr, Repo}; use crate::message::{buildjob, evaluationjob, Pr, Repo};
use crate::worker; use crate::worker;
use tracing::{error, info};
use uuid::Uuid; use uuid::Uuid;
pub struct GitHubCommentWorker { pub struct GitHubCommentWorker {

View file

@ -6,6 +6,7 @@ use crate::worker;
use chrono::{DateTime, Utc}; use chrono::{DateTime, Utc};
use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output}; use hubcaps::checks::{CheckRunOptions, CheckRunState, Conclusion, Output};
use tracing::info;
pub struct GitHubCommentPoster { pub struct GitHubCommentPoster {
github_vend: GithubAppVendingMachine, github_vend: GithubAppVendingMachine,

View file

@ -3,12 +3,13 @@ use crate::message::buildresult::BuildResult;
use crate::worker; use crate::worker;
use crate::writetoline::LineWriter; use crate::writetoline::LineWriter;
use lru_cache::LruCache;
use std::fs::{self, File, OpenOptions}; use std::fs::{self, File, OpenOptions};
use std::io::Write; use std::io::Write;
use std::path::{Component, PathBuf}; use std::path::{Component, PathBuf};
use lru_cache::LruCache;
use tracing::warn;
#[derive(Eq, PartialEq, Hash, Debug, Clone)] #[derive(Eq, PartialEq, Hash, Debug, Clone)]
pub struct LogFrom { pub struct LogFrom {
routing_key: String, routing_key: String,

View file

@ -1,6 +1,8 @@
use crate::stats; use crate::stats;
use crate::worker; use crate::worker;
use tracing::error;
pub struct StatCollectorWorker<E> { pub struct StatCollectorWorker<E> {
events: E, events: E,
collector: stats::MetricCollector, collector: stats::MetricCollector,

View file

@ -2,6 +2,8 @@ use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use tracing::debug;
pub struct TestScratch { pub struct TestScratch {
root: PathBuf, root: PathBuf,
} }

View file

@ -1,8 +1,9 @@
use std::marker::Send;
use amqp::protocol::basic::{BasicProperties, Deliver}; use amqp::protocol::basic::{BasicProperties, Deliver};
use amqp::Basic; use amqp::Basic;
use serde::Serialize; use serde::Serialize;
use tracing::error;
use std::marker::Send;
pub struct Worker<T: SimpleWorker> { pub struct Worker<T: SimpleWorker> {
internal: T, internal: T,