feat(epic3): deliver the accepted Epic 3 scope through Story 3.17
CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
CI / Rust Checks (pull_request) Failing after 13m41s
CI / UI Checks (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Deploy (pull_request) Skipped
Community Release / release (push) Failing after 13m33s
Recovery delivery of the accumulated, TL-accepted Epic 3 work that had never been
committed to Git (stories 3.6-3.17, see the crank board). Story 3.18 is not accepted
yet and is deliberately excluded: its logging surface, its capability registration,
its oracle projections and its tests are not part of this tree.
Accepted scope
- 3.6 typed static Resource Drafts; 3.7 publication and exact binding of static
Resource Versions; 3.8 MCP discovery/read and revocation of static Resources;
- 3.9 Resource import/export in API and UI plus TLS dependency maintenance;
3.10 REST-backed Resource templates; 3.11 shared REST read runtime and the MCP
revision/capability foundation;
- 3.12 parameterised Prompt Drafts with preview; 3.13 Prompt publication and exact
version binding to Agents; 3.14 MCP prompts; 3.15 Prompt import/export;
- 3.16 composite Prompts with published Resources (dependency content scan plus
dynamic read through the accepted 3.11 runtime, admin preview and MCP prompts/get);
- 3.17 bounded MCP completion suggestions from typed published schemas and the
resources/list admission fix for bound template publications.
Accepted evidence being reused (unchanged code paths)
- 3.16 candidate: core 7, admin-api 22, registry 4, mcp-server 4, UI 6; one final
`just verify` run 1651 passed / 0 failed / 2 ignored.
- 3.17 candidate: full run 1672 passed / 0 failed / 2 ignored, QA targeted reruns and
a real MCP Inspector 2.12.0 client smoke.
Delivery engineering in this commit
- CI: one event per change (feature branches are gated by their pull request, push
runs only on main), story events run the changed packages, the full workspace suite
stays the feature/release gate; no cache/sharding without a measured runner check.
- Release: the packaged archives, checksums and SBOM are now uploaded to the Gitea
release entry of the tag instead of dying with the runner workspace.
Not included on purpose: Story 3.18 work, build caches, runtime databases, local
credentials and scratch evidence.
Refs: crank kanban t_e39d7263; baseline 1b6db09bd1.
This commit is contained in:
1 parent
1b6db09bd1
commit
54ce770682
357 files changed
+117394
-5115
No files matched your search
@@ -1,14 +1,63 @@
|
||||
use std::sync::OnceLock;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
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, SignalType, ToolErrorKind, ToolOutcome, UpstreamOperationKind,
|
||||
UpstreamOutcome,
|
||||
McpOutcome, McpResponseMode, MetricBindingError, MetricService, SignalType, ToolErrorKind,
|
||||
ToolOutcome, UpstreamOperationKind, UpstreamOutcome,
|
||||
};
|
||||
|
||||
static BINDING: OnceLock<MetricService> = OnceLock::new();
|
||||
|
||||
/// Publishes the closed process identity exactly once, before the recorder,
|
||||
/// gauges, producers and any listener exist. Re-binding the same service is
|
||||
/// idempotent; a different service is a typed conflict and never wins twice.
|
||||
pub fn bind_metric_service(service: MetricService) -> Result<(), MetricBindingError> {
|
||||
crate::schema::validate_all_projections().map_err(|_| MetricBindingError::InvalidSchema)?;
|
||||
// `OnceLock::set` returns `Err(value)` (the value passed in, not the stored
|
||||
// one), so the idempotency check must read the published binding back.
|
||||
if BINDING.set(service).is_ok() {
|
||||
return Ok(());
|
||||
}
|
||||
match BINDING.get() {
|
||||
Some(existing) if *existing == service => Ok(()),
|
||||
_ => Err(MetricBindingError::ConflictingService),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bound_metric_service() -> Option<MetricService> {
|
||||
BINDING.get().copied()
|
||||
}
|
||||
|
||||
/// Normalises one route against the bound service: own and shared routes are
|
||||
/// preserved, a known route owned by another service degrades to `unmatched`.
|
||||
pub fn normalize_http_route(service: MetricService, route: HttpRoute) -> HttpRoute {
|
||||
match crate::http_route_processes(route.as_str()) {
|
||||
Some(owners) if owners.contains(&service.process()) => route,
|
||||
_ => HttpRoute::unmatched(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn family_applies(service: MetricService, name: &'static str) -> bool {
|
||||
metric_schema()
|
||||
.iter()
|
||||
.find(|definition| definition.name == name)
|
||||
.is_some_and(|definition: &MetricDefinition| {
|
||||
definition.processes.contains(&service.process())
|
||||
})
|
||||
}
|
||||
|
||||
/// Unbound facades (plain unit tests or libraries without observability) are a
|
||||
/// safe no-op; the process never registers a metric handle or exemplar entry.
|
||||
fn bound_family(name: &'static str) -> Option<MetricService> {
|
||||
let service = BINDING.get().copied()?;
|
||||
family_applies(service, name).then_some(service)
|
||||
}
|
||||
|
||||
pub fn record_http_request(
|
||||
route: HttpRoute,
|
||||
method: HttpMethod,
|
||||
@@ -25,6 +74,10 @@ pub fn record_http_request_with_exemplar(
|
||||
duration: Duration,
|
||||
exemplar: Option<ExemplarTraceId>,
|
||||
) {
|
||||
let Some(service) = bound_family("crank_http_requests_total") else {
|
||||
return;
|
||||
};
|
||||
let route = normalize_http_route(service, route);
|
||||
metrics::counter!(
|
||||
"crank_http_requests_total",
|
||||
"route" => route.as_str(),
|
||||
@@ -39,6 +92,7 @@ pub fn record_http_request_with_exemplar(
|
||||
)
|
||||
.record(duration.as_secs_f64());
|
||||
crate::exemplar::record_exemplar(
|
||||
service,
|
||||
"crank_http_request_duration_seconds",
|
||||
vec![("route", route.as_str()), ("method", method.as_str())],
|
||||
duration.as_secs_f64(),
|
||||
@@ -62,6 +116,9 @@ pub fn record_mcp_request_with_exemplar(
|
||||
duration: Duration,
|
||||
exemplar: Option<ExemplarTraceId>,
|
||||
) {
|
||||
let Some(service) = bound_family("crank_mcp_requests_total") else {
|
||||
return;
|
||||
};
|
||||
metrics::counter!(
|
||||
"crank_mcp_requests_total",
|
||||
"method" => method.as_str(),
|
||||
@@ -76,6 +133,7 @@ pub fn record_mcp_request_with_exemplar(
|
||||
)
|
||||
.record(duration.as_secs_f64());
|
||||
crate::exemplar::record_exemplar(
|
||||
service,
|
||||
"crank_mcp_request_duration_seconds",
|
||||
vec![("method", method.as_str()), ("outcome", outcome.as_str())],
|
||||
duration.as_secs_f64(),
|
||||
@@ -84,10 +142,16 @@ pub fn record_mcp_request_with_exemplar(
|
||||
}
|
||||
|
||||
pub fn set_mcp_active_sessions(count: u64) {
|
||||
if bound_family("crank_mcp_active_sessions").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::gauge!("crank_mcp_active_sessions").set(count as f64);
|
||||
}
|
||||
|
||||
pub fn set_mcp_session_metrics_fresh(fresh: bool) {
|
||||
if bound_family("crank_mcp_session_metrics_fresh").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::gauge!("crank_mcp_session_metrics_fresh").set(if fresh { 1.0 } else { 0.0 });
|
||||
}
|
||||
|
||||
@@ -107,6 +171,9 @@ pub fn record_tool_invocation_with_exemplar(
|
||||
duration: Duration,
|
||||
exemplar: Option<ExemplarTraceId>,
|
||||
) {
|
||||
let Some(service) = bound_family("crank_tool_invocations_total") else {
|
||||
return;
|
||||
};
|
||||
let error_kind = match outcome {
|
||||
ToolOutcome::Success => ToolErrorKind::None,
|
||||
ToolOutcome::Aborted => ToolErrorKind::Aborted,
|
||||
@@ -131,6 +198,7 @@ pub fn record_tool_invocation_with_exemplar(
|
||||
)
|
||||
.record(duration.as_secs_f64());
|
||||
crate::exemplar::record_exemplar(
|
||||
service,
|
||||
"crank_tool_invocation_duration_seconds",
|
||||
vec![("source", source.as_str()), ("outcome", outcome.as_str())],
|
||||
duration.as_secs_f64(),
|
||||
@@ -152,6 +220,9 @@ pub fn record_upstream_request_with_exemplar(
|
||||
duration: Duration,
|
||||
exemplar: Option<ExemplarTraceId>,
|
||||
) {
|
||||
let Some(service) = bound_family("crank_upstream_requests_total") else {
|
||||
return;
|
||||
};
|
||||
metrics::counter!(
|
||||
"crank_upstream_requests_total",
|
||||
"operation_kind" => operation_kind.as_str(),
|
||||
@@ -165,6 +236,7 @@ pub fn record_upstream_request_with_exemplar(
|
||||
)
|
||||
.record(duration.as_secs_f64());
|
||||
crate::exemplar::record_exemplar(
|
||||
service,
|
||||
"crank_upstream_request_duration_seconds",
|
||||
vec![
|
||||
("operation_kind", operation_kind.as_str()),
|
||||
@@ -179,25 +251,24 @@ pub struct ToolInvocationMetrics {
|
||||
source: InvocationSource,
|
||||
started_at: Option<Instant>,
|
||||
exemplar: Option<ExemplarTraceId>,
|
||||
active: bool,
|
||||
}
|
||||
|
||||
impl ToolInvocationMetrics {
|
||||
pub fn start(source: InvocationSource) -> Self {
|
||||
Self {
|
||||
source,
|
||||
started_at: Some(Instant::now()),
|
||||
exemplar: None,
|
||||
}
|
||||
Self::start_with_exemplar(source, None)
|
||||
}
|
||||
|
||||
pub fn start_with_exemplar(
|
||||
source: InvocationSource,
|
||||
exemplar: Option<ExemplarTraceId>,
|
||||
) -> Self {
|
||||
let active = bound_family("crank_tool_invocations_total").is_some();
|
||||
Self {
|
||||
source,
|
||||
started_at: Some(Instant::now()),
|
||||
started_at: active.then(Instant::now),
|
||||
exemplar,
|
||||
active,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -220,7 +291,9 @@ impl ToolInvocationMetrics {
|
||||
|
||||
impl Drop for ToolInvocationMetrics {
|
||||
fn drop(&mut self) {
|
||||
self.finish(ToolOutcome::Aborted, ToolErrorKind::Aborted);
|
||||
if self.active {
|
||||
self.finish(ToolOutcome::Aborted, ToolErrorKind::Aborted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,25 +301,24 @@ pub struct UpstreamRequestMetrics {
|
||||
operation_kind: UpstreamOperationKind,
|
||||
started_at: Option<Instant>,
|
||||
exemplar: Option<ExemplarTraceId>,
|
||||
active: bool,
|
||||
}
|
||||
|
||||
impl UpstreamRequestMetrics {
|
||||
pub fn start(operation_kind: UpstreamOperationKind) -> Self {
|
||||
Self {
|
||||
operation_kind,
|
||||
started_at: Some(Instant::now()),
|
||||
exemplar: None,
|
||||
}
|
||||
Self::start_with_exemplar(operation_kind, None)
|
||||
}
|
||||
|
||||
pub fn start_with_exemplar(
|
||||
operation_kind: UpstreamOperationKind,
|
||||
exemplar: Option<ExemplarTraceId>,
|
||||
) -> Self {
|
||||
let active = bound_family("crank_upstream_requests_total").is_some();
|
||||
Self {
|
||||
operation_kind,
|
||||
started_at: Some(Instant::now()),
|
||||
started_at: active.then(Instant::now),
|
||||
exemplar,
|
||||
active,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,11 +340,16 @@ impl UpstreamRequestMetrics {
|
||||
|
||||
impl Drop for UpstreamRequestMetrics {
|
||||
fn drop(&mut self) {
|
||||
self.finish(UpstreamOutcome::Aborted);
|
||||
if self.active {
|
||||
self.finish(UpstreamOutcome::Aborted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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()
|
||||
@@ -281,6 +358,9 @@ pub fn record_limit_rejection(stage: LimitStage) {
|
||||
}
|
||||
|
||||
pub fn record_cache_outcome(outcome: CacheOutcome) {
|
||||
if bound_family("crank_runtime_cache_total").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::counter!(
|
||||
"crank_runtime_cache_total",
|
||||
"outcome" => outcome.as_str()
|
||||
@@ -289,6 +369,9 @@ pub fn record_cache_outcome(outcome: CacheOutcome) {
|
||||
}
|
||||
|
||||
pub fn record_idempotency_outcome(outcome: IdempotencyOutcome) {
|
||||
if bound_family("crank_idempotency_total").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::counter!(
|
||||
"crank_idempotency_total",
|
||||
"outcome" => outcome.as_str()
|
||||
@@ -297,6 +380,9 @@ pub fn record_idempotency_outcome(outcome: IdempotencyOutcome) {
|
||||
}
|
||||
|
||||
pub fn record_confirmation_outcome(outcome: ConfirmationOutcome) {
|
||||
if bound_family("crank_confirmation_total").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::counter!(
|
||||
"crank_confirmation_total",
|
||||
"outcome" => outcome.as_str()
|
||||
@@ -305,6 +391,9 @@ pub fn record_confirmation_outcome(outcome: ConfirmationOutcome) {
|
||||
}
|
||||
|
||||
pub fn set_db_pool_connections(state: DbPoolState, count: u32) {
|
||||
if bound_family("crank_db_pool_connections").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::gauge!(
|
||||
"crank_db_pool_connections",
|
||||
"state" => state.as_str()
|
||||
@@ -313,16 +402,25 @@ pub fn set_db_pool_connections(state: DbPoolState, count: u32) {
|
||||
}
|
||||
|
||||
pub fn set_catalog(tool_count: usize, estimated_context_tokens: usize, warnings: usize) {
|
||||
if bound_family("crank_catalog_tools").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::gauge!("crank_catalog_tools").set(tool_count as f64);
|
||||
metrics::gauge!("crank_catalog_estimated_context_tokens").set(estimated_context_tokens as f64);
|
||||
metrics::gauge!("crank_catalog_warnings").set(warnings as f64);
|
||||
}
|
||||
|
||||
pub fn record_invocation_history_lost() {
|
||||
if bound_family("crank_invocation_history_lost_total").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::counter!("crank_invocation_history_lost_total").increment(1);
|
||||
}
|
||||
|
||||
pub fn record_export_failure(signal: SignalType, exporter: Exporter) {
|
||||
if bound_family("crank_telemetry_export_failures_total").is_none() {
|
||||
return;
|
||||
}
|
||||
metrics::counter!(
|
||||
"crank_telemetry_export_failures_total",
|
||||
"signal_type" => signal.as_str(),
|
||||
@@ -331,44 +429,65 @@ pub fn record_export_failure(signal: SignalType, exporter: Exporter) {
|
||||
.increment(1);
|
||||
}
|
||||
|
||||
pub fn initialize_gauges(service: crate::MetricService) {
|
||||
metrics::gauge!("crank_http_inflight").set(0.0);
|
||||
metrics::gauge!("crank_runtime_inflight").set(0.0);
|
||||
/// Gauges are initialised only for the bound service; any other service (or an
|
||||
/// unbound process) is a no-op and never registers a handle.
|
||||
pub fn initialize_gauges(service: MetricService) {
|
||||
if bound_metric_service() != Some(service) {
|
||||
return;
|
||||
}
|
||||
if family_applies(service, "crank_http_inflight") {
|
||||
metrics::gauge!("crank_http_inflight").set(0.0);
|
||||
}
|
||||
if family_applies(service, "crank_runtime_inflight") {
|
||||
metrics::gauge!("crank_runtime_inflight").set(0.0);
|
||||
}
|
||||
set_db_pool_connections(DbPoolState::Idle, 0);
|
||||
set_db_pool_connections(DbPoolState::Used, 0);
|
||||
if service == crate::MetricService::McpServer {
|
||||
metrics::gauge!("crank_mcp_active_sessions").set(0.0);
|
||||
if service == MetricService::McpServer {
|
||||
set_mcp_active_sessions(0);
|
||||
set_mcp_session_metrics_fresh(false);
|
||||
metrics::gauge!("crank_mcp_active_streams").set(0.0);
|
||||
if family_applies(service, "crank_mcp_active_streams") {
|
||||
metrics::gauge!("crank_mcp_active_streams").set(0.0);
|
||||
}
|
||||
set_catalog(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InFlightGuard {
|
||||
gauge: Gauge,
|
||||
gauge: Option<Gauge>,
|
||||
}
|
||||
|
||||
impl InFlightGuard {
|
||||
pub fn http() -> Self {
|
||||
Self::increment(metrics::gauge!("crank_http_inflight"))
|
||||
Self::increment("crank_http_inflight")
|
||||
}
|
||||
|
||||
pub fn runtime() -> Self {
|
||||
Self::increment(metrics::gauge!("crank_runtime_inflight"))
|
||||
Self::increment("crank_runtime_inflight")
|
||||
}
|
||||
|
||||
pub fn mcp_stream() -> Self {
|
||||
Self::increment(metrics::gauge!("crank_mcp_active_streams"))
|
||||
Self::increment("crank_mcp_active_streams")
|
||||
}
|
||||
|
||||
fn increment(gauge: Gauge) -> Self {
|
||||
fn increment(name: &'static str) -> Self {
|
||||
if bound_family(name).is_none() {
|
||||
return Self { gauge: None };
|
||||
}
|
||||
let gauge = match name {
|
||||
"crank_http_inflight" => metrics::gauge!("crank_http_inflight"),
|
||||
"crank_runtime_inflight" => metrics::gauge!("crank_runtime_inflight"),
|
||||
_ => metrics::gauge!("crank_mcp_active_streams"),
|
||||
};
|
||||
gauge.increment(1.0);
|
||||
Self { gauge }
|
||||
Self { gauge: Some(gauge) }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for InFlightGuard {
|
||||
fn drop(&mut self) {
|
||||
self.gauge.decrement(1.0);
|
||||
if let Some(gauge) = &self.gauge {
|
||||
gauge.decrement(1.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user