наблюдаемость: измерять бюджет каталога MCP
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user