capture logs for resolve-true-destination admin cmd
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
aa34021b27
commit
c914a4fd91
|
@ -1,11 +1,15 @@
|
||||||
use std::{
|
use std::{
|
||||||
collections::{BTreeMap, HashMap},
|
collections::{BTreeMap, HashMap},
|
||||||
sync::Arc,
|
sync::{Arc, Mutex},
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use api::client::validate_and_add_event_id;
|
use conduit::{
|
||||||
use conduit::{utils::HtmlEscape, Error, Result};
|
debug, info, log,
|
||||||
|
log::{capture, Capture},
|
||||||
|
utils::HtmlEscape,
|
||||||
|
warn, Error, Result,
|
||||||
|
};
|
||||||
use ruma::{
|
use ruma::{
|
||||||
api::{client::error::ErrorKind, federation::event::get_room_state},
|
api::{client::error::ErrorKind, federation::event::get_room_state},
|
||||||
events::room::message::RoomMessageEventContent,
|
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 service::{rooms::event_handler::parse_incoming_pdu, sending::resolve::resolve_actual_dest, services, PduEvent};
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
use tracing::{debug, info, warn};
|
|
||||||
use tracing_subscriber::EnvFilter;
|
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> {
|
pub(crate) async fn get_auth_chain(_body: Vec<&str>, event_id: Box<EventId>) -> Result<RoomMessageEventContent> {
|
||||||
let event_id = Arc::<EventId>::from(event_id);
|
let event_id = Arc::<EventId>::from(event_id);
|
||||||
if let Some(event) = services().rooms.timeline.get_pdu_json(&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!(
|
let state = &services().server.log.capture;
|
||||||
"Actual destination: {actual_dest} | Hostname URI: {hostname_uri}"
|
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]
|
#[must_use]
|
||||||
|
|
|
@ -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>
|
/// 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
|
/// Numbers in comments below refer to bullet points in linked section of
|
||||||
/// specification
|
/// specification
|
||||||
|
#[tracing::instrument(skip_all, name = "actual")]
|
||||||
pub async fn resolve_actual_dest(dest: &ServerName, cache: bool) -> Result<(FedDest, String)> {
|
pub async fn resolve_actual_dest(dest: &ServerName, cache: bool) -> Result<(FedDest, String)> {
|
||||||
trace!("Finding actual destination for {dest}");
|
trace!("Finding actual destination for {dest}");
|
||||||
let mut host = dest.as_str().to_owned();
|
let mut host = dest.as_str().to_owned();
|
||||||
|
|
Loading…
Reference in New Issue