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:
Charles Hall 2024-06-04 13:26:23 -07:00
parent 9364d44ce2
commit 0c2094a56f
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
8 changed files with 142 additions and 68 deletions

View file

@ -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()