fix(metrics): preserve runtime limit rejection labels
CI / UI Checks (pull_request) Successful in 12s
CI / Rust Checks (pull_request) Successful in 38m11s
CI / Rust Feature Validation (pull_request) Failing after 10s
CI / Frontend E2E (pull_request) Failing after 25m28s
CI / Community Image Smoke (pull_request) Failing after 27m22s
CI / Required Checks (pull_request) Failing after 1s
CI / Deploy (pull_request) Skipped
CI / UI Checks (pull_request) Successful in 12s
CI / Rust Checks (pull_request) Successful in 38m11s
CI / Rust Feature Validation (pull_request) Failing after 10s
CI / Frontend E2E (pull_request) Failing after 25m28s
CI / Community Image Smoke (pull_request) Failing after 27m22s
CI / Required Checks (pull_request) Failing after 1s
CI / Deploy (pull_request) Skipped
This commit is contained in:
1 parent
2fa5b9de67
commit
c31a0e8e5c
8 files changed
+92
-43
No files matched your search
@@ -217,13 +217,13 @@ 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",
|
||||
@@ -234,7 +234,7 @@ string_enum! {
|
||||
|
||||
string_enum! {
|
||||
pub enum ScopeKind {
|
||||
Process => "process",
|
||||
|
||||
Global => "global",
|
||||
Agent => "agent",
|
||||
Tool => "tool",
|
||||
|
||||
@@ -350,24 +350,18 @@ pub fn record_limit_rejection(stage: LimitStage) {
|
||||
if bound_family("crank_runtime_limit_rejections_total").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::counter!(
|
||||
"crank_runtime_limit_rejections_total",
|
||||
"stage" => stage.as_str(),
|
||||
"reason" => RejectionReason::Limit.as_str(),
|
||||
"scope_kind" => ScopeKind::Process.as_str()
|
||||
)
|
||||
.increment(1);
|
||||
metrics::counter!("crank_runtime_limit_rejections_total", "stage" => stage.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() {
|
||||
if bound_family("crank_runtime_admission_rejections_total").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::counter!(
|
||||
"crank_runtime_limit_rejections_total",
|
||||
"stage" => LimitStage::Admission.as_str(),
|
||||
"crank_runtime_admission_rejections_total",
|
||||
"reason" => reason.as_str(),
|
||||
"scope_kind" => scope_kind.as_str()
|
||||
)
|
||||
|
||||
@@ -407,16 +407,26 @@ pub(crate) const METRIC_SCHEMA: &[MetricDefinition] = &[
|
||||
"crank_runtime_limit_rejections_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["stage", "reason", "scope_kind"],
|
||||
&["stage"],
|
||||
&[domain("stage", LIMIT_STAGES)],
|
||||
&[],
|
||||
BOTH,
|
||||
3,
|
||||
"Runtime executions rejected by a bounded limit.",
|
||||
),
|
||||
metric(
|
||||
"crank_runtime_admission_rejections_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["reason", "scope_kind"],
|
||||
&[
|
||||
domain("stage", LIMIT_STAGES),
|
||||
domain("reason", REJECTION_REASONS),
|
||||
domain("scope_kind", SCOPE_KINDS),
|
||||
],
|
||||
&[],
|
||||
BOTH,
|
||||
96,
|
||||
"Runtime executions rejected by a bounded limit.",
|
||||
15,
|
||||
"Runtime executions rejected by scoped admission.",
|
||||
),
|
||||
metric(
|
||||
"crank_runtime_admission_queue_wait_seconds",
|
||||
|
||||
@@ -12,7 +12,7 @@ use crank_metrics::{
|
||||
record_mcp_request, record_tool_invocation, record_upstream_request, set_catalog,
|
||||
set_db_pool_connections, set_mcp_active_sessions, set_mcp_session_metrics_fresh,
|
||||
};
|
||||
use metrics_util::debugging::DebuggingRecorder;
|
||||
use metrics_util::debugging::{DebugValue, DebuggingRecorder};
|
||||
|
||||
/// Service binding is process-global (`OnceLock`), so every case that needs a
|
||||
/// different service runs in a fresh child re-executed from this same test
|
||||
@@ -282,6 +282,33 @@ fn every_recording_api_matches_the_declared_schema() {
|
||||
});
|
||||
|
||||
let snapshot = snapshotter.snapshot().into_vec();
|
||||
for (name, labels) in [
|
||||
(
|
||||
"crank_runtime_limit_rejections_total",
|
||||
BTreeSet::from([("stage", "concurrency")]),
|
||||
),
|
||||
(
|
||||
"crank_runtime_admission_rejections_total",
|
||||
BTreeSet::from([("reason", "capacity"), ("scope_kind", "global")]),
|
||||
),
|
||||
] {
|
||||
let mut samples = snapshot
|
||||
.iter()
|
||||
.filter(|(key, _, _, _)| key.key().name() == name);
|
||||
let (key, _, _, value) = samples.next().expect(name);
|
||||
assert!(
|
||||
samples.next().is_none(),
|
||||
"unexpected extra series for {name}"
|
||||
);
|
||||
assert_eq!(
|
||||
key.key()
|
||||
.labels()
|
||||
.map(|label| (label.key(), label.value()))
|
||||
.collect::<BTreeSet<_>>(),
|
||||
labels
|
||||
);
|
||||
assert!(matches!(value, DebugValue::Counter(1)), "{name}: {value:?}");
|
||||
}
|
||||
let actual_names = snapshot
|
||||
.iter()
|
||||
.map(|(key, _, _, _)| key.key().name().to_owned())
|
||||
|
||||
@@ -11,7 +11,7 @@ use crank_metrics::{
|
||||
#[test]
|
||||
fn schema_v1_is_complete_deterministic_and_inside_the_frozen_budget() {
|
||||
assert_eq!(METRIC_SCHEMA_VERSION, 2);
|
||||
assert_eq!(metric_schema().len(), 23);
|
||||
assert_eq!(metric_schema().len(), 26);
|
||||
|
||||
for service in [MetricService::AdminApi, MetricService::McpServer] {
|
||||
let budget = schema_budget(service).expect("canonical schema must be valid");
|
||||
@@ -79,15 +79,15 @@ fn canonical_schema_validation_reports_its_category() {
|
||||
assert_eq!(
|
||||
schema_budget(MetricService::AdminApi),
|
||||
Ok(crank_metrics::SchemaBudget {
|
||||
logical_series: 6_381,
|
||||
rendered_series: 19_611
|
||||
logical_series: 6_303,
|
||||
rendered_series: 19_533
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
schema_budget(MetricService::McpServer),
|
||||
Ok(crank_metrics::SchemaBudget {
|
||||
logical_series: 1_179,
|
||||
rendered_series: 3_654
|
||||
logical_series: 1_101,
|
||||
rendered_series: 3_576
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -343,13 +343,25 @@ fn v1_and_v2_registries_are_metric_by_metric_compatible() {
|
||||
let v1 = metric_objects(V1);
|
||||
let v2 = metric_objects(V2);
|
||||
assert_eq!(v1.len(), 23);
|
||||
let admission_families = [
|
||||
"crank_runtime_admission_rejections_total",
|
||||
"crank_runtime_admission_queue_wait_seconds",
|
||||
"crank_runtime_admission_oldest_waiting_seconds",
|
||||
];
|
||||
let (admission, v2_legacy): (Vec<_>, Vec<_>) = v2
|
||||
.iter()
|
||||
.partition(|(name, _)| admission_families.contains(&name.as_str()));
|
||||
assert_eq!(
|
||||
v1.iter().map(|(name, _)| name.clone()).collect::<Vec<_>>(),
|
||||
v2.iter().map(|(name, _)| name.clone()).collect::<Vec<_>>(),
|
||||
"v2 обязан сохранить тот же набор и порядок family"
|
||||
admission
|
||||
.iter()
|
||||
.map(|(name, _)| name.as_str())
|
||||
.collect::<Vec<_>>(),
|
||||
admission_families
|
||||
);
|
||||
assert_eq!(v1.len(), v2_legacy.len());
|
||||
|
||||
for ((name, v1_object), (_, v2_object)) in v1.iter().zip(v2.iter()) {
|
||||
for ((name, v1_object), (v2_name, v2_object)) in v1.iter().zip(v2_legacy) {
|
||||
assert_eq!(name, v2_name, "v2 обязан сохранить порядок v1 family");
|
||||
for field in ["kind", "unit", "help", "processes", "buckets_seconds"] {
|
||||
assert_eq!(
|
||||
json_field(v1_object, field),
|
||||
|
||||
@@ -543,22 +543,22 @@ fn root_budgets_are_per_process_only() {
|
||||
"root обязан объявлять ровно один ключ budgets"
|
||||
);
|
||||
assert!(rendered.ends_with(
|
||||
",\"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"
|
||||
",\"budgets\":[{\"process\":\"admin_api\",\"families\":18,\"logical_series\":6303,\
|
||||
\"rendered_series\":19533,\"exemplar_slots\":12348},{\"process\":\"mcp_server\",\
|
||||
\"families\":26,\"logical_series\":1101,\"rendered_series\":3576,\"exemplar_slots\":2310}]}\n"
|
||||
));
|
||||
assert_eq!(
|
||||
schema_budget(MetricService::AdminApi),
|
||||
Ok(crank_metrics::SchemaBudget {
|
||||
logical_series: 6_381,
|
||||
rendered_series: 19_611
|
||||
logical_series: 6_303,
|
||||
rendered_series: 19_533
|
||||
})
|
||||
);
|
||||
assert_eq!(
|
||||
schema_budget(MetricService::McpServer),
|
||||
Ok(crank_metrics::SchemaBudget {
|
||||
logical_series: 1_179,
|
||||
rendered_series: 3_654
|
||||
logical_series: 1_101,
|
||||
rendered_series: 3_576
|
||||
})
|
||||
);
|
||||
}
|
||||
@@ -751,7 +751,7 @@ fn service_projection_cache_is_allocated_once() {
|
||||
}
|
||||
assert_eq!(
|
||||
metric_schema().len(),
|
||||
23,
|
||||
"union metadata сохраняет 23 family"
|
||||
26,
|
||||
"union metadata сохраняет 23 family v1 и три family admission"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user