mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
move FoundIn to observability.rs
This commit is contained in:
parent
0bd2c43dab
commit
22dd7f1a54
9 changed files with 43 additions and 53 deletions
|
|
@ -67,10 +67,9 @@ use tracing::{debug, error, field, warn};
|
|||
|
||||
use crate::{
|
||||
api::client_server::{self, claim_keys_helper, get_keys_helper},
|
||||
observability::FoundIn,
|
||||
service::pdu::{gen_event_id_canonical_json, PduBuilder},
|
||||
services,
|
||||
utils::{self, FoundIn},
|
||||
Ar, Error, PduEvent, Ra, Result,
|
||||
services, utils, Ar, Error, PduEvent, Ra, Result,
|
||||
};
|
||||
|
||||
/// Wraps either an literal IP address plus port, or a hostname plus complement
|
||||
|
|
|
|||
|
|
@ -1,10 +1,7 @@
|
|||
use std::{collections::HashSet, mem::size_of, sync::Arc};
|
||||
|
||||
use crate::{
|
||||
database::KeyValueDatabase,
|
||||
service,
|
||||
utils::{self, FoundIn},
|
||||
Result,
|
||||
database::KeyValueDatabase, observability::FoundIn, service, utils, Result,
|
||||
};
|
||||
|
||||
impl service::rooms::auth_chain::Data for KeyValueDatabase {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,8 @@ use std::sync::Arc;
|
|||
use ruma::{events::StateEventType, EventId, RoomId};
|
||||
|
||||
use crate::{
|
||||
database::KeyValueDatabase,
|
||||
service, services,
|
||||
utils::{self, FoundIn},
|
||||
Error, Result,
|
||||
database::KeyValueDatabase, observability::FoundIn, service, services,
|
||||
utils, Error, Result,
|
||||
};
|
||||
|
||||
impl service::rooms::short::Data for KeyValueDatabase {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,9 @@ use ruma::{
|
|||
|
||||
use crate::{
|
||||
database::KeyValueDatabase,
|
||||
observability::FoundIn,
|
||||
service::{self, appservice::RegistrationInfo},
|
||||
services,
|
||||
utils::{self, FoundIn},
|
||||
Error, Result,
|
||||
services, utils, Error, Result,
|
||||
};
|
||||
|
||||
impl service::rooms::state_cache::Data for KeyValueDatabase {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,8 @@ use service::rooms::timeline::PduCount;
|
|||
use tracing::error;
|
||||
|
||||
use crate::{
|
||||
database::KeyValueDatabase,
|
||||
service, services,
|
||||
utils::{self, FoundIn},
|
||||
Error, PduEvent, Result,
|
||||
database::KeyValueDatabase, observability::FoundIn, service, services,
|
||||
utils, Error, PduEvent, Result,
|
||||
};
|
||||
|
||||
impl service::rooms::timeline::Data for KeyValueDatabase {
|
||||
|
|
|
|||
|
|
@ -40,6 +40,37 @@ impl Drop for Guard {
|
|||
}
|
||||
}
|
||||
|
||||
/// Type to record cache performance in a tracing span field.
|
||||
pub(crate) enum FoundIn {
|
||||
/// Found in cache
|
||||
Cache,
|
||||
/// Cache miss, but it was in the database. The cache has been updated.
|
||||
Database,
|
||||
/// Cache and database miss, but another server had it. The cache has been
|
||||
/// updated.
|
||||
Remote,
|
||||
/// The entry could not be found anywhere.
|
||||
Nothing,
|
||||
}
|
||||
|
||||
impl FoundIn {
|
||||
/// Returns a stringified representation of the current value
|
||||
fn value(&self) -> &'static str {
|
||||
match self {
|
||||
FoundIn::Cache => "hit",
|
||||
FoundIn::Database => "miss-database",
|
||||
FoundIn::Remote => "miss-remote",
|
||||
FoundIn::Nothing => "not-found",
|
||||
}
|
||||
}
|
||||
|
||||
/// Record the current value to the current [`tracing::Span`]
|
||||
// TODO: use tracing::Value instead if it ever becomes accessible
|
||||
pub(crate) fn record(&self, field: &str) {
|
||||
tracing::Span::current().record(field, self.value());
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize observability
|
||||
pub(crate) fn init(config: &Config) -> Result<Guard, error::Observability> {
|
||||
let config_filter_layer = || EnvFilter::try_new(&config.log);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@ use tokio::sync::MutexGuard;
|
|||
use tracing::{error, warn};
|
||||
|
||||
use crate::{
|
||||
service::pdu::PduBuilder, services, utils::FoundIn, Error, PduEvent, Result,
|
||||
observability::FoundIn, service::pdu::PduBuilder, services, Error,
|
||||
PduEvent, Result,
|
||||
};
|
||||
|
||||
pub(crate) struct Service {
|
||||
|
|
|
|||
|
|
@ -10,11 +10,7 @@ use lru_cache::LruCache;
|
|||
use ruma::{EventId, RoomId};
|
||||
|
||||
use self::data::StateDiff;
|
||||
use crate::{
|
||||
services,
|
||||
utils::{self, FoundIn},
|
||||
Result,
|
||||
};
|
||||
use crate::{observability::FoundIn, services, utils, Result};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub(crate) struct CompressedStateLayer {
|
||||
|
|
|
|||
29
src/utils.rs
29
src/utils.rs
|
|
@ -245,35 +245,6 @@ pub(crate) fn truncate_str_for_debug(
|
|||
}
|
||||
}
|
||||
|
||||
/// Type to record cache performance in a tracing span field.
|
||||
pub(crate) enum FoundIn {
|
||||
/// Found in cache
|
||||
Cache,
|
||||
/// Cache miss, but it was in the database. The cache has been updated.
|
||||
Database,
|
||||
/// Cache and database miss, but another server had it. The cache has been
|
||||
/// updated.
|
||||
Remote,
|
||||
/// The entry could not be found anywhere.
|
||||
Nothing,
|
||||
}
|
||||
|
||||
impl FoundIn {
|
||||
fn value(&self) -> &'static str {
|
||||
match self {
|
||||
FoundIn::Cache => "hit",
|
||||
FoundIn::Database => "miss-database",
|
||||
FoundIn::Remote => "miss-remote",
|
||||
FoundIn::Nothing => "not-found",
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: use tracing::Value instead if it ever becomes accessible
|
||||
pub(crate) fn record(&self, field: &str) {
|
||||
tracing::Span::current().record(field, self.value());
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::utils::truncate_str_for_debug;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue