Start adding metrics to collab server
This commit is contained in:
@@ -218,7 +218,7 @@ impl Server {
|
|||||||
let receipt = envelope.receipt();
|
let receipt = envelope.receipt();
|
||||||
let handler = handler.clone();
|
let handler = handler.clone();
|
||||||
async move {
|
async move {
|
||||||
let mut store = server.store.write().await;
|
let mut store = server.state_mut().await;
|
||||||
let response = (handler)(server.clone(), &mut *store, envelope);
|
let response = (handler)(server.clone(), &mut *store, envelope);
|
||||||
match response {
|
match response {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
@@ -1094,6 +1094,15 @@ impl<'a> Drop for StoreWriteGuard<'a> {
|
|||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
self.check_invariants();
|
self.check_invariants();
|
||||||
|
|
||||||
|
let metrics = self.metrics();
|
||||||
|
tracing::info!(
|
||||||
|
connections = metrics.connections,
|
||||||
|
registered_projects = metrics.registered_projects,
|
||||||
|
shared_projects = metrics.shared_projects,
|
||||||
|
collaborators_per_project = metrics.collaborators_per_project,
|
||||||
|
"metrics"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,41 @@ pub struct LeftProject {
|
|||||||
pub authorized_user_ids: Vec<UserId>,
|
pub authorized_user_ids: Vec<UserId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
pub struct Metrics {
|
||||||
|
pub connections: usize,
|
||||||
|
pub registered_projects: usize,
|
||||||
|
pub shared_projects: usize,
|
||||||
|
pub collaborators_per_project: f32,
|
||||||
|
}
|
||||||
|
|
||||||
impl Store {
|
impl Store {
|
||||||
|
pub fn metrics(&self) -> Metrics {
|
||||||
|
let connections = self.connections.len();
|
||||||
|
let mut registered_projects = 0;
|
||||||
|
let mut shared_projects = 0;
|
||||||
|
let mut collaborators = 0;
|
||||||
|
for project in self.projects.values() {
|
||||||
|
registered_projects += 1;
|
||||||
|
if let Some(share) = project.share.as_ref() {
|
||||||
|
shared_projects += 1;
|
||||||
|
collaborators += share.active_replica_ids.len();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let collaborators_per_project = if shared_projects == 0 || collaborators == 0 {
|
||||||
|
0.
|
||||||
|
} else {
|
||||||
|
collaborators as f32 / shared_projects as f32
|
||||||
|
};
|
||||||
|
|
||||||
|
Metrics {
|
||||||
|
connections,
|
||||||
|
registered_projects,
|
||||||
|
shared_projects,
|
||||||
|
collaborators_per_project,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[instrument(skip(self))]
|
#[instrument(skip(self))]
|
||||||
pub fn add_connection(&mut self, connection_id: ConnectionId, user_id: UserId) {
|
pub fn add_connection(&mut self, connection_id: ConnectionId, user_id: UserId) {
|
||||||
self.connections.insert(
|
self.connections.insert(
|
||||||
|
|||||||
Reference in New Issue
Block a user