mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-19 08:41:24 +01:00
More useful tracing spans
This commit is contained in:
parent
c0ce2ebbf8
commit
5172f66c1a
14 changed files with 121 additions and 27 deletions
|
|
@ -8,7 +8,7 @@ pub(crate) use data::Data;
|
|||
use ruma::{api::client::error::ErrorKind, EventId, RoomId};
|
||||
use tracing::{debug, error, warn};
|
||||
|
||||
use crate::{services, Error, Result};
|
||||
use crate::{services, utils::debug_slice_truncated, Error, Result};
|
||||
|
||||
pub(crate) struct Service {
|
||||
pub(crate) db: &'static dyn Data,
|
||||
|
|
@ -31,7 +31,10 @@ impl Service {
|
|||
self.db.cache_auth_chain(key, auth_chain)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, starting_events))]
|
||||
#[tracing::instrument(
|
||||
skip(self, starting_events),
|
||||
fields(starting_events = debug_slice_truncated(&starting_events, 5)),
|
||||
)]
|
||||
pub(crate) async fn get_auth_chain<'a>(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
@ -138,7 +141,7 @@ impl Service {
|
|||
}))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, event_id))]
|
||||
#[tracing::instrument(skip(self))]
|
||||
fn get_auth_chain_inner(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ pub(crate) struct Service {
|
|||
impl Service {
|
||||
/// Sets a user as typing until the timeout timestamp is reached or
|
||||
/// `roomtyping_remove` is called.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) async fn typing_add(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
|
@ -47,6 +48,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Removes a user from typing before the timeout is reached.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) async fn typing_remove(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
|
@ -71,6 +73,7 @@ impl Service {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) async fn wait_for_update(&self, room_id: &RoomId) -> Result<()> {
|
||||
let mut receiver = self.typing_update_sender.subscribe();
|
||||
while let Ok(next) = receiver.recv().await {
|
||||
|
|
@ -83,6 +86,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Makes sure that typing events with old timestamps get removed.
|
||||
#[tracing::instrument(skip(self, room_id))]
|
||||
async fn typings_maintain(&self, room_id: &RoomId) -> Result<()> {
|
||||
let current_timestamp = utils::millis_since_unix_epoch();
|
||||
let mut removable = Vec::new();
|
||||
|
|
@ -119,6 +123,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Returns the count of the last typing update in this room.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) async fn last_typing_update(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
@ -134,6 +139,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Returns a new typing EDU.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) async fn typings_all(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
|
|||
|
|
@ -1085,6 +1085,7 @@ impl Service {
|
|||
Ok(pdu_id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, room_version_id, incoming_state))]
|
||||
async fn resolve_state(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
@ -1397,6 +1398,8 @@ impl Service {
|
|||
})
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
#[allow(clippy::type_complexity)]
|
||||
async fn fetch_unknown_prev_events(
|
||||
&self,
|
||||
origin: &ServerName,
|
||||
|
|
@ -1558,6 +1561,7 @@ impl Service {
|
|||
// Gets a list of servers for which we don't have the signing key yet. We go
|
||||
// over the PDUs and either cache the key or add it to the list that
|
||||
// needs to be retrieved.
|
||||
#[tracing::instrument(skip_all)]
|
||||
async fn get_server_keys_from_cache(
|
||||
&self,
|
||||
pdu: &RawJsonValue,
|
||||
|
|
@ -1797,6 +1801,7 @@ impl Service {
|
|||
/// Returns Ok if the acl allows the server
|
||||
// Allowed because this function uses `services()`
|
||||
#[allow(clippy::unused_self)]
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub(crate) fn acl_check(
|
||||
&self,
|
||||
server_name: &ServerName,
|
||||
|
|
@ -2010,6 +2015,7 @@ impl Service {
|
|||
Err(Error::BadServerResponse("Failed to find public key for server"))
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
fn check_room_id(room_id: &RoomId, pdu: &PduEvent) -> Result<()> {
|
||||
if pdu.room_id != room_id {
|
||||
warn!("Found event from room {} in room {}", pdu.room_id, room_id);
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ impl Service {
|
|||
// Allowed because this function uses `services()`
|
||||
clippy::unused_self,
|
||||
)]
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn paginate_relations_with_filter(
|
||||
&self,
|
||||
sender_user: &UserId,
|
||||
|
|
@ -178,6 +179,7 @@ impl Service {
|
|||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub(crate) fn relations_until<'a>(
|
||||
&'a self,
|
||||
user_id: &'a UserId,
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ pub(crate) struct Service {
|
|||
|
||||
impl Service {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) async fn get_hierarchy(
|
||||
&self,
|
||||
sender_user: &UserId,
|
||||
|
|
@ -326,6 +327,7 @@ impl Service {
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
#[tracing::instrument(skip(self, sender_user, children))]
|
||||
fn get_room_chunk(
|
||||
&self,
|
||||
sender_user: &UserId,
|
||||
|
|
@ -525,6 +527,7 @@ impl Service {
|
|||
Ok(allowed)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self, sender_user))]
|
||||
fn handle_join_rule(
|
||||
&self,
|
||||
join_rule: &JoinRule,
|
||||
|
|
|
|||
|
|
@ -20,7 +20,11 @@ use tokio::sync::MutexGuard;
|
|||
use tracing::warn;
|
||||
|
||||
use super::state_compressor::CompressedStateEvent;
|
||||
use crate::{services, utils::calculate_hash, Error, PduEvent, Result};
|
||||
use crate::{
|
||||
services,
|
||||
utils::{calculate_hash, debug_slice_truncated},
|
||||
Error, PduEvent, Result,
|
||||
};
|
||||
|
||||
pub(crate) struct Service {
|
||||
pub(crate) db: &'static dyn Data,
|
||||
|
|
@ -28,6 +32,12 @@ pub(crate) struct Service {
|
|||
|
||||
impl Service {
|
||||
/// Set the room to the given statehash and update caches.
|
||||
#[tracing::instrument(skip(
|
||||
self,
|
||||
statediffnew,
|
||||
_statediffremoved,
|
||||
state_lock
|
||||
))]
|
||||
pub(crate) async fn force_state(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
@ -354,6 +364,7 @@ impl Service {
|
|||
Ok(create_event_content.room_version)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn get_room_shortstatehash(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
@ -361,6 +372,7 @@ impl Service {
|
|||
self.db.get_room_shortstatehash(room_id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn get_forward_extremities(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
@ -368,6 +380,10 @@ impl Service {
|
|||
self.db.get_forward_extremities(room_id)
|
||||
}
|
||||
|
||||
#[tracing::instrument(
|
||||
skip(self, event_ids, state_lock),
|
||||
fields(event_ids = debug_slice_truncated(&event_ids, 5)),
|
||||
)]
|
||||
pub(crate) fn set_forward_extremities(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ impl Service {
|
|||
self.db.state_full_ids(shortstatehash).await
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) async fn state_full(
|
||||
&self,
|
||||
shortstatehash: u64,
|
||||
|
|
@ -68,6 +69,7 @@ impl Service {
|
|||
|
||||
/// Returns a single PDU from `room_id` with key (`event_type`,
|
||||
/// `state_key`).
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn state_get(
|
||||
&self,
|
||||
shortstatehash: u64,
|
||||
|
|
@ -78,6 +80,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Get membership for given user in state
|
||||
#[tracing::instrument(skip(self))]
|
||||
fn user_membership(
|
||||
&self,
|
||||
shortstatehash: u64,
|
||||
|
|
@ -100,6 +103,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// The user was a joined member at this state (potentially in the past)
|
||||
#[tracing::instrument(skip(self), ret(level = "trace"))]
|
||||
fn user_was_joined(&self, shortstatehash: u64, user_id: &UserId) -> bool {
|
||||
self.user_membership(shortstatehash, user_id)
|
||||
.map(|s| s == MembershipState::Join)
|
||||
|
|
@ -108,6 +112,7 @@ impl Service {
|
|||
|
||||
/// The user was an invited or joined room member at this state (potentially
|
||||
/// in the past)
|
||||
#[tracing::instrument(skip(self), ret(level = "trace"))]
|
||||
fn user_was_invited(&self, shortstatehash: u64, user_id: &UserId) -> bool {
|
||||
self.user_membership(shortstatehash, user_id)
|
||||
.map(|s| s == MembershipState::Join || s == MembershipState::Invite)
|
||||
|
|
@ -294,6 +299,7 @@ impl Service {
|
|||
}
|
||||
|
||||
/// Returns the state hash for this pdu.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn pdu_shortstatehash(
|
||||
&self,
|
||||
event_id: &EventId,
|
||||
|
|
@ -334,6 +340,7 @@ impl Service {
|
|||
self.db.room_state_get(room_id, event_type, state_key)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn get_name(&self, room_id: &RoomId) -> Result<Option<String>> {
|
||||
self.room_state_get(room_id, &StateEventType::RoomName, "")?.map_or(
|
||||
Ok(None),
|
||||
|
|
@ -354,6 +361,7 @@ impl Service {
|
|||
)
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn get_avatar(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
@ -372,6 +380,7 @@ impl Service {
|
|||
|
||||
// Allowed because this function uses `services()`
|
||||
#[allow(clippy::unused_self)]
|
||||
#[tracing::instrument(skip(self), ret(level = "trace"))]
|
||||
pub(crate) fn user_can_invite(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
@ -398,6 +407,7 @@ impl Service {
|
|||
.is_ok()
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn get_member(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
@ -420,6 +430,7 @@ impl Service {
|
|||
/// If `federation` is `true`, it allows redaction events from any user of
|
||||
/// the same server as the original event sender, [as required by room
|
||||
/// versions >= v3](https://spec.matrix.org/v1.10/rooms/v11/#handling-redactions)
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn user_can_redact(
|
||||
&self,
|
||||
redacts: &EventId,
|
||||
|
|
|
|||
|
|
@ -286,6 +286,7 @@ impl Service {
|
|||
/// Returns the new shortstatehash, and the state diff from the previous
|
||||
/// room state
|
||||
#[allow(clippy::type_complexity)]
|
||||
#[tracing::instrument(skip(self, new_state_ids_compressed))]
|
||||
pub(crate) fn save_state(
|
||||
&self,
|
||||
room_id: &RoomId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue