Thread naming and display (#2190)

* sometimes handlers fail
* enums are better than strings
* clippyisms
This commit is contained in:
James Hodgkinson 2023-10-08 13:08:46 +10:00 committed by GitHub
parent 48979b8e1a
commit 19f9fde012
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 80 additions and 40 deletions

View file

@ -168,7 +168,7 @@ impl AdminActor {
} }
} }
} }
info!("Stopped AdminActor"); info!("Stopped {}", super::TaskName::AdminSocket);
}); });
Ok(handle) Ok(handle)
} }

View file

@ -312,7 +312,7 @@ pub async fn create_https_server(
}; };
#[cfg(feature = "otel")] #[cfg(feature = "otel")]
opentelemetry::global::shutdown_tracer_provider(); opentelemetry::global::shutdown_tracer_provider();
info!("Stopped WebAcceptorActor"); info!("Stopped {}", super::TaskName::HttpsServer);
})) }))
} }

View file

@ -47,7 +47,7 @@ impl IntervalActor {
} }
} }
info!("Stopped IntervalActor"); info!("Stopped {}", super::TaskName::IntervalActor);
}) })
} }
@ -149,7 +149,7 @@ impl IntervalActor {
} }
} }
} }
info!("Stopped OnlineBackupActor"); info!("Stopped {}", super::TaskName::BackupActor);
}); });
Ok(handle) Ok(handle)

View file

@ -150,7 +150,7 @@ async fn tls_acceptor(
} }
} }
} }
info!("Stopped LdapAcceptorActor"); info!("Stopped {}", super::TaskName::LdapActor);
} }
pub(crate) async fn create_ldap_server( pub(crate) async fn create_ldap_server(

View file

@ -34,6 +34,7 @@ mod interval;
mod ldaps; mod ldaps;
mod repl; mod repl;
use std::fmt::{Display, Formatter};
use std::path::Path; use std::path::Path;
use std::sync::Arc; use std::sync::Arc;
@ -49,6 +50,7 @@ use kanidmd_lib::utils::{duration_from_epoch_now, touch_file_or_quit};
use libc::umask; use libc::umask;
use tokio::sync::broadcast; use tokio::sync::broadcast;
use tokio::task::JoinHandle;
use crate::actors::v1_read::QueryServerReadV1; use crate::actors::v1_read::QueryServerReadV1;
use crate::actors::v1_write::QueryServerWriteV1; use crate::actors::v1_write::QueryServerWriteV1;
@ -647,12 +649,42 @@ pub enum CoreAction {
Shutdown, Shutdown,
} }
pub(crate) enum TaskName {
AdminSocket,
AuditdActor,
BackupActor,
DelayedActionActor,
HttpsServer,
IntervalActor,
LdapActor,
Replication,
}
impl Display for TaskName {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
TaskName::AdminSocket => "Admin Socket",
TaskName::AuditdActor => "Auditd Actor",
TaskName::BackupActor => "Backup Actor",
TaskName::DelayedActionActor => "Delayed Action Actor",
TaskName::HttpsServer => "HTTPS Server",
TaskName::IntervalActor => "Interval Actor",
TaskName::LdapActor => "LDAP Acceptor Actor",
TaskName::Replication => "Replication",
}
.to_string()
)
}
}
pub struct CoreHandle { pub struct CoreHandle {
clean_shutdown: bool, clean_shutdown: bool,
tx: broadcast::Sender<CoreAction>, tx: broadcast::Sender<CoreAction>,
/// This stores a name for the handle, and the handle itself so we can tell which failed/succeeded at the end.
handles: Vec<tokio::task::JoinHandle<()>>, handles: Vec<(TaskName, tokio::task::JoinHandle<()>)>,
// interval_handle: tokio::task::JoinHandle<()>,
} }
impl CoreHandle { impl CoreHandle {
@ -663,9 +695,13 @@ impl CoreHandle {
} }
// Wait on the handles. // Wait on the handles.
while let Some(handle) = self.handles.pop() { while let Some((handle_name, handle)) = self.handles.pop() {
if handle.await.is_err() { if let Err(error) = handle.await {
eprintln!("A task failed to join"); eprintln!(
"Task {} failed to finish: {:?}",
handle_name,
error
);
} }
} }
@ -700,8 +736,8 @@ pub async fn create_server_core(
} }
info!( info!(
"Starting kanidm with configuration: {} {}", "Starting kanidm with {}configuration: {}",
if config_test { "TEST" } else { "" }, if config_test { "TEST " } else { "" },
config config
); );
// Setup umask, so that every we touch or create is secure. // Setup umask, so that every we touch or create is secure.
@ -820,7 +856,7 @@ pub async fn create_server_core(
} }
} }
} }
info!("Stopped DelayedActionActor"); info!("Stopped {}", TaskName::DelayedActionActor);
}); });
let mut broadcast_rx = broadcast_tx.subscribe(); let mut broadcast_rx = broadcast_tx.subscribe();
@ -847,7 +883,7 @@ pub async fn create_server_core(
} }
} }
} }
info!("Stopped AuditdActor"); info!("Stopped {}", TaskName::AuditdActor);
}); });
// Setup timed events associated to the write thread // Setup timed events associated to the write thread
@ -919,7 +955,7 @@ pub async fn create_server_core(
}; };
let maybe_http_acceptor_handle = if config_test { let maybe_http_acceptor_handle = if config_test {
admin_info!("this config rocks! 🪨 "); admin_info!("This config rocks! 🪨 ");
None None
} else { } else {
let h: tokio::task::JoinHandle<()> = match https::create_https_server( let h: tokio::task::JoinHandle<()> = match https::create_https_server(
@ -963,26 +999,30 @@ pub async fn create_server_core(
None None
}; };
let mut handles = vec![interval_handle, delayed_handle, auditd_handle]; let mut handles: Vec<(TaskName, JoinHandle<()>)> = vec![
(TaskName::IntervalActor, interval_handle),
(TaskName::DelayedActionActor, delayed_handle),
(TaskName::AuditdActor, auditd_handle),
];
if let Some(backup_handle) = maybe_backup_handle { if let Some(backup_handle) = maybe_backup_handle {
handles.push(backup_handle) handles.push((TaskName::BackupActor, backup_handle))
} }
if let Some(admin_sock_handle) = maybe_admin_sock_handle { if let Some(admin_sock_handle) = maybe_admin_sock_handle {
handles.push(admin_sock_handle) handles.push((TaskName::AdminSocket, admin_sock_handle))
} }
if let Some(ldap_handle) = maybe_ldap_acceptor_handle { if let Some(ldap_handle) = maybe_ldap_acceptor_handle {
handles.push(ldap_handle) handles.push((TaskName::LdapActor, ldap_handle))
} }
if let Some(http_handle) = maybe_http_acceptor_handle { if let Some(http_handle) = maybe_http_acceptor_handle {
handles.push(http_handle) handles.push((TaskName::HttpsServer, http_handle))
} }
if let Some(repl_handle) = maybe_repl_handle { if let Some(repl_handle) = maybe_repl_handle {
handles.push(repl_handle) handles.push((TaskName::Replication, repl_handle))
} }
Ok(CoreHandle { Ok(CoreHandle {

View file

@ -904,5 +904,5 @@ async fn repl_acceptor(
} }
} }
info!("Stopped Replication Acceptor"); info!("Stopped {}", super::TaskName::Replication);
} }

View file

@ -78,7 +78,7 @@ macro_rules! try_from_entry {
let mail = $value let mail = $value
.get_ava_iter_mail(Attribute::Mail) .get_ava_iter_mail(Attribute::Mail)
.map(|i| i.map(str::to_string).collect()) .map(|i| i.map(str::to_string).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let valid_from = $value.get_ava_single_datetime(Attribute::AccountValidFrom); let valid_from = $value.get_ava_single_datetime(Attribute::AccountValidFrom);

View file

@ -96,7 +96,7 @@ macro_rules! try_from_entry {
let sshkeys = $value let sshkeys = $value
.get_ava_iter_sshpubkeys(Attribute::SshPublicKey) .get_ava_iter_sshpubkeys(Attribute::SshPublicKey)
.map(|i| i.map(|s| s.to_string()).collect()) .map(|i| i.map(|s| s.to_string()).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let cred = $value let cred = $value
.get_ava_single_credential(Attribute::UnixPassword) .get_ava_single_credential(Attribute::UnixPassword)
@ -109,7 +109,7 @@ macro_rules! try_from_entry {
let mail = $value let mail = $value
.get_ava_iter_mail(Attribute::Mail) .get_ava_iter_mail(Attribute::Mail)
.map(|i| i.map(str::to_string).collect()) .map(|i| i.map(str::to_string).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let valid_from = $value.get_ava_single_datetime(Attribute::AccountValidFrom); let valid_from = $value.get_ava_single_datetime(Attribute::AccountValidFrom);

View file

@ -444,36 +444,36 @@ impl SchemaClass {
let systemmay = value let systemmay = value
.get_ava_iter_iutf8(Attribute::SystemMay) .get_ava_iter_iutf8(Attribute::SystemMay)
.map(|i| i.map(|v| v.into()).collect()) .map(|i| i.map(|v| v.into()).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let systemmust = value let systemmust = value
.get_ava_iter_iutf8(Attribute::SystemMust) .get_ava_iter_iutf8(Attribute::SystemMust)
.map(|i| i.map(|v| v.into()).collect()) .map(|i| i.map(|v| v.into()).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let may = value let may = value
.get_ava_iter_iutf8(Attribute::May) .get_ava_iter_iutf8(Attribute::May)
.map(|i| i.map(|v| v.into()).collect()) .map(|i| i.map(|v| v.into()).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let must = value let must = value
.get_ava_iter_iutf8(Attribute::Must) .get_ava_iter_iutf8(Attribute::Must)
.map(|i| i.map(|v| v.into()).collect()) .map(|i| i.map(|v| v.into()).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let systemsupplements = value let systemsupplements = value
.get_ava_iter_iutf8(Attribute::SystemSupplements) .get_ava_iter_iutf8(Attribute::SystemSupplements)
.map(|i| i.map(|v| v.into()).collect()) .map(|i| i.map(|v| v.into()).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let supplements = value let supplements = value
.get_ava_iter_iutf8(Attribute::Supplements) .get_ava_iter_iutf8(Attribute::Supplements)
.map(|i| i.map(|v| v.into()).collect()) .map(|i| i.map(|v| v.into()).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let systemexcludes = value let systemexcludes = value
.get_ava_iter_iutf8(Attribute::SystemExcludes) .get_ava_iter_iutf8(Attribute::SystemExcludes)
.map(|i| i.map(|v| v.into()).collect()) .map(|i| i.map(|v| v.into()).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let excludes = value let excludes = value
.get_ava_iter_iutf8(Attribute::Excludes) .get_ava_iter_iutf8(Attribute::Excludes)
.map(|i| i.map(|v| v.into()).collect()) .map(|i| i.map(|v| v.into()).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
Ok(SchemaClass { Ok(SchemaClass {
name, name,

View file

@ -129,12 +129,12 @@ impl AccessControlCreate {
let attrs = value let attrs = value
.get_ava_iter_iutf8(Attribute::AcpCreateAttr) .get_ava_iter_iutf8(Attribute::AcpCreateAttr)
.map(|i| i.map(AttrString::from).collect()) .map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let classes = value let classes = value
.get_ava_iter_iutf8(Attribute::AcpCreateClass) .get_ava_iter_iutf8(Attribute::AcpCreateClass)
.map(|i| i.map(AttrString::from).collect()) .map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
Ok(AccessControlCreate { Ok(AccessControlCreate {
acp: AccessControlProfile::try_from(qs, value)?, acp: AccessControlProfile::try_from(qs, value)?,
@ -190,17 +190,17 @@ impl AccessControlModify {
let presattrs = value let presattrs = value
.get_ava_iter_iutf8(Attribute::AcpModifyPresentAttr) .get_ava_iter_iutf8(Attribute::AcpModifyPresentAttr)
.map(|i| i.map(AttrString::from).collect()) .map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let remattrs = value let remattrs = value
.get_ava_iter_iutf8(Attribute::AcpModifyRemovedAttr) .get_ava_iter_iutf8(Attribute::AcpModifyRemovedAttr)
.map(|i| i.map(AttrString::from).collect()) .map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
let classes = value let classes = value
.get_ava_iter_iutf8(Attribute::AcpModifyClass) .get_ava_iter_iutf8(Attribute::AcpModifyClass)
.map(|i| i.map(AttrString::from).collect()) .map(|i| i.map(AttrString::from).collect())
.unwrap_or_else(Vec::new); .unwrap_or_default();
Ok(AccessControlModify { Ok(AccessControlModify {
acp: AccessControlProfile::try_from(qs, value)?, acp: AccessControlProfile::try_from(qs, value)?,

View file

@ -1167,7 +1167,7 @@ where
aliases: self aliases: self
.token_homedirectory_alias(tok) .token_homedirectory_alias(tok)
.map(|s| vec![s]) .map(|s| vec![s])
.unwrap_or_else(Vec::new), .unwrap_or_default(),
})) }))
} }