mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
move FoundIn to observability.rs
This commit is contained in:
parent
71f3d84115
commit
b2d6810f35
9 changed files with 43 additions and 53 deletions
|
|
@ -67,10 +67,9 @@ use tracing::{debug, error, field, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
api::client_server::{self, claim_keys_helper, get_keys_helper},
|
api::client_server::{self, claim_keys_helper, get_keys_helper},
|
||||||
|
observability::FoundIn,
|
||||||
service::pdu::{gen_event_id_canonical_json, PduBuilder},
|
service::pdu::{gen_event_id_canonical_json, PduBuilder},
|
||||||
services,
|
services, utils, Ar, Error, PduEvent, Ra, Result,
|
||||||
utils::{self, FoundIn},
|
|
||||||
Ar, Error, PduEvent, Ra, Result,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Wraps either an literal IP address plus port, or a hostname plus complement
|
/// 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 std::{collections::HashSet, mem::size_of, sync::Arc};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::KeyValueDatabase,
|
database::KeyValueDatabase, observability::FoundIn, service, utils, Result,
|
||||||
service,
|
|
||||||
utils::{self, FoundIn},
|
|
||||||
Result,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl service::rooms::auth_chain::Data for KeyValueDatabase {
|
impl service::rooms::auth_chain::Data for KeyValueDatabase {
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,8 @@ use std::sync::Arc;
|
||||||
use ruma::{events::StateEventType, EventId, RoomId};
|
use ruma::{events::StateEventType, EventId, RoomId};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::KeyValueDatabase,
|
database::KeyValueDatabase, observability::FoundIn, service, services,
|
||||||
service, services,
|
utils, Error, Result,
|
||||||
utils::{self, FoundIn},
|
|
||||||
Error, Result,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl service::rooms::short::Data for KeyValueDatabase {
|
impl service::rooms::short::Data for KeyValueDatabase {
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,9 @@ use ruma::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::KeyValueDatabase,
|
database::KeyValueDatabase,
|
||||||
|
observability::FoundIn,
|
||||||
service::{self, appservice::RegistrationInfo},
|
service::{self, appservice::RegistrationInfo},
|
||||||
services,
|
services, utils, Error, Result,
|
||||||
utils::{self, FoundIn},
|
|
||||||
Error, Result,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl service::rooms::state_cache::Data for KeyValueDatabase {
|
impl service::rooms::state_cache::Data for KeyValueDatabase {
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,8 @@ use service::rooms::timeline::PduCount;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
database::KeyValueDatabase,
|
database::KeyValueDatabase, observability::FoundIn, service, services,
|
||||||
service, services,
|
utils, Error, PduEvent, Result,
|
||||||
utils::{self, FoundIn},
|
|
||||||
Error, PduEvent, Result,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
impl service::rooms::timeline::Data for KeyValueDatabase {
|
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
|
/// Initialize observability
|
||||||
pub(crate) fn init(config: &Config) -> Result<Guard, error::Observability> {
|
pub(crate) fn init(config: &Config) -> Result<Guard, error::Observability> {
|
||||||
let config_filter_layer = || EnvFilter::try_new(&config.log);
|
let config_filter_layer = || EnvFilter::try_new(&config.log);
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@ use tokio::sync::MutexGuard;
|
||||||
use tracing::{error, warn};
|
use tracing::{error, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
service::pdu::PduBuilder, services, utils::FoundIn, Error, PduEvent, Result,
|
observability::FoundIn, service::pdu::PduBuilder, services, Error,
|
||||||
|
PduEvent, Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) struct Service {
|
pub(crate) struct Service {
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,7 @@ use lru_cache::LruCache;
|
||||||
use ruma::{EventId, RoomId};
|
use ruma::{EventId, RoomId};
|
||||||
|
|
||||||
use self::data::StateDiff;
|
use self::data::StateDiff;
|
||||||
use crate::{
|
use crate::{observability::FoundIn, services, utils, Result};
|
||||||
services,
|
|
||||||
utils::{self, FoundIn},
|
|
||||||
Result,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct CompressedStateLayer {
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::utils::truncate_str_for_debug;
|
use crate::utils::truncate_str_for_debug;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue