Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/tracedecay-store-runtime/src/session_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@ impl ProjectRuntimeOwnerRegistryV1 {
self.0.lock()
}

#[hotpath::measure(label = "daemon.session_registry.list_ready_sessions")]
fn ready_session_projects(&self) -> Result<Vec<ProjectId>> {
let entries = self.lock().map_err(|_| {
session_registry_error(
Expand Down Expand Up @@ -425,6 +426,7 @@ impl ProjectRuntimeOwnerRegistryV1 {
}
}

#[hotpath::measure(label = "daemon.session_registry.reserve_session_replacement")]
fn reserve_session_replacement(
&self,
project_id: &ProjectId,
Expand Down Expand Up @@ -483,6 +485,7 @@ impl ProjectRuntimeOwnerRegistryV1 {
}))
}

#[hotpath::measure(label = "daemon.session_registry.reserve_session_recovery")]
fn reserve_session_recovery(
&self,
project_id: &ProjectId,
Expand Down Expand Up @@ -528,6 +531,7 @@ impl ProjectRuntimeOwnerRegistryV1 {
/// Rebuilds the fail-closed post-restart recovery record. The durable
/// quarantine receipt is written only after the old paired owners have
/// closed; it never reconstructs or remounts that terminal owner.
#[hotpath::measure(label = "daemon.session_registry.reconstruct_terminal_recovery")]
fn reconstruct_durable_terminal_recovery(
&self,
project_id: &ProjectId,
Expand Down Expand Up @@ -568,6 +572,7 @@ impl ProjectRuntimeOwnerRegistryV1 {
}
}

#[hotpath::measure(label = "daemon.session_registry.bind_memory_graph")]
fn bind_ready_project_memory_graph(
owners: &ProjectRuntimeOwnerRegistryV1,
project_id: &ProjectId,
Expand Down Expand Up @@ -2668,6 +2673,7 @@ impl DaemonSessionRuntimeRegistryV1 {
})
}

#[hotpath::measure(label = "daemon.session_registry.admit_remote_node")]
fn admit_remote_node_owner(
&self,
node_id: &BrainNodeId,
Expand Down Expand Up @@ -2716,6 +2722,7 @@ impl DaemonSessionRuntimeRegistryV1 {
))
}

#[hotpath::measure(label = "daemon.session_registry.admit_project_runtime")]
fn admit_project_runtime_owner(
&self,
project_id: &ProjectId,
Expand Down Expand Up @@ -2784,6 +2791,7 @@ impl DaemonSessionRuntimeRegistryV1 {
)))
}

#[hotpath::measure(label = "daemon.session_registry.extend_project_runtime")]
fn extend_project_runtime_owner(
&self,
project_id: &ProjectId,
Expand Down Expand Up @@ -2833,6 +2841,7 @@ impl DaemonSessionRuntimeRegistryV1 {
)))
}

#[hotpath::measure(label = "daemon.session_registry.reserve_runtime_retirement")]
fn reserve_project_runtime_retirement(
&self,
project_id: &ProjectId,
Expand Down Expand Up @@ -3079,6 +3088,7 @@ impl DaemonSessionRuntimeRegistryV1 {
})
}

#[hotpath::measure(label = "daemon.session_registry.retire_session_sync", future = true)]
async fn retire_project_session_sync(&self, project_id: &ProjectId) -> Result<()> {
self.active_session_sync_service("retire project session sync")?
.retire_project(self.identity.profile_id(), project_id)
Expand All @@ -3087,6 +3097,7 @@ impl DaemonSessionRuntimeRegistryV1 {
.map_err(|error| session_registry_error("retire project session sync", error))
}

#[hotpath::measure(label = "daemon.session_registry.rebind_session_sync", future = true)]
async fn rebind_project_session_sync(
&self,
project_id: &ProjectId,
Expand Down Expand Up @@ -3136,6 +3147,7 @@ impl ProfileRuntime for DaemonSessionRuntimeRegistryV1 {
}
}

#[hotpath::measure(label = "daemon.session_registry.runtime_incarnation")]
fn runtime_incarnation(identity: &LocalProfileIdentityAuthorityV1) -> Result<StoreIncarnationV1> {
let process_run_id = tracedecay_runtime_core::runtime_identity::process_run_id();
let daemon_generation =
Expand Down
4 changes: 4 additions & 0 deletions crates/tracedecay/src/daemon/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ impl DaemonEngine {

/// A doctor-facing read of one project's watch coverage; `git_watcher` is
/// module-private, so the core Doctor route reads through this accessor.
#[hotpath::measure(label = "daemon.engine.git_watcher_health", future = true)]
pub(super) async fn git_watcher_health(
&self,
project_root: Option<&std::path::Path>,
Expand Down Expand Up @@ -303,6 +304,7 @@ impl DaemonEngine {

/// Logs a `daemon_version_skew` event when this handshake's client runs a
/// different binary version, deduped per distinct client version.
#[hotpath::measure(label = "daemon.engine.log_version_skew", future = true)]
pub(super) async fn log_client_version_skew(&self, handshake: &DaemonHandshake) -> Result<()> {
let Some(client_version) = self.client_version_skew_to_log(handshake).await? else {
return Ok(());
Expand Down Expand Up @@ -334,6 +336,7 @@ impl DaemonEngine {
/// exactly what arms its notification for the first request after warm-up
/// completes; marking it would strand the provisional catalog for the rest
/// of the daemon's life, because this set is never otherwise cleared.
#[hotpath::measure(label = "daemon.engine.claim_catalog_refresh", future = true)]
pub(super) async fn claim_catalog_refresh(
&self,
handshake: &DaemonHandshake,
Expand Down Expand Up @@ -726,6 +729,7 @@ impl DaemonEngine {
})
}

#[hotpath::measure(label = "daemon.engine.cached_open_failure", future = true)]
pub(super) async fn cached_project_open_failure(
&self,
handshake: &DaemonHandshake,
Expand Down
8 changes: 8 additions & 0 deletions crates/tracedecay/src/daemon/http_application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ impl DaemonHttpApplicationRegistry {
Ok(Some(router))
}

#[hotpath::measure(label = "daemon.http.application.build_registry_router")]
fn router(
self,
admission: LocalHttpAdmission,
Expand Down Expand Up @@ -408,6 +409,7 @@ async fn provision_remote_node(
}
}

#[hotpath::measure(label = "daemon.http.application.remote_status_read", future = true)]
async fn remote_operational_status(
State(registry): State<DaemonHttpApplicationRegistry>,
) -> Response {
Expand Down Expand Up @@ -654,6 +656,7 @@ impl LocalHttpAdmission {
}
}

#[hotpath::measure(label = "daemon.http.application.local_admission", future = true)]
async fn require_local_http_admission(
State(admission): State<LocalHttpAdmission>,
request: Request<Body>,
Expand Down Expand Up @@ -990,6 +993,7 @@ struct RemoteBrainTlsListener {
}

impl RemoteBrainTlsListener {
#[hotpath::measure(label = "daemon.http.application.tls_bind", future = true)]
async fn bind(config: &RemoteBrainTlsConfig) -> Result<Self> {
let certificates = CertificateDer::pem_file_iter(config.certificate_chain())
.map_err(|error| tls_configuration_error("open Remote Brain TLS certificate", error))?
Expand Down Expand Up @@ -1041,6 +1045,7 @@ impl RemoteBrainTlsListener {
self.listener.local_addr()
}

#[hotpath::measure(label = "daemon.http.application.tls_accept", future = true)]
async fn accept(&self) -> Option<(RemoteBrainTlsIo, SocketAddr)> {
let (stream, address) = match self.listener.accept().await {
Ok(accepted) => accepted,
Expand Down Expand Up @@ -1070,6 +1075,7 @@ impl RemoteBrainTlsListener {
}
}

#[hotpath::measure(label = "daemon.http.application.tls_validate_identity")]
fn validate_remote_brain_tls_identity(
certificates: &[CertificateDer<'_>],
listen: SocketAddr,
Expand Down Expand Up @@ -1434,6 +1440,7 @@ impl RemoteBrainTlsIo {
}
}

#[hotpath::measure(label = "daemon.http.application.observe_http_request")]
fn observe_http_request(&mut self, bytes: &[u8]) -> io::Result<()> {
if self.request_read_complete {
return Ok(());
Expand Down Expand Up @@ -1684,6 +1691,7 @@ impl Drop for RemoteBrainTlsIo {
}
}

#[hotpath::measure(label = "daemon.http.application.parse_body_length")]
fn declared_http11_body_length(header_bytes: &[u8]) -> io::Result<u64> {
let headers = std::str::from_utf8(header_bytes).map_err(|_| {
io::Error::new(
Expand Down
125 changes: 68 additions & 57 deletions crates/tracedecay/src/daemon/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,42 +124,45 @@ impl GuardedStoreTelemetryPort {
store: &'a StoreKeyV1,
observation: TableGrowthObservation,
) -> StorageTelemetryFuture<'a, TableGrowthTelemetryReadV1> {
Box::pin(async move {
if !self.admits(context, store) {
return TableGrowthTelemetryReadV1::Denied {
store: store.clone(),
};
}
let Ok(current) = self
.handle
.table_size_telemetry(self.reader_wait, || telemetry_interruption(context))
else {
return TableGrowthTelemetryReadV1::Unknown {
store: store.clone(),
};
};
let observed_at = now_micros();
let mut current_tables = BTreeMap::new();
for sample in current {
let Ok(table) = TableNameV1::new(sample.table_name) else {
Box::pin(hotpath::future!(
async move {
if !self.admits(context, store) {
return TableGrowthTelemetryReadV1::Denied {
store: store.clone(),
};
}
let Ok(current) = self
.handle
.table_size_telemetry(self.reader_wait, || telemetry_interruption(context))
else {
return TableGrowthTelemetryReadV1::Unknown {
store: store.clone(),
};
};
current_tables.insert(table, StorageByteSizeV1(sample.bytes));
}
let mut watermarks = match self.table_watermarks.lock() {
Ok(watermarks) => watermarks,
Err(poisoned) => poisoned.into_inner(),
};
compare_table_growth(
store,
current_tables,
observed_at,
&mut watermarks,
observation,
)
})
let observed_at = now_micros();
let mut current_tables = BTreeMap::new();
for sample in current {
let Ok(table) = TableNameV1::new(sample.table_name) else {
return TableGrowthTelemetryReadV1::Unknown {
store: store.clone(),
};
};
current_tables.insert(table, StorageByteSizeV1(sample.bytes));
}
let mut watermarks = match self.table_watermarks.lock() {
Ok(watermarks) => watermarks,
Err(poisoned) => poisoned.into_inner(),
};
compare_table_growth(
store,
current_tables,
observed_at,
&mut watermarks,
observation,
)
},
label = "daemon.maintenance.read_table_growth"
))
}
}

Expand All @@ -169,34 +172,37 @@ impl StoreSizeTelemetryPort for GuardedStoreTelemetryPort {
context: &'a RequestContext,
store: &'a StoreKeyV1,
) -> StorageTelemetryFuture<'a, StorageTelemetryReadV1> {
Box::pin(async move {
if !self.admits(context, store) {
return StorageTelemetryReadV1::Denied {
store: store.clone(),
};
}
let Ok(sample) = self
.handle
.store_size_telemetry(self.reader_wait, || telemetry_interruption(context))
else {
return StorageTelemetryReadV1::Unknown {
store: store.clone(),
Box::pin(hotpath::future!(
async move {
if !self.admits(context, store) {
return StorageTelemetryReadV1::Denied {
store: store.clone(),
};
}
let Ok(sample) = self
.handle
.store_size_telemetry(self.reader_wait, || telemetry_interruption(context))
else {
return StorageTelemetryReadV1::Unknown {
store: store.clone(),
};
};
};
let sample = StoreSizeSampleV1 {
store: store.clone(),
page_size_bytes: sample.page_size_bytes,
page_count: sample.page_count,
freelist_pages: sample.freelist_pages,
observed_at: now_micros(),
};
if sample.validate().is_err() {
return StorageTelemetryReadV1::Unknown {
let sample = StoreSizeSampleV1 {
store: store.clone(),
page_size_bytes: sample.page_size_bytes,
page_count: sample.page_count,
freelist_pages: sample.freelist_pages,
observed_at: now_micros(),
};
}
StorageTelemetryReadV1::Observed { sample }
})
if sample.validate().is_err() {
return StorageTelemetryReadV1::Unknown {
store: store.clone(),
};
}
StorageTelemetryReadV1::Observed { sample }
},
label = "daemon.maintenance.read_store_size"
))
}

fn table_growth<'a>(
Expand All @@ -208,6 +214,7 @@ impl StoreSizeTelemetryPort for GuardedStoreTelemetryPort {
}
}

#[hotpath::measure(label = "daemon.maintenance.compare_table_growth")]
fn compare_table_growth(
store: &StoreKeyV1,
current_tables: BTreeMap<TableNameV1, StorageByteSizeV1>,
Expand Down Expand Up @@ -720,6 +727,7 @@ impl StoreTelemetrySamplingRegistry {
)
}

#[hotpath::measure(label = "daemon.maintenance.sample_store_telemetry", future = true)]
async fn advance_registered(
&self,
active_paths: &BTreeSet<PathBuf>,
Expand Down Expand Up @@ -759,6 +767,7 @@ impl StoreTelemetrySamplingRegistry {
}
}

#[hotpath::measure(label = "daemon.maintenance.mint_telemetry_context")]
fn storage_telemetry_request_context(
scope: ResolvedScope,
) -> Result<RequestContext, ApplicationContractError> {
Expand Down Expand Up @@ -1778,11 +1787,13 @@ fn checkpoint_path(profile_root: &Path) -> PathBuf {
.join(CHECKPOINT_FILE)
}

#[hotpath::measure(label = "daemon.maintenance.load_cursor")]
fn load_cursor(path: &Path) -> Option<ColdStoreCursorV1> {
let bytes = std::fs::read(path).ok()?;
serde_json::from_slice(&bytes).ok()
}

#[hotpath::measure(label = "daemon.maintenance.persist_cursor")]
fn persist_cursor(path: &Path, cursor: &ColdStoreCursorV1) -> std::io::Result<()> {
let parent = path
.parent()
Expand Down
Loading
Loading