наблюдаемость: измерять бюджет каталога MCP
CI / Rust Checks (push) Successful in 12m5s
CI / UI Checks (push) Successful in 9s
CI / Deployment Manifests (push) Successful in 6s
CI / Frontend E2E (push) Failing after 30s
CI / Deploy (push) Has been skipped

This commit is contained in:
2026-07-21 01:59:09 +03:00
parent 0241d186ea
commit 63f8ee333f
10 changed files with 284 additions and 4 deletions
+41 -1
View File
@@ -8,7 +8,9 @@ use crank_core::{CacheScope, CoordinationStateStore, CoordinationStateValue};
use crank_registry::{PostgresRegistry, PublishedAgentTool, RegistryError};
use serde::{Deserialize, Serialize};
use tokio::sync::{Mutex, RwLock};
use tracing::info;
use tracing::{info, warn};
use crate::manifest::analyze_published_tool_catalog;
#[derive(Clone)]
pub struct PublishedToolCatalog {
@@ -105,6 +107,7 @@ impl PublishedToolCatalog {
}
if let Some((tools, age)) = self.load_shared_snapshot(workspace_slug, agent_slug).await {
log_catalog_analysis(workspace_slug, agent_slug, "shared_cache", &tools);
let mut guard = self.cached.write().await;
guard.insert(
key,
@@ -125,6 +128,7 @@ impl PublishedToolCatalog {
Err(RegistryError::PublishedAgentNotFound { .. }) => Vec::new(),
Err(error) => return Err(error),
};
log_catalog_analysis(workspace_slug, agent_slug, "postgres", &tools);
self.store_shared_snapshot(workspace_slug, agent_slug, &tools)
.await;
let mut guard = self.cached.write().await;
@@ -208,6 +212,42 @@ impl PublishedToolCatalog {
}
}
fn log_catalog_analysis(
workspace_slug: &str,
agent_slug: &str,
source: &str,
tools: &[PublishedAgentTool],
) {
let analysis = match analyze_published_tool_catalog(tools) {
Ok(analysis) => analysis,
Err(error) => {
warn!(workspace_slug, agent_slug, source, %error, "published catalog analysis failed");
return;
}
};
let warning_count = analysis
.quality
.findings
.iter()
.filter(|finding| finding.severity == crank_core::ToolQualitySeverity::Warning)
.count();
info!(
workspace_slug,
agent_slug,
source,
tool_count = analysis.budget.tool_count,
serialized_bytes = analysis.budget.serialized_bytes,
estimated_context_tokens = analysis.budget.estimated_context_tokens,
largest_tool_estimated_context_tokens =
analysis.budget.largest_tool_estimated_context_tokens,
recommended_context_tokens = analysis.budget.recommended_context_tokens,
exceeds_recommended_budget = analysis.budget.exceeds_recommended_budget,
catalog_quality_warning_count = warning_count,
"published agent catalog analyzed"
);
}
fn now_unix_ms() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)