Skip to content

Commit

Permalink
Add UUID to stats
Browse files Browse the repository at this point in the history
This should allow any stats consumer to know when the file has been
lost and the counters should be restarted.
Athos Couto authored and MarinPostma committed Jan 24, 2024
1 parent b32d62f commit ce2d378
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libsql-server/src/http/admin/stats.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ use serde::Serialize;

use axum::extract::{Path, State};
use axum::Json;
use uuid::Uuid;

use crate::namespace::{MakeNamespace, NamespaceName};
use crate::replication::FrameNo;
@@ -13,6 +14,7 @@ use super::AppState;

#[derive(Serialize)]
pub struct StatsResponse {
pub id: Option<Uuid>,
pub rows_read_count: u64,
pub rows_written_count: u64,
pub storage_bytes_used: u64,
@@ -25,6 +27,7 @@ pub struct StatsResponse {
impl From<&Stats> for StatsResponse {
fn from(stats: &Stats) -> Self {
Self {
id: stats.id(),
rows_read_count: stats.rows_read(),
rows_written_count: stats.rows_written(),
storage_bytes_used: stats.storage_bytes_used(),
11 changes: 11 additions & 0 deletions libsql-server/src/stats.rs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ use std::collections::BTreeSet;
use tokio::io::AsyncWriteExt;
use tokio::task::JoinSet;
use tokio::time::Duration;
use uuid::Uuid;

use crate::namespace::NamespaceName;
use crate::replication::FrameNo;
@@ -56,6 +57,8 @@ pub struct Stats {
#[serde(skip)]
namespace: NamespaceName,

#[serde(default)]
id: Option<Uuid>,
#[serde(default)]
rows_written: AtomicU64,
#[serde(default)]
@@ -93,6 +96,10 @@ impl Stats {
Stats::default()
};

if this.id.is_none() {
this.id = Some(Uuid::new_v4());
}

this.namespace = namespace;
let this = Arc::new(this);

@@ -226,6 +233,10 @@ impl Stats {
counter!("libsql_server_query_rows_written", rows_written);
counter!("libsql_server_query_mem_used", mem_used);
}

pub fn id(&self) -> Option<Uuid> {
self.id.clone()
}
}

async fn spawn_stats_persist_thread(stats: Weak<Stats>, path: PathBuf) -> anyhow::Result<()> {

0 comments on commit ce2d378

Please sign in to comment.