feat(epic4): публиковать execution mode и применять общий admission (Story 4.1, FR-21, FR-24)
CI / UI Checks (pull_request) Successful in 11s
CI / Rust Checks (pull_request) Successful in 12m45s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped
Community Release / release (push) Successful in 40m35s
CI / UI Checks (pull_request) Successful in 11s
CI / Rust Checks (pull_request) Successful in 12m45s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped
Community Release / release (push) Successful in 40m35s
Tool Draft фиксирует synchronous/background/adaptive, deadline и fallback; runtime применяет единый снимок политики (concurrency, очередь, approval, deadline) до внешнего действия. Насыщение отклоняется typed overload с retry guidance, mandatory safety store fail closed, background/adaptive используют опубликованный synchronous/unsupported fallback. Refs: #29
This commit is contained in:
1 parent
44774883a0
commit
e80d30ddb0
72 files changed
+4157
-121
No files matched your search
@@ -217,6 +217,34 @@ string_enum! {
|
||||
Concurrency => "concurrency",
|
||||
RateLimit => "rate_limit",
|
||||
McpStream => "mcp_stream",
|
||||
Admission => "admission",
|
||||
}
|
||||
}
|
||||
|
||||
string_enum! {
|
||||
pub enum RejectionReason {
|
||||
Limit => "limit",
|
||||
Capacity => "capacity",
|
||||
QueueFull => "queue_full",
|
||||
Deadline => "deadline",
|
||||
Unsupported => "unsupported",
|
||||
DependencyUnavailable => "dependency_unavailable",
|
||||
}
|
||||
}
|
||||
|
||||
string_enum! {
|
||||
pub enum ScopeKind {
|
||||
Process => "process",
|
||||
Global => "global",
|
||||
Agent => "agent",
|
||||
Tool => "tool",
|
||||
}
|
||||
}
|
||||
|
||||
string_enum! {
|
||||
pub enum AdmissionModeLabel {
|
||||
Synchronous => "synchronous",
|
||||
Background => "background",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,15 @@ mod schema;
|
||||
|
||||
pub use exemplar::{ExemplarObservation, ExemplarTraceId, exemplar_snapshot};
|
||||
pub use labels::{
|
||||
CacheOutcome, ConfirmationOutcome, DbPoolState, Exporter, HttpMethod, HttpRoute,
|
||||
HttpStatusClass, IdempotencyOutcome, InvocationSource, LimitStage, McpMethod, McpOutcome,
|
||||
McpResponseMode, SignalType, ToolErrorKind, ToolOutcome, UpstreamOperationKind,
|
||||
UpstreamOutcome,
|
||||
AdmissionModeLabel, CacheOutcome, ConfirmationOutcome, DbPoolState, Exporter, HttpMethod,
|
||||
HttpRoute, HttpStatusClass, IdempotencyOutcome, InvocationSource, LimitStage, McpMethod,
|
||||
McpOutcome, McpResponseMode, RejectionReason, ScopeKind, SignalType, ToolErrorKind,
|
||||
ToolOutcome, UpstreamOperationKind, UpstreamOutcome,
|
||||
};
|
||||
pub use record::{
|
||||
InFlightGuard, ToolInvocationMetrics, UpstreamRequestMetrics, bind_metric_service,
|
||||
bound_metric_service, initialize_gauges, normalize_http_route, record_cache_outcome,
|
||||
bound_metric_service, initialize_gauges, normalize_http_route, record_admission_oldest_waiting,
|
||||
record_admission_queue_wait, record_admission_rejection, record_cache_outcome,
|
||||
record_confirmation_outcome, record_export_failure, record_http_request,
|
||||
record_http_request_with_exemplar, record_idempotency_outcome, record_invocation_history_lost,
|
||||
record_limit_rejection, record_mcp_request, record_mcp_request_with_exemplar,
|
||||
|
||||
@@ -5,10 +5,10 @@ use metrics::Gauge;
|
||||
|
||||
use crate::schema::{MetricDefinition, metric_schema};
|
||||
use crate::{
|
||||
CacheOutcome, ConfirmationOutcome, DbPoolState, ExemplarTraceId, Exporter, HttpMethod,
|
||||
HttpRoute, HttpStatusClass, IdempotencyOutcome, InvocationSource, LimitStage, McpMethod,
|
||||
McpOutcome, McpResponseMode, MetricBindingError, MetricService, SignalType, ToolErrorKind,
|
||||
ToolOutcome, UpstreamOperationKind, UpstreamOutcome,
|
||||
AdmissionModeLabel, CacheOutcome, ConfirmationOutcome, DbPoolState, ExemplarTraceId, Exporter,
|
||||
HttpMethod, HttpRoute, HttpStatusClass, IdempotencyOutcome, InvocationSource, LimitStage,
|
||||
McpMethod, McpOutcome, McpResponseMode, MetricBindingError, MetricService, RejectionReason,
|
||||
ScopeKind, SignalType, ToolErrorKind, ToolOutcome, UpstreamOperationKind, UpstreamOutcome,
|
||||
};
|
||||
|
||||
static BINDING: OnceLock<MetricService> = OnceLock::new();
|
||||
@@ -352,11 +352,47 @@ pub fn record_limit_rejection(stage: LimitStage) {
|
||||
}
|
||||
metrics::counter!(
|
||||
"crank_runtime_limit_rejections_total",
|
||||
"stage" => stage.as_str()
|
||||
"stage" => stage.as_str(),
|
||||
"reason" => RejectionReason::Limit.as_str(),
|
||||
"scope_kind" => ScopeKind::Process.as_str()
|
||||
)
|
||||
.increment(1);
|
||||
}
|
||||
|
||||
/// Typed admission refusal with finite, low-cardinality labels only: no workspace, Agent, Tool,
|
||||
/// request id, fingerprint or arbitrary error text ever becomes a label.
|
||||
pub fn record_admission_rejection(reason: RejectionReason, scope_kind: ScopeKind) {
|
||||
if bound_family("crank_runtime_limit_rejections_total").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::counter!(
|
||||
"crank_runtime_limit_rejections_total",
|
||||
"stage" => LimitStage::Admission.as_str(),
|
||||
"reason" => reason.as_str(),
|
||||
"scope_kind" => scope_kind.as_str()
|
||||
)
|
||||
.increment(1);
|
||||
}
|
||||
|
||||
pub fn record_admission_queue_wait(mode: AdmissionModeLabel, waited_ms: u64) {
|
||||
if bound_family("crank_runtime_admission_queue_wait_seconds").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::gauge!(
|
||||
"crank_runtime_admission_queue_wait_seconds",
|
||||
"mode" => mode.as_str()
|
||||
)
|
||||
.set(waited_ms as f64 / 1000.0);
|
||||
}
|
||||
|
||||
pub fn record_admission_oldest_waiting(oldest_waiting_ms: Option<u64>) {
|
||||
if bound_family("crank_runtime_admission_oldest_waiting_seconds").is_none() {
|
||||
return;
|
||||
}
|
||||
let seconds = oldest_waiting_ms.unwrap_or_default() as f64 / 1000.0;
|
||||
metrics::gauge!("crank_runtime_admission_oldest_waiting_seconds").set(seconds);
|
||||
}
|
||||
|
||||
pub fn record_cache_outcome(outcome: CacheOutcome) {
|
||||
if bound_family("crank_runtime_cache_total").is_none() {
|
||||
return;
|
||||
|
||||
@@ -3,16 +3,17 @@
|
||||
|
||||
use super::routes::{BOTH, HTTP_ROUTE_DOMAIN, MCP};
|
||||
use crate::labels::{
|
||||
CacheOutcome, ConfirmationOutcome, DbPoolState, Exporter, HttpMethod, HttpStatusClass,
|
||||
IdempotencyOutcome, InvocationSource, LimitStage, McpMethod, McpOutcome, McpResponseMode,
|
||||
SignalType, ToolErrorKind, ToolOutcome, UpstreamOperationKind, UpstreamOutcome,
|
||||
AdmissionModeLabel, CacheOutcome, ConfirmationOutcome, DbPoolState, Exporter, HttpMethod,
|
||||
HttpStatusClass, IdempotencyOutcome, InvocationSource, LimitStage, McpMethod, McpOutcome,
|
||||
McpResponseMode, RejectionReason, ScopeKind, SignalType, ToolErrorKind, ToolOutcome,
|
||||
UpstreamOperationKind, UpstreamOutcome,
|
||||
};
|
||||
|
||||
pub const METRIC_SCHEMA_VERSION: u32 = 2;
|
||||
pub const MAX_METRIC_FAMILIES: usize = 128;
|
||||
pub const MAX_PRODUCT_LABELS_PER_FAMILY: usize = 4;
|
||||
pub const MAX_LOGICAL_SERIES_PER_PROCESS: usize = 6_285;
|
||||
pub const MAX_RENDERED_SERIES_PER_PROCESS: usize = 19_515;
|
||||
pub const MAX_LOGICAL_SERIES_PER_PROCESS: usize = 6_381;
|
||||
pub const MAX_RENDERED_SERIES_PER_PROCESS: usize = 19_611;
|
||||
pub const MAX_EXEMPLAR_SLOTS_PER_PROCESS: usize = 12_348;
|
||||
pub const MAX_EXPOSITION_BYTES: usize = 8 * 1024 * 1024;
|
||||
|
||||
@@ -179,6 +180,9 @@ const TOOL_ERRORS: &[&str] = ToolErrorKind::VALUES;
|
||||
const OPERATION_KINDS: &[&str] = UpstreamOperationKind::VALUES;
|
||||
const UPSTREAM_OUTCOMES: &[&str] = UpstreamOutcome::VALUES;
|
||||
const LIMIT_STAGES: &[&str] = LimitStage::VALUES;
|
||||
const REJECTION_REASONS: &[&str] = RejectionReason::VALUES;
|
||||
const SCOPE_KINDS: &[&str] = ScopeKind::VALUES;
|
||||
const ADMISSION_MODES: &[&str] = AdmissionModeLabel::VALUES;
|
||||
const CACHE_OUTCOMES: &[&str] = CacheOutcome::VALUES;
|
||||
const IDEMPOTENCY_OUTCOMES: &[&str] = IdempotencyOutcome::VALUES;
|
||||
const CONFIRMATION_OUTCOMES: &[&str] = ConfirmationOutcome::VALUES;
|
||||
@@ -403,13 +407,39 @@ pub(crate) const METRIC_SCHEMA: &[MetricDefinition] = &[
|
||||
"crank_runtime_limit_rejections_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["stage"],
|
||||
&[domain("stage", LIMIT_STAGES)],
|
||||
&["stage", "reason", "scope_kind"],
|
||||
&[
|
||||
domain("stage", LIMIT_STAGES),
|
||||
domain("reason", REJECTION_REASONS),
|
||||
domain("scope_kind", SCOPE_KINDS),
|
||||
],
|
||||
&[],
|
||||
BOTH,
|
||||
3,
|
||||
96,
|
||||
"Runtime executions rejected by a bounded limit.",
|
||||
),
|
||||
metric(
|
||||
"crank_runtime_admission_queue_wait_seconds",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Seconds,
|
||||
&["mode"],
|
||||
&[domain("mode", ADMISSION_MODES)],
|
||||
&[],
|
||||
BOTH,
|
||||
2,
|
||||
"Wait of the most recently admitted execution before it received a scoped permit.",
|
||||
),
|
||||
metric(
|
||||
"crank_runtime_admission_oldest_waiting_seconds",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Seconds,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
BOTH,
|
||||
1,
|
||||
"Age of the oldest waiting admission request.",
|
||||
),
|
||||
metric(
|
||||
"crank_runtime_cache_total",
|
||||
MetricKind::Counter,
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
use std::{collections::BTreeSet, time::Duration};
|
||||
|
||||
use crank_metrics::{
|
||||
CacheOutcome, ConfirmationOutcome, DbPoolState, Exporter, HttpMethod, HttpRoute,
|
||||
HttpStatusClass, IdempotencyOutcome, InFlightGuard, InvocationSource, LimitStage, McpMethod,
|
||||
McpOutcome, McpResponseMode, MetricService, SignalType, ToolErrorKind, ToolInvocationMetrics,
|
||||
ToolOutcome, UpstreamOperationKind, UpstreamOutcome, UpstreamRequestMetrics,
|
||||
bind_metric_service, initialize_gauges, metric_schema, record_cache_outcome,
|
||||
record_confirmation_outcome, record_export_failure, record_http_request,
|
||||
AdmissionModeLabel, CacheOutcome, ConfirmationOutcome, DbPoolState, Exporter, HttpMethod,
|
||||
HttpRoute, HttpStatusClass, IdempotencyOutcome, InFlightGuard, InvocationSource, LimitStage,
|
||||
McpMethod, McpOutcome, McpResponseMode, MetricService, RejectionReason, ScopeKind, SignalType,
|
||||
ToolErrorKind, ToolInvocationMetrics, ToolOutcome, UpstreamOperationKind, UpstreamOutcome,
|
||||
UpstreamRequestMetrics, bind_metric_service, initialize_gauges, metric_schema,
|
||||
record_admission_oldest_waiting, record_admission_queue_wait, record_admission_rejection,
|
||||
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_mcp_session_metrics_fresh,
|
||||
@@ -71,6 +72,9 @@ fn schema_names_are_unique_and_labels_are_closed() {
|
||||
"state",
|
||||
"signal_type",
|
||||
"exporter",
|
||||
"reason",
|
||||
"scope_kind",
|
||||
"mode",
|
||||
];
|
||||
for metric in schema {
|
||||
assert!(
|
||||
@@ -265,6 +269,9 @@ fn every_recording_api_matches_the_declared_schema() {
|
||||
Duration::from_millis(1),
|
||||
);
|
||||
record_limit_rejection(LimitStage::Concurrency);
|
||||
record_admission_rejection(RejectionReason::Capacity, ScopeKind::Global);
|
||||
record_admission_queue_wait(AdmissionModeLabel::Synchronous, 5);
|
||||
record_admission_oldest_waiting(Some(5));
|
||||
record_cache_outcome(CacheOutcome::Hit);
|
||||
record_idempotency_outcome(IdempotencyOutcome::Replay);
|
||||
record_confirmation_outcome(ConfirmationOutcome::Required);
|
||||
|
||||
@@ -48,10 +48,10 @@ fn schema_v1_is_complete_deterministic_and_inside_the_frozen_budget() {
|
||||
|
||||
#[test]
|
||||
fn frozen_budget_edges_are_exact() {
|
||||
assert!(validate_budget(6_284, 19_514).is_ok());
|
||||
assert!(validate_budget(6_285, 19_515).is_ok());
|
||||
assert!(validate_budget(6_286, 16_000).is_err());
|
||||
assert!(validate_budget(6_000, 19_516).is_err());
|
||||
assert!(validate_budget(6_380, 19_610).is_ok());
|
||||
assert!(validate_budget(6_381, 19_611).is_ok());
|
||||
assert!(validate_budget(6_382, 19_000).is_err());
|
||||
assert!(validate_budget(6_000, 19_612).is_err());
|
||||
assert_eq!(
|
||||
crank_metrics::max_exemplar_slots(MetricService::AdminApi),
|
||||
12_348
|
||||
@@ -79,15 +79,15 @@ fn canonical_schema_validation_reports_its_category() {
|
||||
assert_eq!(
|
||||
schema_budget(MetricService::AdminApi),
|
||||
Ok(crank_metrics::SchemaBudget {
|
||||
logical_series: 6_285,
|
||||
rendered_series: 19_515
|
||||
logical_series: 6_381,
|
||||
rendered_series: 19_611
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
schema_budget(MetricService::McpServer),
|
||||
Ok(crank_metrics::SchemaBudget {
|
||||
logical_series: 1_083,
|
||||
rendered_series: 3_558
|
||||
logical_series: 1_179,
|
||||
rendered_series: 3_654
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -543,22 +543,22 @@ fn root_budgets_are_per_process_only() {
|
||||
"root обязан объявлять ровно один ключ budgets"
|
||||
);
|
||||
assert!(rendered.ends_with(
|
||||
",\"budgets\":[{\"process\":\"admin_api\",\"families\":15,\"logical_series\":6285,\
|
||||
\"rendered_series\":19515,\"exemplar_slots\":12348},{\"process\":\"mcp_server\",\
|
||||
\"families\":23,\"logical_series\":1083,\"rendered_series\":3558,\"exemplar_slots\":2310}]}\n"
|
||||
",\"budgets\":[{\"process\":\"admin_api\",\"families\":17,\"logical_series\":6381,\
|
||||
\"rendered_series\":19611,\"exemplar_slots\":12348},{\"process\":\"mcp_server\",\
|
||||
\"families\":25,\"logical_series\":1179,\"rendered_series\":3654,\"exemplar_slots\":2310}]}\n"
|
||||
));
|
||||
assert_eq!(
|
||||
schema_budget(MetricService::AdminApi),
|
||||
Ok(crank_metrics::SchemaBudget {
|
||||
logical_series: 6_285,
|
||||
rendered_series: 19_515
|
||||
logical_series: 6_381,
|
||||
rendered_series: 19_611
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
schema_budget(MetricService::McpServer),
|
||||
Ok(crank_metrics::SchemaBudget {
|
||||
logical_series: 1_083,
|
||||
rendered_series: 3_558
|
||||
logical_series: 1_179,
|
||||
rendered_series: 3_654
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -566,11 +566,11 @@ fn root_budgets_are_per_process_only() {
|
||||
/// TD-M3 — frozen caps и границы `validate_exemplar_budget` точны.
|
||||
#[test]
|
||||
fn frozen_caps_and_edges_are_exact() {
|
||||
assert_eq!(MAX_LOGICAL_SERIES_PER_PROCESS, 6_285);
|
||||
assert_eq!(MAX_RENDERED_SERIES_PER_PROCESS, 19_515);
|
||||
assert_eq!(MAX_LOGICAL_SERIES_PER_PROCESS, 6_381);
|
||||
assert_eq!(MAX_RENDERED_SERIES_PER_PROCESS, 19_611);
|
||||
assert_eq!(MAX_EXEMPLAR_SLOTS_PER_PROCESS, 12_348);
|
||||
assert!(validate_budget(6_285, 19_515).is_ok());
|
||||
assert!(validate_budget(6_286, 19_515).is_err());
|
||||
assert!(validate_budget(6_381, 19_611).is_ok());
|
||||
assert!(validate_budget(6_382, 19_611).is_err());
|
||||
assert!(validate_exemplar_budget(12_347).is_ok());
|
||||
assert!(validate_exemplar_budget(12_348).is_ok());
|
||||
assert!(validate_exemplar_budget(12_349).is_err());
|
||||
|
||||
Reference in new issue
Block a user