nzrd: finally use tracing

This commit is contained in:
snow flurry 2024-08-18 19:56:52 -07:00
parent f63626489d
commit 6fe1ed02aa
8 changed files with 25 additions and 74 deletions

57
Cargo.lock generated
View file

@ -1046,17 +1046,6 @@ dependencies = [
"windows-sys 0.52.0", "windows-sys 0.52.0",
] ]
[[package]]
name = "hostname"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9c7c7c8ac16c798734b8a24560c1362120597c40d5e1459f09498f8f6c8f2ba"
dependencies = [
"cfg-if",
"libc",
"windows",
]
[[package]] [[package]]
name = "http" name = "http"
version = "1.1.0" version = "1.1.0"
@ -1532,15 +1521,6 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]] [[package]]
name = "nzr" name = "nzr"
version = "0.9.0" version = "0.9.0"
@ -1607,7 +1587,6 @@ dependencies = [
"home", "home",
"libc", "libc",
"libsqlite3-sys", "libsqlite3-sys",
"log",
"nix", "nix",
"nzr-api", "nzr-api",
"nzr-virt", "nzr-virt",
@ -1619,12 +1598,13 @@ dependencies = [
"serde_with", "serde_with",
"serde_yaml", "serde_yaml",
"stdext", "stdext",
"syslog",
"tarpc", "tarpc",
"tempfile", "tempfile",
"thiserror", "thiserror",
"tokio", "tokio",
"tokio-serde 0.9.0", "tokio-serde 0.9.0",
"tracing",
"tracing-subscriber",
"trait-variant", "trait-variant",
"uuid", "uuid",
"zerocopy", "zerocopy",
@ -2309,18 +2289,6 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394"
[[package]]
name = "syslog"
version = "7.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "019f1500a13379b7d051455df397c75770de6311a7a188a699499502704d9f10"
dependencies = [
"hostname",
"libc",
"log",
"time",
]
[[package]] [[package]]
name = "tabled" name = "tabled"
version = "0.15.0" version = "0.15.0"
@ -2444,9 +2412,7 @@ checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885"
dependencies = [ dependencies = [
"deranged", "deranged",
"itoa", "itoa",
"libc",
"num-conv", "num-conv",
"num_threads",
"powerfmt", "powerfmt",
"serde", "serde",
"time-core", "time-core",
@ -2960,25 +2926,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be"
dependencies = [
"windows-core",
"windows-targets",
]
[[package]]
name = "windows-core"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets",
]
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.42.0" version = "0.42.0"

View file

@ -26,9 +26,8 @@ tarpc = { version = "0.34", features = [
] } ] }
# Logging # Logging
# TODO: switch to tracing? tracing = "0.1"
log = "0.4.17" tracing-subscriber = "0.3"
syslog = "7"
# Database # Database
diesel = { version = "2.2", features = [ diesel = { version = "2.2", features = [

View file

@ -9,10 +9,10 @@ use super::*;
use crate::ctrl::vm::Progress; use crate::ctrl::vm::Progress;
use crate::ctx::Context; use crate::ctx::Context;
use crate::model::{Instance, Subnet}; use crate::model::{Instance, Subnet};
use log::{debug, info, warn};
use nzr_api::net::mac::MacAddr; use nzr_api::net::mac::MacAddr;
use nzr_api::{args, model, nzr_event}; use nzr_api::{args, model, nzr_event};
use std::sync::Arc; use std::sync::Arc;
use tracing::{debug, info, warn};
const VIRT_MAC_OUI: &[u8] = &[0x02, 0xf1, 0x0f]; const VIRT_MAC_OUI: &[u8] = &[0x02, 0xf1, 0x0f];

View file

@ -3,7 +3,6 @@ use diesel::{
SqliteConnection, SqliteConnection,
}; };
use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness}; use diesel_migrations::{embed_migrations, EmbeddedMigrations, MigrationHarness};
use log::trace;
use nzr_virt::{vol, Connection}; use nzr_virt::{vol, Connection};
use std::ops::Deref; use std::ops::Deref;
use thiserror::Error; use thiserror::Error;
@ -67,7 +66,7 @@ impl InnerCtx {
baseimg: conn.get_pool(&config.storage.base_image_pool).await?, baseimg: conn.get_pool(&config.storage.base_image_pool).await?,
}; };
trace!("Connecting to database"); tracing::trace!("Connecting to database");
let db_uri = config.db_uri.clone(); let db_uri = config.db_uri.clone();
let sqldb = tokio::task::spawn_blocking(|| { let sqldb = tokio::task::spawn_blocking(|| {
let manager = ConnectionManager::<SqliteConnection>::new(db_uri); let manager = ConnectionManager::<SqliteConnection>::new(db_uri);
@ -78,7 +77,7 @@ impl InnerCtx {
.unwrap()?; .unwrap()?;
{ {
trace!("Running pending migrations"); tracing::trace!("Running pending migrations");
let mut conn = sqldb.get()?; let mut conn = sqldb.get()?;
tokio::task::spawn_blocking(move || { tokio::task::spawn_blocking(move || {
conn.run_pending_migrations(MIGRATIONS) conn.run_pending_migrations(MIGRATIONS)

View file

@ -4,23 +4,29 @@ mod ctx;
mod model; mod model;
mod rpc; mod rpc;
use log::LevelFilter;
use log::*;
use nzr_api::config;
use std::str::FromStr; use std::str::FromStr;
use nzr_api::config;
#[tokio::main(flavor = "multi_thread")] #[tokio::main(flavor = "multi_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> { async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cfg: config::Config = config::Config::figment().extract()?; let cfg: config::Config = config::Config::figment().extract()?;
let ctx = ctx::Context::new(cfg).await?; let ctx = ctx::Context::new(cfg).await?;
syslog::init_unix( let mut bad_loglevel = false;
syslog::Facility::LOG_DAEMON, let log_level = tracing::Level::from_str(&ctx.config.log_level).unwrap_or_else(|_| {
LevelFilter::from_str(ctx.config.log_level.as_str())?, bad_loglevel = true;
)?; tracing::Level::WARN
});
tracing_subscriber::fmt().with_max_level(log_level).init();
if bad_loglevel {
tracing::warn!("Couldn't parse log level from config, defaulting to {log_level}");
}
if let Err(err) = rpc::serve(ctx.clone()).await { if let Err(err) = rpc::serve(ctx.clone()).await {
error!("Error from RPC: {}", err); tracing::error!("Error from RPC: {}", err);
} }
Ok(()) Ok(())

View file

@ -404,7 +404,7 @@ impl Subnet {
// the API. // the API.
Ok(addr) => Some(addr), Ok(addr) => Some(addr),
Err(err) => { Err(err) => {
log::error!( tracing::error!(
"Error parsing DNS server '{}' for {}: {}", "Error parsing DNS server '{}' for {}: {}",
s, s,
&self.name, &self.name,
@ -416,7 +416,7 @@ impl Subnet {
.collect(), .collect(),
domain_name: self.domain_name.as_ref().map(|s| { domain_name: self.domain_name.as_ref().map(|s| {
Name::from_str(s).unwrap_or_else(|e| { Name::from_str(s).unwrap_or_else(|e| {
log::error!("Error parsing DNS name for {}: {}", &self.name, e); tracing::error!("Error parsing DNS name for {}: {}", &self.name, e);
Name::default() Name::default()
}) })
}), }),

View file

@ -48,7 +48,7 @@ impl<'a, T: Transactable> Drop for Transaction<'a, T> {
let ctx = self.ctx.clone(); let ctx = self.ctx.clone();
tokio::spawn(async move { tokio::spawn(async move {
if let Err(err) = inner.undo_tx(&ctx).await { if let Err(err) = inner.undo_tx(&ctx).await {
log::error!("Error undoing transaction: {err}"); tracing::error!("Error undoing transaction: {err}");
} }
}); });
} }

View file

@ -13,8 +13,8 @@ use uuid::Uuid;
use crate::cmd; use crate::cmd;
use crate::ctx::Context; use crate::ctx::Context;
use crate::model::{Instance, SshPubkey, Subnet}; use crate::model::{Instance, SshPubkey, Subnet};
use log::*;
use std::collections::HashMap; use std::collections::HashMap;
use tracing::*;
#[derive(Clone)] #[derive(Clone)]
pub struct NzrServer { pub struct NzrServer {