Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite logging. #859

Merged
merged 6 commits into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions Cargo.lock

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

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ clap = { version = "4", features = [ "wrap_help", "cargo", "derive" ]
crossbeam-queue = "0.3.1"
crossbeam-utils = "0.8.1"
dirs = "4.0.0"
fern = "0.6.0"
form_urlencoded = "1.0"
futures = "0.3.4"
hyper = { version = "0.14", features = [ "server", "stream" ] }
listenfd = "1"
log = "0.4.8"
log-reroute = "0.1.5"
num_cpus = "1.12.0"
once_cell = "1"
pin-project-lite = "0.2.4"
rand = "0.8.1"
reqwest = { version = "0.11.0", default-features = false, features = ["blocking", "rustls-tls" ] }
Expand Down
4 changes: 4 additions & 0 deletions doc/manual/source/manual-page.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1534,6 +1534,10 @@ SIGUSR1: Reload TALs and restart validation
that succeeds, restart validation. If loading the TALs fails, Routinator
will exit.

SIGUSR2: Re-open log file
When receiving SIGUSR2 and logging to a file is enabled, Routinator will
re-open the log file. If this fails, Routinator will exit.

Exit Status
-----------

Expand Down
2 changes: 1 addition & 1 deletion doc/manual/source/prometheus-metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ file of the RRDP repository, or the base URI of the rsync repository.
manifest’s own CRL is considered a *stray*.
* ``ca_cert`` - The number of Certificate Authority (CA) certificates with
the state *valid*.
* ``router_cert`` - The number of End Entity (EE) certificates found to be
* ``router_cert`` - The number of router certificates found to be
present and *valid*. This only refers to such certificates included as
stand-alone files which are BGPsec router certificates.
* ``roa`` - The number of :term:`Route Origin Attestations <Route Origin
Expand Down
72 changes: 52 additions & 20 deletions src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use std::str::FromStr;
use std::sync::mpsc;
use std::sync::Arc;
use std::sync::mpsc::RecvTimeoutError;
use std::time::Duration;
use std::time::{Duration, Instant};
#[cfg(feature = "rta")] use bytes::Bytes;
use clap::{Arg, Args, ArgAction, ArgMatches, FromArgMatches, Parser};
use log::{error, info};
Expand Down Expand Up @@ -275,25 +275,46 @@ impl Server {
if let Some(log) = log.as_ref() {
log.flush();
}
match sig_rx.recv_timeout(timeout) {
Ok(UserSignal::ReloadTals) => {
match validation.reload_tals() {
Ok(_) => {
info!("Reloaded TALs at user request.");
},
Err(_) => {
error!(
"Fatal: Reloading TALs failed, \
shutting down."
);
break Err(Failed);

// Because we don’t want to restart validation upon
// log rotation, we need to loop here. But then we need
// to recalculate timeout.
let deadline = Instant::now() + timeout;
let end = loop {
let timeout = deadline.saturating_duration_since(
Instant::now()
);
match sig_rx.recv_timeout(timeout) {
Ok(UserSignal::ReloadTals) => {
match validation.reload_tals() {
Ok(_) => {
info!("Reloaded TALs at user request.");
break None;
},
Err(_) => {
error!(
"Fatal: Reloading TALs failed, \
shutting down."
);
break Some(Err(Failed));
}
}
}
Ok(UserSignal::RotateLog) => {
if process.rotate_log().is_err() {
break Some(Err(Failed));
}
}
Err(RecvTimeoutError::Timeout) => {
break None;
}
Err(RecvTimeoutError::Disconnected) => {
break Some(Ok(()));
}
}
Err(RecvTimeoutError::Timeout) => { }
Err(RecvTimeoutError::Disconnected) => {
break Ok(());
}
};
if let Some(end) = end {
break end;
}
};
// An error here means the receiver is gone which is fine.
Expand Down Expand Up @@ -1219,6 +1240,7 @@ impl Man {
#[allow(dead_code)]
enum UserSignal {
ReloadTals,
RotateLog,
}

/// Wait for the next validation run or a user telling us to quit or reload.
Expand All @@ -1227,6 +1249,7 @@ enum UserSignal {
#[cfg(unix)]
struct SignalListener {
usr1: Signal,
usr2: Signal,
}

#[cfg(unix)]
Expand All @@ -1239,16 +1262,25 @@ impl SignalListener {
error!("Attaching to signal USR1 failed: {}", err);
return Err(Failed)
}
}
},
usr2: match signal(SignalKind::user_defined2()) {
Ok(usr2) => usr2,
Err(err) => {
error!("Attaching to signal USR2 failed: {}", err);
return Err(Failed)
}
},
})
}

/// Waits for the next thing to do.
///
/// Returns what to do.
pub async fn next(&mut self) -> UserSignal {
self.usr1.recv().await;
UserSignal::ReloadTals
tokio::select! {
_ = self.usr1.recv() => UserSignal::ReloadTals,
_ = self.usr2.recv() => UserSignal::RotateLog,
}
}
}

Expand Down
Loading