наблюдаемость: ввести безопасный контракт метрик
CI / Rust Checks (push) Successful in 6m9s
CI / UI Checks (push) Successful in 5s
CI / Community Image Smoke (push) Successful in 1m3s
CI / Frontend E2E (push) Successful in 3m47s
CI / Deploy (push) Failing after 3s
CI / Rust Checks (pull_request) Successful in 6m15s
CI / UI Checks (pull_request) Successful in 5s
CI / Frontend E2E (pull_request) Successful in 5m17s
CI / Community Image Smoke (pull_request) Successful in 4m25s
CI / Deploy (pull_request) Skipped

This commit is contained in:
bsodfather committed 2026-07-31 05:04:08 +03:00
1 parent ec2453c00f
commit 9b1a739e39
50 files changed
+3066 -433

No files matched your search

+179
View File
@@ -0,0 +1,179 @@
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MetricKind {
Counter,
Gauge,
Histogram,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum MetricUnit {
Count,
Seconds,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MetricDefinition {
pub name: &'static str,
pub kind: MetricKind,
pub unit: MetricUnit,
pub labels: &'static [&'static str],
pub description: &'static str,
}
pub const DURATION_BUCKETS_SECONDS: &[f64] = &[
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1.0, 2.5, 5.0, 10.0, 30.0, 60.0,
];
const METRIC_SCHEMA: &[MetricDefinition] = &[
counter(
"crank_http_requests_total",
&["route", "method", "status_class"],
"Total HTTP requests.",
),
histogram(
"crank_http_request_duration_seconds",
&["route", "method"],
"HTTP request duration in seconds.",
),
gauge(
"crank_http_inflight",
&[],
"HTTP requests currently being processed.",
),
counter(
"crank_mcp_requests_total",
&["method", "response_mode", "outcome"],
"Total MCP JSON-RPC requests.",
),
gauge(
"crank_mcp_active_sessions",
&[],
"Active persisted MCP transport sessions.",
),
gauge(
"crank_mcp_active_streams",
&[],
"MCP event streams currently being served.",
),
counter(
"crank_tool_invocations_total",
&["source", "outcome", "error_kind"],
"Total tool invocations.",
),
histogram(
"crank_tool_invocation_duration_seconds",
&["source", "outcome"],
"Tool invocation duration in seconds.",
),
counter(
"crank_upstream_requests_total",
&["operation_kind", "outcome"],
"Total upstream requests.",
),
histogram(
"crank_upstream_request_duration_seconds",
&["operation_kind", "outcome"],
"Upstream request duration in seconds.",
),
gauge(
"crank_runtime_inflight",
&[],
"Runtime executions currently in progress.",
),
counter(
"crank_runtime_limit_rejections_total",
&["stage"],
"Runtime executions rejected by a bounded limit.",
),
counter(
"crank_runtime_cache_total",
&["outcome"],
"Runtime response cache outcomes.",
),
counter(
"crank_idempotency_total",
&["outcome"],
"Runtime idempotency outcomes.",
),
counter(
"crank_confirmation_total",
&["outcome"],
"Runtime confirmation outcomes.",
),
gauge(
"crank_db_pool_connections",
&["state"],
"PostgreSQL pool connections by state.",
),
gauge(
"crank_catalog_tools",
&[],
"Tools in the current published catalog.",
),
gauge(
"crank_catalog_estimated_context_tokens",
&[],
"Estimated context tokens in the current published catalog.",
),
gauge(
"crank_catalog_warnings",
&[],
"Warnings in the current published catalog.",
),
counter(
"crank_invocation_history_lost_total",
&[],
"Invocation history records lost after an action completed.",
),
counter(
"crank_telemetry_export_failures_total",
&["signal_type", "exporter"],
"Telemetry export failures.",
),
];
pub const fn metric_schema() -> &'static [MetricDefinition] {
METRIC_SCHEMA
}
const fn counter(
name: &'static str,
labels: &'static [&'static str],
description: &'static str,
) -> MetricDefinition {
MetricDefinition {
name,
kind: MetricKind::Counter,
unit: MetricUnit::Count,
labels,
description,
}
}
const fn gauge(
name: &'static str,
labels: &'static [&'static str],
description: &'static str,
) -> MetricDefinition {
MetricDefinition {
name,
kind: MetricKind::Gauge,
unit: MetricUnit::Count,
labels,
description,
}
}
const fn histogram(
name: &'static str,
labels: &'static [&'static str],
description: &'static str,
) -> MetricDefinition {
MetricDefinition {
name,
kind: MetricKind::Histogram,
unit: MetricUnit::Seconds,
labels,
description,
}
}