capture logs for resolve-true-destination admin cmd

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-06-11 01:27:58 +00:00
parent aa34021b27
commit c914a4fd91
2 changed files with 27 additions and 8 deletions

View File

@ -1,11 +1,15 @@
use std::{
collections::{BTreeMap, HashMap},
sync::Arc,
sync::{Arc, Mutex},
time::Instant,
};
use api::client::validate_and_add_event_id;
use conduit::{utils::HtmlEscape, Error, Result};
use conduit::{
debug, info, log,
log::{capture, Capture},
utils::HtmlEscape,
warn, Error, Result,
};
use ruma::{
api::{client::error::ErrorKind, federation::event::get_room_state},
events::room::message::RoomMessageEventContent,
@ -13,9 +17,10 @@ use ruma::{
};
use service::{rooms::event_handler::parse_incoming_pdu, sending::resolve::resolve_actual_dest, services, PduEvent};
use tokio::sync::RwLock;
use tracing::{debug, info, warn};
use tracing_subscriber::EnvFilter;
use crate::api::client::validate_and_add_event_id;
pub(crate) async fn get_auth_chain(_body: Vec<&str>, event_id: Box<EventId>) -> Result<RoomMessageEventContent> {
let event_id = Arc::<EventId>::from(event_id);
if let Some(event) = services().rooms.timeline.get_pdu_json(&event_id)? {
@ -635,11 +640,24 @@ pub(crate) async fn resolve_true_destination(
));
}
let (actual_dest, hostname_uri) = resolve_actual_dest(&server_name, !no_cache).await?;
let filter: &capture::Filter = &|data| {
data.level() <= log::Level::DEBUG
&& data.mod_name().starts_with("conduit")
&& matches!(data.span_name(), "actual" | "well-known" | "srv")
};
Ok(RoomMessageEventContent::text_plain(format!(
"Actual destination: {actual_dest} | Hostname URI: {hostname_uri}"
)))
let state = &services().server.log.capture;
let logs = Arc::new(Mutex::new(String::new()));
let capture = Capture::new(state, Some(filter), capture::to_html(&logs));
let (actual_dest, hostname_uri);
{
let _capture_scope = capture.start();
(actual_dest, hostname_uri) = resolve_actual_dest(&server_name, !no_cache).await?;
};
let plain = format!("Actual destination: {actual_dest} | Hostname URI: {hostname_uri}");
let html = format!("{}<br>{plain}", logs.lock().expect("locked"));
Ok(RoomMessageEventContent::text_html(plain, html))
}
#[must_use]

View File

@ -75,6 +75,7 @@ pub(crate) async fn get_actual_dest(server_name: &ServerName) -> Result<ActualDe
/// Implemented according to the specification at <https://matrix.org/docs/spec/server_server/r0.1.4#resolving-server-names>
/// Numbers in comments below refer to bullet points in linked section of
/// specification
#[tracing::instrument(skip_all, name = "actual")]
pub async fn resolve_actual_dest(dest: &ServerName, cache: bool) -> Result<(FedDest, String)> {
trace!("Finding actual destination for {dest}");
let mut host = dest.as_str().to_owned();