mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-18 08:11:24 +01:00
record FoundIn with metrics instead of traces
This is much more efficient in terms of network use and data storage, and also easier to visualize.
This commit is contained in:
parent
9364d44ce2
commit
0c2094a56f
8 changed files with 142 additions and 68 deletions
|
|
@ -28,8 +28,9 @@ use tokio::sync::MutexGuard;
|
|||
use tracing::{error, warn};
|
||||
|
||||
use crate::{
|
||||
observability::FoundIn, service::pdu::PduBuilder, services, Error,
|
||||
PduEvent, Result,
|
||||
observability::{FoundIn, Lookup, METRICS},
|
||||
service::pdu::PduBuilder,
|
||||
services, Error, PduEvent, Result,
|
||||
};
|
||||
|
||||
pub(crate) struct Service {
|
||||
|
|
@ -123,13 +124,15 @@ impl Service {
|
|||
|
||||
/// Whether a server is allowed to see an event through federation, based on
|
||||
/// the room's history_visibility at that event's state.
|
||||
#[tracing::instrument(skip(self), fields(cache_result))]
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn server_can_see_event(
|
||||
&self,
|
||||
origin: &ServerName,
|
||||
room_id: &RoomId,
|
||||
event_id: &EventId,
|
||||
) -> Result<bool> {
|
||||
let lookup = Lookup::VisibilityForServer;
|
||||
|
||||
let Some(shortstatehash) = self.pdu_shortstatehash(event_id)? else {
|
||||
return Ok(true);
|
||||
};
|
||||
|
|
@ -140,7 +143,7 @@ impl Service {
|
|||
.unwrap()
|
||||
.get_mut(&(origin.to_owned(), shortstatehash))
|
||||
{
|
||||
FoundIn::Cache.record("cache_result");
|
||||
METRICS.record_lookup(lookup, FoundIn::Cache);
|
||||
return Ok(*visibility);
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +194,7 @@ impl Service {
|
|||
}
|
||||
};
|
||||
|
||||
FoundIn::Database.record("cache_result");
|
||||
METRICS.record_lookup(lookup, FoundIn::Database);
|
||||
self.server_visibility_cache
|
||||
.lock()
|
||||
.unwrap()
|
||||
|
|
@ -202,13 +205,15 @@ impl Service {
|
|||
|
||||
/// Whether a user is allowed to see an event, based on
|
||||
/// the room's history_visibility at that event's state.
|
||||
#[tracing::instrument(skip(self), fields(cache_result))]
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn user_can_see_event(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
room_id: &RoomId,
|
||||
event_id: &EventId,
|
||||
) -> Result<bool> {
|
||||
let lookup = Lookup::VisibilityForUser;
|
||||
|
||||
let Some(shortstatehash) = self.pdu_shortstatehash(event_id)? else {
|
||||
return Ok(true);
|
||||
};
|
||||
|
|
@ -219,7 +224,7 @@ impl Service {
|
|||
.unwrap()
|
||||
.get_mut(&(user_id.to_owned(), shortstatehash))
|
||||
{
|
||||
FoundIn::Cache.record("cache_result");
|
||||
METRICS.record_lookup(lookup, FoundIn::Cache);
|
||||
return Ok(*visibility);
|
||||
}
|
||||
|
||||
|
|
@ -262,7 +267,7 @@ impl Service {
|
|||
}
|
||||
};
|
||||
|
||||
FoundIn::Database.record("cache_result");
|
||||
METRICS.record_lookup(lookup, FoundIn::Database);
|
||||
self.user_visibility_cache
|
||||
.lock()
|
||||
.unwrap()
|
||||
|
|
|
|||
|
|
@ -10,7 +10,10 @@ use lru_cache::LruCache;
|
|||
use ruma::{EventId, RoomId};
|
||||
|
||||
use self::data::StateDiff;
|
||||
use crate::{observability::FoundIn, services, utils, Result};
|
||||
use crate::{
|
||||
observability::{FoundIn, Lookup, METRICS},
|
||||
services, utils, Result,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct CompressedStateLayer {
|
||||
|
|
@ -33,15 +36,17 @@ impl Service {
|
|||
/// Returns a stack with info on shortstatehash, full state, added diff and
|
||||
/// removed diff for the selected shortstatehash and each parent layer.
|
||||
#[allow(clippy::type_complexity)]
|
||||
#[tracing::instrument(skip(self), fields(cache_result))]
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn load_shortstatehash_info(
|
||||
&self,
|
||||
shortstatehash: u64,
|
||||
) -> Result<Vec<CompressedStateLayer>> {
|
||||
let lookup = Lookup::StateInfo;
|
||||
|
||||
if let Some(r) =
|
||||
self.stateinfo_cache.lock().unwrap().get_mut(&shortstatehash)
|
||||
{
|
||||
FoundIn::Cache.record("cache_result");
|
||||
METRICS.record_lookup(lookup, FoundIn::Cache);
|
||||
return Ok(r.clone());
|
||||
}
|
||||
|
||||
|
|
@ -76,7 +81,7 @@ impl Service {
|
|||
}]
|
||||
};
|
||||
|
||||
FoundIn::Database.record("cache_result");
|
||||
METRICS.record_lookup(lookup, FoundIn::Database);
|
||||
self.stateinfo_cache
|
||||
.lock()
|
||||
.unwrap()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue