feat: freeze typed metrics registry and bounded exemplars
This commit is contained in:
@@ -8,7 +8,7 @@ use crank_metrics::{
|
||||
metric_schema, record_cache_outcome, record_confirmation_outcome, record_export_failure,
|
||||
record_http_request, record_idempotency_outcome, record_invocation_history_lost,
|
||||
record_limit_rejection, record_mcp_request, record_tool_invocation, record_upstream_request,
|
||||
set_catalog, set_db_pool_connections, set_mcp_active_sessions,
|
||||
set_catalog, set_db_pool_connections, set_mcp_active_sessions, set_mcp_session_metrics_fresh,
|
||||
};
|
||||
use metrics_util::debugging::DebuggingRecorder;
|
||||
|
||||
@@ -80,6 +80,26 @@ fn application_outcomes_are_distinct_from_transport_success() {
|
||||
assert_eq!(ConfirmationOutcome::Required.as_str(), "required");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn impossible_tool_outcome_pairs_are_normalized() {
|
||||
let recorder = DebuggingRecorder::new();
|
||||
let snapshotter = recorder.snapshotter();
|
||||
metrics::with_local_recorder(&recorder, || {
|
||||
record_tool_invocation(
|
||||
InvocationSource::AgentToolCall,
|
||||
ToolOutcome::Success,
|
||||
ToolErrorKind::Mapping,
|
||||
Duration::ZERO,
|
||||
);
|
||||
});
|
||||
let snapshot = snapshotter.snapshot().into_vec();
|
||||
assert!(snapshot.iter().any(|(key, _, _, _)| {
|
||||
key.key().name() == "crank_tool_invocations_total"
|
||||
&& has_label(key.key(), "outcome", "success")
|
||||
&& has_label(key.key(), "error_kind", "none")
|
||||
}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dropped_product_guards_record_aborted_outcomes() {
|
||||
let recorder = DebuggingRecorder::new();
|
||||
@@ -128,6 +148,7 @@ fn diverse_calls_cannot_create_unbounded_series() {
|
||||
McpMethod::ToolsCall,
|
||||
McpResponseMode::Json,
|
||||
McpOutcome::ToolError,
|
||||
Duration::from_millis(1),
|
||||
);
|
||||
record_tool_invocation(
|
||||
InvocationSource::AgentToolCall,
|
||||
@@ -147,7 +168,7 @@ fn diverse_calls_cannot_create_unbounded_series() {
|
||||
.map(|(key, _, _, _)| format!("{:?}", key.key()))
|
||||
.collect::<BTreeSet<_>>();
|
||||
|
||||
assert_eq!(series.len(), 8);
|
||||
assert_eq!(series.len(), 9);
|
||||
assert!(
|
||||
series
|
||||
.iter()
|
||||
@@ -172,8 +193,10 @@ fn every_recording_api_matches_the_declared_schema() {
|
||||
McpMethod::ToolsCall,
|
||||
McpResponseMode::Json,
|
||||
McpOutcome::Success,
|
||||
Duration::from_millis(1),
|
||||
);
|
||||
set_mcp_active_sessions(1);
|
||||
set_mcp_session_metrics_fresh(true);
|
||||
let _stream = InFlightGuard::mcp_stream();
|
||||
let _runtime = InFlightGuard::runtime();
|
||||
record_tool_invocation(
|
||||
|
||||
Reference in New Issue
Block a user