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
@@ -0,0 +1,262 @@
|
||||
//! Checked-арифметика бюджетов серий/exemplar, структурная валидация и
|
||||
//! per-process ceilings.
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use super::descriptor::{
|
||||
LabelClass, MAX_EXEMPLAR_SLOTS_PER_PROCESS, MAX_LOGICAL_SERIES_PER_PROCESS,
|
||||
MAX_METRIC_FAMILIES, MAX_PRODUCT_LABELS_PER_FAMILY, MAX_RENDERED_SERIES_PER_PROCESS,
|
||||
METRIC_SCHEMA, MetricDefinition, MetricKind, MetricService,
|
||||
};
|
||||
use super::projection::service_projection;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct SchemaBudget {
|
||||
pub logical_series: usize,
|
||||
pub rendered_series: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
pub enum SchemaError {
|
||||
TooManyFamilies,
|
||||
DuplicateMetric,
|
||||
InvalidMetric,
|
||||
DuplicateLabel,
|
||||
InvalidDomain,
|
||||
InvalidBuckets,
|
||||
InvalidCeiling,
|
||||
BudgetExceeded,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum MetricBindingError {
|
||||
InvalidSchema,
|
||||
ConflictingService,
|
||||
}
|
||||
|
||||
/// Checked series budget of one candidate family: the product of its
|
||||
/// label-domain sizes and, for histograms, the `buckets + 3` rendered sample
|
||||
/// lines per logical series. Overflow is a typed budget failure; the closed
|
||||
/// schema never saturates and never reports a truncated count.
|
||||
pub(crate) fn checked_series_budget<I>(
|
||||
domain_sizes: I,
|
||||
kind: MetricKind,
|
||||
bucket_count: usize,
|
||||
) -> Result<SchemaBudget, SchemaError>
|
||||
where
|
||||
I: IntoIterator<Item = usize>,
|
||||
{
|
||||
let logical_series = domain_sizes
|
||||
.into_iter()
|
||||
.try_fold(1_usize, |product, size| {
|
||||
product.checked_mul(size).ok_or(SchemaError::BudgetExceeded)
|
||||
})?;
|
||||
if kind != MetricKind::Histogram {
|
||||
return Ok(SchemaBudget {
|
||||
logical_series,
|
||||
rendered_series: logical_series,
|
||||
});
|
||||
}
|
||||
let rendered_per_series = bucket_count
|
||||
.checked_add(3)
|
||||
.ok_or(SchemaError::BudgetExceeded)?;
|
||||
let rendered_series = logical_series
|
||||
.checked_mul(rendered_per_series)
|
||||
.ok_or(SchemaError::BudgetExceeded)?;
|
||||
Ok(SchemaBudget {
|
||||
logical_series,
|
||||
rendered_series,
|
||||
})
|
||||
}
|
||||
|
||||
/// Checked exemplar slots of one family (`L x (buckets + 1)`): an overflow is a
|
||||
/// typed budget failure, never a wrapped slot count.
|
||||
pub(crate) fn checked_exemplar_slots(
|
||||
kind: MetricKind,
|
||||
logical_series: usize,
|
||||
bucket_count: usize,
|
||||
) -> Result<usize, SchemaError> {
|
||||
if kind != MetricKind::Histogram {
|
||||
return Ok(0);
|
||||
}
|
||||
let buckets = bucket_count
|
||||
.checked_add(1)
|
||||
.ok_or(SchemaError::BudgetExceeded)?;
|
||||
logical_series
|
||||
.checked_mul(buckets)
|
||||
.ok_or(SchemaError::BudgetExceeded)
|
||||
}
|
||||
|
||||
/// Checked exemplar capacity of one service projection. `None` means the
|
||||
/// projection's arithmetic overflowed, so every caller can fail closed (no
|
||||
/// exemplar growth) instead of recording under a saturated capacity.
|
||||
pub(crate) fn checked_exemplar_capacity(service: MetricService) -> Option<usize> {
|
||||
service_projection(service)
|
||||
.iter()
|
||||
.try_fold(0_usize, |total, definition| {
|
||||
checked_exemplar_slots(
|
||||
definition.kind,
|
||||
definition.max_logical_series,
|
||||
definition.buckets.len(),
|
||||
)
|
||||
.ok()
|
||||
.and_then(|slots| total.checked_add(slots))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn validate_budget(logical: usize, rendered: usize) -> Result<(), SchemaError> {
|
||||
if logical > MAX_LOGICAL_SERIES_PER_PROCESS || rendered > MAX_RENDERED_SERIES_PER_PROCESS {
|
||||
Err(SchemaError::BudgetExceeded)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate_exemplar_budget(slots: usize) -> Result<(), SchemaError> {
|
||||
if slots > MAX_EXEMPLAR_SLOTS_PER_PROCESS {
|
||||
Err(SchemaError::BudgetExceeded)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Structural validation of exactly one projected schema, including the
|
||||
/// per-process ceilings. It must never be applied to the union descriptors.
|
||||
pub fn validate_schema(schema: &[MetricDefinition]) -> Result<SchemaBudget, SchemaError> {
|
||||
let budget = validate_structure(schema)?;
|
||||
validate_budget(budget.logical_series, budget.rendered_series)?;
|
||||
let exemplars = schema.iter().try_fold(0_usize, |total, definition| {
|
||||
let slots = checked_exemplar_slots(
|
||||
definition.kind,
|
||||
definition.max_logical_series,
|
||||
definition.buckets.len(),
|
||||
)?;
|
||||
total.checked_add(slots).ok_or(SchemaError::BudgetExceeded)
|
||||
})?;
|
||||
validate_exemplar_budget(exemplars)?;
|
||||
Ok(budget)
|
||||
}
|
||||
|
||||
/// Structural validation without any sum ceiling (used for the union metadata
|
||||
/// and reused by the renderer before it validates every service projection).
|
||||
fn validate_structure(schema: &[MetricDefinition]) -> Result<SchemaBudget, SchemaError> {
|
||||
if schema.len() > MAX_METRIC_FAMILIES {
|
||||
return Err(SchemaError::TooManyFamilies);
|
||||
}
|
||||
let mut names = BTreeSet::new();
|
||||
let mut logical = 0usize;
|
||||
let mut rendered = 0usize;
|
||||
for item in schema {
|
||||
if !names.insert(item.name) {
|
||||
return Err(SchemaError::DuplicateMetric);
|
||||
}
|
||||
if !valid_metric_name(item.name)
|
||||
|| !valid_static_text(item.description)
|
||||
|| item.processes.is_empty()
|
||||
|| item.labels.len() > MAX_PRODUCT_LABELS_PER_FAMILY
|
||||
|| item.labels.len() != item.label_domains.len()
|
||||
{
|
||||
return Err(SchemaError::InvalidMetric);
|
||||
}
|
||||
let mut owners = BTreeSet::new();
|
||||
for owner in item.processes {
|
||||
if !owners.insert(*owner) {
|
||||
return Err(SchemaError::InvalidMetric);
|
||||
}
|
||||
}
|
||||
let mut labels = BTreeSet::new();
|
||||
for (label, domain) in item.labels.iter().zip(item.label_domains) {
|
||||
if *label != domain.name || !valid_label_name(label) || !labels.insert(*label) {
|
||||
return Err(SchemaError::DuplicateLabel);
|
||||
}
|
||||
if domain.class != LabelClass::ProductClosed
|
||||
|| domain.values.is_empty()
|
||||
|| domain.values.iter().any(|value| !valid_domain_value(value))
|
||||
|| domain.values.iter().copied().collect::<BTreeSet<_>>().len()
|
||||
!= domain.values.len()
|
||||
{
|
||||
return Err(SchemaError::InvalidDomain);
|
||||
}
|
||||
}
|
||||
if item.kind == MetricKind::Histogram {
|
||||
if item.buckets.is_empty()
|
||||
|| item.buckets.iter().any(|v| !v.is_finite() || *v <= 0.0)
|
||||
|| item.buckets.windows(2).any(|pair| pair[0] >= pair[1])
|
||||
{
|
||||
return Err(SchemaError::InvalidBuckets);
|
||||
}
|
||||
} else if !item.buckets.is_empty() {
|
||||
return Err(SchemaError::InvalidBuckets);
|
||||
}
|
||||
// Единственная checked-арифметика серий: переполнение домена или
|
||||
// rendered-серий обязано быть типизированным BudgetExceeded, а не
|
||||
// насыщенным «почти верным» значением.
|
||||
let budget = checked_series_budget(
|
||||
item.label_domains.iter().map(|domain| domain.values.len()),
|
||||
item.kind,
|
||||
item.buckets.len(),
|
||||
)?;
|
||||
if budget.logical_series != item.max_logical_series
|
||||
|| budget.rendered_series != item.max_rendered_series
|
||||
{
|
||||
return Err(SchemaError::InvalidCeiling);
|
||||
}
|
||||
logical = logical
|
||||
.checked_add(budget.logical_series)
|
||||
.ok_or(SchemaError::BudgetExceeded)?;
|
||||
rendered = rendered
|
||||
.checked_add(budget.rendered_series)
|
||||
.ok_or(SchemaError::BudgetExceeded)?;
|
||||
}
|
||||
Ok(SchemaBudget {
|
||||
logical_series: logical,
|
||||
rendered_series: rendered,
|
||||
})
|
||||
}
|
||||
|
||||
/// Validates the union structure plus **every** service projection. Union
|
||||
/// totals are deliberately not compared against the per-process ceilings.
|
||||
pub fn validate_all_projections() -> Result<(), SchemaError> {
|
||||
validate_structure(METRIC_SCHEMA)?;
|
||||
validate_schema(service_projection(MetricService::AdminApi))?;
|
||||
validate_schema(service_projection(MetricService::McpServer))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn valid_static_text(value: &str) -> bool {
|
||||
!value.trim().is_empty()
|
||||
&& value.len() <= 512
|
||||
&& !value
|
||||
.bytes()
|
||||
.any(|byte| byte.is_ascii_control() || matches!(byte, b'"' | b'\\'))
|
||||
}
|
||||
|
||||
fn valid_metric_name(name: &str) -> bool {
|
||||
!name.is_empty()
|
||||
&& name
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_lowercase() || byte.is_ascii_digit() || byte == b'_')
|
||||
&& name.starts_with("crank_")
|
||||
}
|
||||
|
||||
fn valid_label_name(name: &str) -> bool {
|
||||
!name.is_empty()
|
||||
&& name.len() <= 64
|
||||
&& !name.starts_with("__")
|
||||
&& name
|
||||
.bytes()
|
||||
.next()
|
||||
.is_some_and(|byte| byte.is_ascii_lowercase() || byte == b'_')
|
||||
&& name
|
||||
.bytes()
|
||||
.skip(1)
|
||||
.all(|byte| byte.is_ascii_lowercase() || byte.is_ascii_digit() || byte == b'_')
|
||||
}
|
||||
|
||||
fn valid_domain_value(value: &str) -> bool {
|
||||
!value.is_empty()
|
||||
&& value.len() <= 256
|
||||
&& !value
|
||||
.bytes()
|
||||
.any(|byte| byte.is_ascii_control() || matches!(byte, b'"' | b'\\'))
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
//! Checked-арифметика серий и exemplar-слотов: типизированное переполнение
|
||||
//! вместо насыщения (TD-M5).
|
||||
|
||||
use super::budget::{
|
||||
SchemaBudget, SchemaError, checked_exemplar_capacity, checked_exemplar_slots,
|
||||
checked_series_budget,
|
||||
};
|
||||
use super::descriptor::{MAX_EXEMPLAR_SLOTS_PER_PROCESS, MetricKind, MetricService};
|
||||
use super::projection::{max_exemplar_slots, service_projection};
|
||||
|
||||
/// TD-M5 — реальное целочисленное переполнение checked-seam'а обязано быть
|
||||
/// типизированным `BudgetExceeded`, а не насыщенным/усечённым счётчиком.
|
||||
/// Фикстура — только размеры доменов, поэтому enormous-аллокаций нет.
|
||||
#[test]
|
||||
fn checked_seam_reports_overflow_typed_and_never_saturates() {
|
||||
// Логический product переполняется.
|
||||
assert_eq!(
|
||||
checked_series_budget([usize::MAX, 2], MetricKind::Counter, 0),
|
||||
Err(SchemaError::BudgetExceeded)
|
||||
);
|
||||
// Граница: ровно представимый product остаётся принятым (без saturation).
|
||||
assert_eq!(
|
||||
checked_series_budget([usize::MAX, 1], MetricKind::Counter, 0),
|
||||
Ok(SchemaBudget {
|
||||
logical_series: usize::MAX,
|
||||
rendered_series: usize::MAX,
|
||||
})
|
||||
);
|
||||
// Rendered product переполняется при корректном logical.
|
||||
assert_eq!(
|
||||
checked_series_budget([usize::MAX / 4, 2], MetricKind::Histogram, 13),
|
||||
Err(SchemaError::BudgetExceeded)
|
||||
);
|
||||
// `buckets + 3` само переполняется.
|
||||
assert_eq!(
|
||||
checked_series_budget([1], MetricKind::Histogram, usize::MAX),
|
||||
Err(SchemaError::BudgetExceeded)
|
||||
);
|
||||
// Нормальный histogram считается точно (13 buckets → 16 rendered).
|
||||
assert_eq!(
|
||||
checked_series_budget([7, 2], MetricKind::Histogram, 13),
|
||||
Ok(SchemaBudget {
|
||||
logical_series: 14,
|
||||
rendered_series: 224,
|
||||
})
|
||||
);
|
||||
// Пустой домен: один logical series, как у gauge без labels.
|
||||
assert_eq!(
|
||||
checked_series_budget(std::iter::empty::<usize>(), MetricKind::Gauge, 0),
|
||||
Ok(SchemaBudget {
|
||||
logical_series: 1,
|
||||
rendered_series: 1,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/// TD-M5 — exemplar-слоты считаются checked, capacity fail-closed.
|
||||
#[test]
|
||||
fn checked_exemplar_slots_and_capacity_are_typed_and_bounded() {
|
||||
assert_eq!(
|
||||
checked_exemplar_slots(MetricKind::Histogram, usize::MAX, 13),
|
||||
Err(SchemaError::BudgetExceeded)
|
||||
);
|
||||
assert_eq!(
|
||||
checked_exemplar_slots(MetricKind::Histogram, usize::MAX / 2, 2),
|
||||
Err(SchemaError::BudgetExceeded)
|
||||
);
|
||||
assert_eq!(
|
||||
checked_exemplar_slots(MetricKind::Histogram, 1, usize::MAX),
|
||||
Err(SchemaError::BudgetExceeded)
|
||||
);
|
||||
assert_eq!(
|
||||
checked_exemplar_slots(MetricKind::Counter, usize::MAX, 13),
|
||||
Ok(0)
|
||||
);
|
||||
// 4 series x (13 finite buckets + 1 Inf) = 56 слотов, без saturation.
|
||||
assert_eq!(checked_exemplar_slots(MetricKind::Histogram, 4, 13), Ok(56));
|
||||
// Реальная проекция остаётся в frozen-границах.
|
||||
assert_eq!(
|
||||
checked_exemplar_capacity(MetricService::AdminApi),
|
||||
Some(12_348)
|
||||
);
|
||||
assert_eq!(
|
||||
checked_exemplar_capacity(MetricService::McpServer),
|
||||
Some(2_310)
|
||||
);
|
||||
assert_eq!(
|
||||
max_exemplar_slots(MetricService::AdminApi),
|
||||
MAX_EXEMPLAR_SLOTS_PER_PROCESS
|
||||
);
|
||||
for service in [MetricService::AdminApi, MetricService::McpServer] {
|
||||
for definition in service_projection(service) {
|
||||
assert_ne!(definition.max_logical_series, usize::MAX);
|
||||
assert_eq!(
|
||||
definition.max_exemplar_slots(),
|
||||
checked_exemplar_slots(
|
||||
definition.kind,
|
||||
definition.max_logical_series,
|
||||
definition.buckets.len()
|
||||
)
|
||||
.expect("projected exemplar slots are in range")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,520 @@
|
||||
//! Закрытые дескрипторы метрик: kind/unit/process/service, домены labels и
|
||||
//! `METRIC_SCHEMA` (union-таблица метадат, не бюджет процесса).
|
||||
|
||||
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,
|
||||
};
|
||||
|
||||
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_EXEMPLAR_SLOTS_PER_PROCESS: usize = 12_348;
|
||||
pub const MAX_EXPOSITION_BYTES: usize = 8 * 1024 * 1024;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum MetricKind {
|
||||
Counter,
|
||||
Gauge,
|
||||
Histogram,
|
||||
}
|
||||
|
||||
impl MetricKind {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Counter => "counter",
|
||||
Self::Gauge => "gauge",
|
||||
Self::Histogram => "histogram",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum MetricUnit {
|
||||
Count,
|
||||
Seconds,
|
||||
}
|
||||
|
||||
impl MetricUnit {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::Count => "count",
|
||||
Self::Seconds => "seconds",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
|
||||
pub enum MetricProcess {
|
||||
AdminApi,
|
||||
McpServer,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum MetricService {
|
||||
AdminApi,
|
||||
McpServer,
|
||||
}
|
||||
|
||||
impl MetricService {
|
||||
pub fn parse(value: &str) -> Option<Self> {
|
||||
match value {
|
||||
"admin-api" => Some(Self::AdminApi),
|
||||
"mcp-server" => Some(Self::McpServer),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn process(self) -> MetricProcess {
|
||||
match self {
|
||||
Self::AdminApi => MetricProcess::AdminApi,
|
||||
Self::McpServer => MetricProcess::McpServer,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MetricProcess {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::AdminApi => "admin_api",
|
||||
Self::McpServer => "mcp_server",
|
||||
}
|
||||
}
|
||||
|
||||
pub const fn service(self) -> MetricService {
|
||||
match self {
|
||||
Self::AdminApi => MetricService::AdminApi,
|
||||
Self::McpServer => MetricService::McpServer,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum LabelClass {
|
||||
ProductClosed,
|
||||
ProcessConstant,
|
||||
}
|
||||
|
||||
impl LabelClass {
|
||||
pub const fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Self::ProductClosed => "product_closed",
|
||||
Self::ProcessConstant => "process_constant",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct LabelDomain {
|
||||
pub name: &'static str,
|
||||
pub class: LabelClass,
|
||||
pub values: &'static [&'static str],
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
pub struct MetricDefinition {
|
||||
pub name: &'static str,
|
||||
pub kind: MetricKind,
|
||||
pub unit: MetricUnit,
|
||||
pub labels: &'static [&'static str],
|
||||
pub label_domains: &'static [LabelDomain],
|
||||
pub buckets: &'static [f64],
|
||||
pub processes: &'static [MetricProcess],
|
||||
pub max_logical_series: usize,
|
||||
pub max_rendered_series: usize,
|
||||
pub description: &'static str,
|
||||
}
|
||||
|
||||
impl MetricDefinition {
|
||||
/// `E(m, p)` — exemplar slots contributed by this family inside one process
|
||||
/// projection. Histograms hold `L x (finite_buckets + 1)` latest-per-bucket
|
||||
/// observations; counters/gauges hold none. The multiply is checked: an
|
||||
/// overflowing definition (one that already failed the checked seam) fails
|
||||
/// loudly instead of returning a saturated or truncated count.
|
||||
pub const fn max_exemplar_slots(&self) -> usize {
|
||||
if !matches!(self.kind, MetricKind::Histogram) {
|
||||
return 0;
|
||||
}
|
||||
match self.max_logical_series.checked_mul(self.buckets.len() + 1) {
|
||||
Some(slots) => slots,
|
||||
None => panic!("exemplar slot arithmetic overflowed a validated definition"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
];
|
||||
|
||||
pub const PROCESS_CONSTANT_LABELS: &[LabelDomain] = &[
|
||||
LabelDomain {
|
||||
name: "service",
|
||||
class: LabelClass::ProcessConstant,
|
||||
values: &["admin-api", "mcp-server"],
|
||||
},
|
||||
LabelDomain {
|
||||
name: "version",
|
||||
class: LabelClass::ProcessConstant,
|
||||
values: &["validated_release_identity"],
|
||||
},
|
||||
LabelDomain {
|
||||
name: "environment",
|
||||
class: LabelClass::ProcessConstant,
|
||||
values: &["validated_startup_value"],
|
||||
},
|
||||
];
|
||||
|
||||
const METHODS: &[&str] = HttpMethod::VALUES;
|
||||
const STATUS: &[&str] = HttpStatusClass::VALUES;
|
||||
const MCP_METHODS: &[&str] = McpMethod::VALUES;
|
||||
const RESPONSE_MODES: &[&str] = McpResponseMode::VALUES;
|
||||
const MCP_OUTCOMES: &[&str] = McpOutcome::VALUES;
|
||||
const SOURCES: &[&str] = InvocationSource::VALUES;
|
||||
const TOOL_OUTCOMES: &[&str] = ToolOutcome::VALUES;
|
||||
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 CACHE_OUTCOMES: &[&str] = CacheOutcome::VALUES;
|
||||
const IDEMPOTENCY_OUTCOMES: &[&str] = IdempotencyOutcome::VALUES;
|
||||
const CONFIRMATION_OUTCOMES: &[&str] = ConfirmationOutcome::VALUES;
|
||||
const DB_STATES: &[&str] = DbPoolState::VALUES;
|
||||
const SIGNAL_TYPES: &[&str] = SignalType::VALUES;
|
||||
const EXPORTERS: &[&str] = Exporter::VALUES;
|
||||
|
||||
const fn domain(name: &'static str, values: &'static [&'static str]) -> LabelDomain {
|
||||
LabelDomain {
|
||||
name,
|
||||
class: LabelClass::ProductClosed,
|
||||
values,
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(
|
||||
clippy::too_many_arguments,
|
||||
reason = "the canonical descriptor keeps every metric contract dimension explicit"
|
||||
)]
|
||||
const fn metric(
|
||||
name: &'static str,
|
||||
kind: MetricKind,
|
||||
unit: MetricUnit,
|
||||
labels: &'static [&'static str],
|
||||
label_domains: &'static [LabelDomain],
|
||||
buckets: &'static [f64],
|
||||
processes: &'static [MetricProcess],
|
||||
logical: usize,
|
||||
description: &'static str,
|
||||
) -> MetricDefinition {
|
||||
let rendered = if matches!(kind, MetricKind::Histogram) {
|
||||
logical * (buckets.len() + 3)
|
||||
} else {
|
||||
logical
|
||||
};
|
||||
MetricDefinition {
|
||||
name,
|
||||
kind,
|
||||
unit,
|
||||
labels,
|
||||
label_domains,
|
||||
buckets,
|
||||
processes,
|
||||
max_logical_series: logical,
|
||||
max_rendered_series: rendered,
|
||||
description,
|
||||
}
|
||||
}
|
||||
|
||||
/// Union descriptors: the route domain is the whole union and `max_*` are the
|
||||
/// union Cartesian metadata used for structural diagnostics, **not** a process
|
||||
/// budget. Real per-process data lives in the service projections.
|
||||
pub(crate) const METRIC_SCHEMA: &[MetricDefinition] = &[
|
||||
metric(
|
||||
"crank_http_requests_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["route", "method", "status_class"],
|
||||
&[
|
||||
domain("route", HTTP_ROUTE_DOMAIN),
|
||||
domain("method", METHODS),
|
||||
domain("status_class", STATUS),
|
||||
],
|
||||
&[],
|
||||
BOTH,
|
||||
HTTP_ROUTE_DOMAIN.len() * 10 * 6,
|
||||
"Total HTTP requests.",
|
||||
),
|
||||
metric(
|
||||
"crank_http_request_duration_seconds",
|
||||
MetricKind::Histogram,
|
||||
MetricUnit::Seconds,
|
||||
&["route", "method"],
|
||||
&[
|
||||
domain("route", HTTP_ROUTE_DOMAIN),
|
||||
domain("method", METHODS),
|
||||
],
|
||||
DURATION_BUCKETS_SECONDS,
|
||||
BOTH,
|
||||
HTTP_ROUTE_DOMAIN.len() * 10,
|
||||
"HTTP request duration in seconds.",
|
||||
),
|
||||
metric(
|
||||
"crank_http_inflight",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Count,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
BOTH,
|
||||
1,
|
||||
"HTTP requests currently being processed.",
|
||||
),
|
||||
metric(
|
||||
"crank_mcp_requests_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["method", "response_mode", "outcome"],
|
||||
&[
|
||||
domain("method", MCP_METHODS),
|
||||
domain("response_mode", RESPONSE_MODES),
|
||||
domain("outcome", MCP_OUTCOMES),
|
||||
],
|
||||
&[],
|
||||
MCP,
|
||||
9 * 3 * 7,
|
||||
"Total MCP JSON-RPC requests.",
|
||||
),
|
||||
metric(
|
||||
"crank_mcp_request_duration_seconds",
|
||||
MetricKind::Histogram,
|
||||
MetricUnit::Seconds,
|
||||
&["method", "outcome"],
|
||||
&[
|
||||
domain("method", MCP_METHODS),
|
||||
domain("outcome", MCP_OUTCOMES),
|
||||
],
|
||||
DURATION_BUCKETS_SECONDS,
|
||||
MCP,
|
||||
9 * 7,
|
||||
"MCP JSON-RPC request duration in seconds.",
|
||||
),
|
||||
metric(
|
||||
"crank_mcp_active_sessions",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Count,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
MCP,
|
||||
1,
|
||||
"Active persisted MCP transport sessions.",
|
||||
),
|
||||
metric(
|
||||
"crank_mcp_session_metrics_fresh",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Count,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
MCP,
|
||||
1,
|
||||
"Whether the active-session gauge was refreshed successfully.",
|
||||
),
|
||||
metric(
|
||||
"crank_mcp_active_streams",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Count,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
MCP,
|
||||
1,
|
||||
"MCP event streams currently being served.",
|
||||
),
|
||||
metric(
|
||||
"crank_tool_invocations_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["source", "outcome", "error_kind"],
|
||||
&[
|
||||
domain("source", SOURCES),
|
||||
domain("outcome", TOOL_OUTCOMES),
|
||||
domain("error_kind", TOOL_ERRORS),
|
||||
],
|
||||
&[],
|
||||
BOTH,
|
||||
3 * 3 * 22,
|
||||
"Total tool invocations.",
|
||||
),
|
||||
metric(
|
||||
"crank_tool_invocation_duration_seconds",
|
||||
MetricKind::Histogram,
|
||||
MetricUnit::Seconds,
|
||||
&["source", "outcome"],
|
||||
&[domain("source", SOURCES), domain("outcome", TOOL_OUTCOMES)],
|
||||
DURATION_BUCKETS_SECONDS,
|
||||
BOTH,
|
||||
3 * 3,
|
||||
"Tool invocation duration in seconds.",
|
||||
),
|
||||
metric(
|
||||
"crank_upstream_requests_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["operation_kind", "outcome"],
|
||||
&[
|
||||
domain("operation_kind", OPERATION_KINDS),
|
||||
domain("outcome", UPSTREAM_OUTCOMES),
|
||||
],
|
||||
&[],
|
||||
BOTH,
|
||||
13,
|
||||
"Total upstream requests.",
|
||||
),
|
||||
metric(
|
||||
"crank_upstream_request_duration_seconds",
|
||||
MetricKind::Histogram,
|
||||
MetricUnit::Seconds,
|
||||
&["operation_kind", "outcome"],
|
||||
&[
|
||||
domain("operation_kind", OPERATION_KINDS),
|
||||
domain("outcome", UPSTREAM_OUTCOMES),
|
||||
],
|
||||
DURATION_BUCKETS_SECONDS,
|
||||
BOTH,
|
||||
13,
|
||||
"Upstream request duration in seconds.",
|
||||
),
|
||||
metric(
|
||||
"crank_runtime_inflight",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Count,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
BOTH,
|
||||
1,
|
||||
"Runtime executions currently in progress.",
|
||||
),
|
||||
metric(
|
||||
"crank_runtime_limit_rejections_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["stage"],
|
||||
&[domain("stage", LIMIT_STAGES)],
|
||||
&[],
|
||||
BOTH,
|
||||
3,
|
||||
"Runtime executions rejected by a bounded limit.",
|
||||
),
|
||||
metric(
|
||||
"crank_runtime_cache_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["outcome"],
|
||||
&[domain("outcome", CACHE_OUTCOMES)],
|
||||
&[],
|
||||
BOTH,
|
||||
7,
|
||||
"Runtime response cache outcomes.",
|
||||
),
|
||||
metric(
|
||||
"crank_idempotency_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["outcome"],
|
||||
&[domain("outcome", IDEMPOTENCY_OUTCOMES)],
|
||||
&[],
|
||||
BOTH,
|
||||
8,
|
||||
"Runtime idempotency outcomes.",
|
||||
),
|
||||
metric(
|
||||
"crank_confirmation_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["outcome"],
|
||||
&[domain("outcome", CONFIRMATION_OUTCOMES)],
|
||||
&[],
|
||||
BOTH,
|
||||
5,
|
||||
"Runtime confirmation outcomes.",
|
||||
),
|
||||
metric(
|
||||
"crank_db_pool_connections",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Count,
|
||||
&["state"],
|
||||
&[domain("state", DB_STATES)],
|
||||
&[],
|
||||
BOTH,
|
||||
2,
|
||||
"PostgreSQL pool connections by state.",
|
||||
),
|
||||
metric(
|
||||
"crank_catalog_tools",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Count,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
MCP,
|
||||
1,
|
||||
"Tools in the current published catalog.",
|
||||
),
|
||||
metric(
|
||||
"crank_catalog_estimated_context_tokens",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Count,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
MCP,
|
||||
1,
|
||||
"Estimated context tokens in the current published catalog.",
|
||||
),
|
||||
metric(
|
||||
"crank_catalog_warnings",
|
||||
MetricKind::Gauge,
|
||||
MetricUnit::Count,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
MCP,
|
||||
1,
|
||||
"Warnings in the current published catalog.",
|
||||
),
|
||||
metric(
|
||||
"crank_invocation_history_lost_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&[],
|
||||
&[],
|
||||
&[],
|
||||
BOTH,
|
||||
1,
|
||||
"Invocation history records lost after an action completed.",
|
||||
),
|
||||
metric(
|
||||
"crank_telemetry_export_failures_total",
|
||||
MetricKind::Counter,
|
||||
MetricUnit::Count,
|
||||
&["signal_type", "exporter"],
|
||||
&[
|
||||
domain("signal_type", SIGNAL_TYPES),
|
||||
domain("exporter", EXPORTERS),
|
||||
],
|
||||
&[],
|
||||
BOTH,
|
||||
4,
|
||||
"Telemetry export failures.",
|
||||
),
|
||||
];
|
||||
|
||||
/// Union descriptors (`metadata`, not a budget).
|
||||
pub const fn metric_schema() -> &'static [MetricDefinition] {
|
||||
METRIC_SCHEMA
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
//! Ленивые per-service проекции union-таблицы: один раз посчитанный
|
||||
//! checked-бюджет на процесс, без per-request аллокаций.
|
||||
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use super::budget::{
|
||||
SchemaBudget, SchemaError, checked_exemplar_capacity, checked_series_budget, validate_schema,
|
||||
};
|
||||
use super::descriptor::{LabelDomain, METRIC_SCHEMA, MetricDefinition, MetricService};
|
||||
use super::routes::service_route_domain;
|
||||
|
||||
fn build_projection(service: MetricService) -> Result<&'static [MetricDefinition], SchemaError> {
|
||||
let route_values = service_route_domain(service);
|
||||
let mut definitions = Vec::new();
|
||||
for definition in METRIC_SCHEMA {
|
||||
if !definition.processes.contains(&service.process()) {
|
||||
continue;
|
||||
}
|
||||
let label_domains: &'static [LabelDomain] = Box::leak(
|
||||
definition
|
||||
.label_domains
|
||||
.iter()
|
||||
.map(|label_domain| {
|
||||
if label_domain.name == "route" {
|
||||
LabelDomain {
|
||||
values: route_values,
|
||||
..*label_domain
|
||||
}
|
||||
} else {
|
||||
*label_domain
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.into_boxed_slice(),
|
||||
);
|
||||
let budget = checked_series_budget(
|
||||
label_domains
|
||||
.iter()
|
||||
.map(|label_domain| label_domain.values.len()),
|
||||
definition.kind,
|
||||
definition.buckets.len(),
|
||||
)?;
|
||||
definitions.push(MetricDefinition {
|
||||
label_domains,
|
||||
max_logical_series: budget.logical_series,
|
||||
max_rendered_series: budget.rendered_series,
|
||||
..*definition
|
||||
});
|
||||
}
|
||||
Ok(Box::leak(definitions.into_boxed_slice()))
|
||||
}
|
||||
|
||||
static ADMIN_PROJECTION: OnceLock<&'static [MetricDefinition]> = OnceLock::new();
|
||||
static MCP_PROJECTION: OnceLock<&'static [MetricDefinition]> = OnceLock::new();
|
||||
|
||||
/// Derived projection cache initialized once per service (no per-request allocation).
|
||||
/// The static schema is a compile-time constant, so a checked-seam overflow here
|
||||
/// is a programming error: it fails loudly instead of publishing a saturated or
|
||||
/// truncated series budget.
|
||||
pub fn service_projection(service: MetricService) -> &'static [MetricDefinition] {
|
||||
let cache = match service {
|
||||
MetricService::AdminApi => &ADMIN_PROJECTION,
|
||||
MetricService::McpServer => &MCP_PROJECTION,
|
||||
};
|
||||
cache.get_or_init(|| match build_projection(service) {
|
||||
Ok(projection) => projection,
|
||||
Err(error) => {
|
||||
panic!("static metric projection must satisfy the checked schema seam: {error:?}")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn metric_schema_for_service(
|
||||
service: MetricService,
|
||||
) -> impl Iterator<Item = &'static MetricDefinition> {
|
||||
service_projection(service).iter()
|
||||
}
|
||||
|
||||
pub fn schema_budget(service: MetricService) -> Result<SchemaBudget, SchemaError> {
|
||||
validate_schema(service_projection(service))
|
||||
}
|
||||
|
||||
pub fn max_exemplar_slots(service: MetricService) -> usize {
|
||||
checked_exemplar_capacity(service)
|
||||
.expect("validated service projection must carry a bounded exemplar budget")
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
//! Детерминированный компактный v2-снимок реестра
|
||||
//! (`docs/schemas/metrics-registry-v2.json`).
|
||||
|
||||
use super::budget::{
|
||||
SchemaError, checked_exemplar_slots, validate_all_projections, validate_schema,
|
||||
};
|
||||
use super::descriptor::{
|
||||
MAX_EXEMPLAR_SLOTS_PER_PROCESS, MAX_EXPOSITION_BYTES, MAX_LOGICAL_SERIES_PER_PROCESS,
|
||||
MAX_METRIC_FAMILIES, MAX_PRODUCT_LABELS_PER_FAMILY, MAX_RENDERED_SERIES_PER_PROCESS,
|
||||
METRIC_SCHEMA, METRIC_SCHEMA_VERSION, MetricProcess, PROCESS_CONSTANT_LABELS,
|
||||
};
|
||||
use super::projection::service_projection;
|
||||
use super::routes::HTTP_ROUTES;
|
||||
|
||||
/// Deterministic compact v2 registry snapshot (Rust descriptor table is the
|
||||
/// only generator). Every service projection is validated before rendering.
|
||||
pub fn render_metric_schema_json() -> Result<String, SchemaError> {
|
||||
validate_all_projections()?;
|
||||
let mut out = String::with_capacity(20 * 1024);
|
||||
out.push_str("{\"schema_version\":");
|
||||
out.push_str(&METRIC_SCHEMA_VERSION.to_string());
|
||||
out.push_str(",\"limits\":{\"max_families\":");
|
||||
out.push_str(&MAX_METRIC_FAMILIES.to_string());
|
||||
out.push_str(",\"max_product_labels_per_family\":");
|
||||
out.push_str(&MAX_PRODUCT_LABELS_PER_FAMILY.to_string());
|
||||
out.push_str(",\"max_logical_series\":");
|
||||
out.push_str(&MAX_LOGICAL_SERIES_PER_PROCESS.to_string());
|
||||
out.push_str(",\"max_rendered_series\":");
|
||||
out.push_str(&MAX_RENDERED_SERIES_PER_PROCESS.to_string());
|
||||
out.push_str(",\"max_exemplar_slots\":");
|
||||
out.push_str(&MAX_EXEMPLAR_SLOTS_PER_PROCESS.to_string());
|
||||
out.push_str(",\"max_exposition_bytes\":");
|
||||
out.push_str(&MAX_EXPOSITION_BYTES.to_string());
|
||||
out.push_str("},\"global_labels\":[");
|
||||
for (index, label) in PROCESS_CONSTANT_LABELS.iter().enumerate() {
|
||||
comma(&mut out, index);
|
||||
out.push_str("{\"name\":\"");
|
||||
out.push_str(label.name);
|
||||
out.push_str("\",\"class\":\"");
|
||||
out.push_str(label.class.as_str());
|
||||
out.push_str("\",\"domain\":[");
|
||||
out.push_str(&json_strings(label.values));
|
||||
out.push_str("]}");
|
||||
}
|
||||
out.push_str("],\"http_routes\":[");
|
||||
for (index, route) in HTTP_ROUTES.iter().enumerate() {
|
||||
comma(&mut out, index);
|
||||
out.push_str("{\"route\":\"");
|
||||
out.push_str(route.route);
|
||||
out.push_str("\",\"processes\":[");
|
||||
out.push_str(&json_processes(route.processes));
|
||||
out.push_str("]}");
|
||||
}
|
||||
out.push_str("],\"metrics\":[");
|
||||
for (index, definition) in METRIC_SCHEMA.iter().enumerate() {
|
||||
comma(&mut out, index);
|
||||
out.push_str("{\"name\":\"");
|
||||
out.push_str(definition.name);
|
||||
out.push_str("\",\"kind\":\"");
|
||||
out.push_str(definition.kind.as_str());
|
||||
out.push_str("\",\"unit\":\"");
|
||||
out.push_str(definition.unit.as_str());
|
||||
out.push_str("\",\"help\":\"");
|
||||
out.push_str(definition.description);
|
||||
out.push_str("\",\"processes\":[");
|
||||
out.push_str(&json_processes(definition.processes));
|
||||
out.push_str("],\"labels\":[");
|
||||
for (label_index, label_domain) in definition.label_domains.iter().enumerate() {
|
||||
comma(&mut out, label_index);
|
||||
out.push_str("{\"name\":\"");
|
||||
out.push_str(label_domain.name);
|
||||
out.push_str("\",\"class\":\"");
|
||||
out.push_str(label_domain.class.as_str());
|
||||
if label_domain.name == "route" {
|
||||
out.push_str("\",\"domain_ref\":\"http_routes\"}");
|
||||
} else {
|
||||
out.push_str("\",\"domain\":[");
|
||||
out.push_str(&json_strings(label_domain.values));
|
||||
out.push_str("]}");
|
||||
}
|
||||
}
|
||||
out.push_str("],\"buckets_seconds\":[");
|
||||
out.push_str(&json_numbers(definition.buckets));
|
||||
out.push_str("],\"bounds\":[");
|
||||
for (bound_index, process) in definition.processes.iter().enumerate() {
|
||||
comma(&mut out, bound_index);
|
||||
out.push_str(&bound_json(*process, definition.name)?);
|
||||
}
|
||||
out.push_str("]}");
|
||||
}
|
||||
out.push_str("],\"budgets\":[");
|
||||
for (index, process) in [MetricProcess::AdminApi, MetricProcess::McpServer]
|
||||
.iter()
|
||||
.enumerate()
|
||||
{
|
||||
comma(&mut out, index);
|
||||
let projection = service_projection(process.service());
|
||||
let budget = validate_schema(projection)?;
|
||||
let exemplars = projection.iter().try_fold(0_usize, |total, definition| {
|
||||
let slots = checked_exemplar_slots(
|
||||
definition.kind,
|
||||
definition.max_logical_series,
|
||||
definition.buckets.len(),
|
||||
)?;
|
||||
total.checked_add(slots).ok_or(SchemaError::BudgetExceeded)
|
||||
})?;
|
||||
out.push_str("{\"process\":\"");
|
||||
out.push_str(process.as_str());
|
||||
out.push_str("\",\"families\":");
|
||||
out.push_str(&projection.len().to_string());
|
||||
out.push_str(",\"logical_series\":");
|
||||
out.push_str(&budget.logical_series.to_string());
|
||||
out.push_str(",\"rendered_series\":");
|
||||
out.push_str(&budget.rendered_series.to_string());
|
||||
out.push_str(",\"exemplar_slots\":");
|
||||
out.push_str(&exemplars.to_string());
|
||||
out.push('}');
|
||||
}
|
||||
out.push_str("]}\n");
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn bound_json(process: MetricProcess, name: &str) -> Result<String, SchemaError> {
|
||||
let projection = service_projection(process.service());
|
||||
let definition = projection
|
||||
.iter()
|
||||
.find(|definition| definition.name == name)
|
||||
.expect("validated projection declares every family it owns");
|
||||
let exemplars = checked_exemplar_slots(
|
||||
definition.kind,
|
||||
definition.max_logical_series,
|
||||
definition.buckets.len(),
|
||||
)?;
|
||||
Ok(format!(
|
||||
"{{\"process\":\"{}\",\"logical_series\":{},\"rendered_series\":{},\"exemplar_slots\":{}}}",
|
||||
process.as_str(),
|
||||
definition.max_logical_series,
|
||||
definition.max_rendered_series,
|
||||
exemplars
|
||||
))
|
||||
}
|
||||
|
||||
fn json_strings(values: &[&str]) -> String {
|
||||
values
|
||||
.iter()
|
||||
.map(|value| format!("\"{value}\""))
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
}
|
||||
|
||||
fn json_numbers(values: &[f64]) -> String {
|
||||
values
|
||||
.iter()
|
||||
.map(|value| value.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
}
|
||||
|
||||
fn json_processes(values: &[MetricProcess]) -> String {
|
||||
values
|
||||
.iter()
|
||||
.map(|value| format!("\"{}\"", value.as_str()))
|
||||
.collect::<Vec<_>>()
|
||||
.join(",")
|
||||
}
|
||||
|
||||
fn comma(out: &mut String, index: usize) {
|
||||
if index > 0 {
|
||||
out.push(',');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,497 @@
|
||||
//! Единственная вручную поддерживаемая таблица route+owners (`HTTP_ROUTES`) и
|
||||
//! производные от неё домены (union и две сервисные проекции).
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use super::budget::SchemaError;
|
||||
use super::descriptor::{MetricProcess, MetricService};
|
||||
|
||||
pub(crate) const BOTH: &[MetricProcess] = &[MetricProcess::AdminApi, MetricProcess::McpServer];
|
||||
pub(crate) const MCP: &[MetricProcess] = &[MetricProcess::McpServer];
|
||||
|
||||
/// One row of the single manually maintained route/ownership truth.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub struct HttpRouteDefinition {
|
||||
pub route: &'static str,
|
||||
pub processes: &'static [MetricProcess],
|
||||
}
|
||||
|
||||
const fn process_matches(value: MetricProcess, expected: MetricProcess) -> bool {
|
||||
matches!(
|
||||
(value, expected),
|
||||
(MetricProcess::AdminApi, MetricProcess::AdminApi)
|
||||
| (MetricProcess::McpServer, MetricProcess::McpServer)
|
||||
)
|
||||
}
|
||||
|
||||
const fn owners_contain(row: &HttpRouteDefinition, process: MetricProcess) -> bool {
|
||||
let mut index = 0;
|
||||
while index < row.processes.len() {
|
||||
if process_matches(row.processes[index], process) {
|
||||
return true;
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
const fn project_route_count(process: MetricProcess) -> usize {
|
||||
let mut count = 0;
|
||||
let mut index = 0;
|
||||
while index < HTTP_ROUTES.len() {
|
||||
if owners_contain(&HTTP_ROUTES[index], process) {
|
||||
count += 1;
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
count
|
||||
}
|
||||
|
||||
const fn project_route_domain<const N: usize>(process: MetricProcess) -> [&'static str; N] {
|
||||
let mut routes = [""; N];
|
||||
let mut index = 0;
|
||||
let mut next = 0;
|
||||
while index < HTTP_ROUTES.len() {
|
||||
if owners_contain(&HTTP_ROUTES[index], process) {
|
||||
routes[next] = HTTP_ROUTES[index].route;
|
||||
next += 1;
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
routes
|
||||
}
|
||||
|
||||
/// Union route domain (`91`) derived from the single ownership table.
|
||||
pub const HTTP_ROUTE_DOMAIN: &[&str] = &union_route_domain_array();
|
||||
|
||||
const fn union_route_domain_array() -> [&'static str; HTTP_ROUTES.len()] {
|
||||
let mut routes = [""; HTTP_ROUTES.len()];
|
||||
let mut index = 0;
|
||||
while index < HTTP_ROUTES.len() {
|
||||
routes[index] = HTTP_ROUTES[index].route;
|
||||
index += 1;
|
||||
}
|
||||
routes
|
||||
}
|
||||
|
||||
const ADMIN_ROUTE_COUNT: usize = project_route_count(MetricProcess::AdminApi);
|
||||
const MCP_ROUTE_COUNT: usize = project_route_count(MetricProcess::McpServer);
|
||||
|
||||
pub const ADMIN_HTTP_ROUTE_DOMAIN: &[&str] =
|
||||
&project_route_domain::<ADMIN_ROUTE_COUNT>(MetricProcess::AdminApi);
|
||||
pub const MCP_HTTP_ROUTE_DOMAIN: &[&str] =
|
||||
&project_route_domain::<MCP_ROUTE_COUNT>(MetricProcess::McpServer);
|
||||
|
||||
/// The single manually maintained route+owners enumeration. Sorted by ASCII
|
||||
/// route; `unmatched` is the last row. Every other domain (union and the two
|
||||
/// service projections) is derived from this table.
|
||||
pub const HTTP_ROUTES: &[HttpRouteDefinition] = &[
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/capabilities",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/tool-search/preview",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/{agent_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/{agent_id}/archive",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/{agent_id}/bindings",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/{agent_id}/platform-api-keys",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/{agent_id}/platform-api-keys/{key_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/{agent_id}/platform-api-keys/{key_id}/revoke",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/{agent_id}/publish",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/{agent_id}/unpublish",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/agents/{agent_id}/versions/{version}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/approvals",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/approvals/{approval_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/approvals/{approval_id}/approve",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/approvals/{approval_id}/deny",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/auth-profiles",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/auth-profiles/{auth_profile_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/export",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/imports/openapi/plans/{plan_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/imports/openapi/preview",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/imports/openapi/{job_id}/create",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/imports/openapi/{job_id}/plans",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/imports/openapi/{plan_id}/apply",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/logs",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/logs/export.csv",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/logs/{log_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/onboarding",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/onboarding/events",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/onboarding/import-context",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/onboarding/reset-selection",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/onboarding/select-draft",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/analyze-quality",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/import",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}/archive",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}/drafts/generate",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}/export",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}/publish",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}/samples/input-json",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}/samples/output-json",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}/test-runs",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}/versions",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/operations/{operation_id}/versions/{version}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/prompts",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/prompts/import",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/prompts/{prompt_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/prompts/{prompt_id}/export",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/prompts/{prompt_id}/preview",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/prompts/{prompt_id}/versions/{version}/export",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/import",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/archive",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/content",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/export",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/preview",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/publish",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/revoke",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/test-runs",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/versions/{version}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/versions/{version}/content",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/resources/{resource_id}/versions/{version}/export",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/secrets",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/secrets/{secret_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/secrets/{secret_id}/rotate",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/upstreams",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/upstreams/{upstream_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/usage",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/usage/agents/{agent_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/usage/export.csv",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/admin/workspaces/{workspace_id}/usage/operations/{operation_id}",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/auth/bootstrap/complete",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/auth/bootstrap/status",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/auth/login",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/auth/logout",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/auth/password",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/auth/profile",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/auth/session",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/api/auth/session/csrf",
|
||||
processes: &[MetricProcess::AdminApi],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/health",
|
||||
processes: BOTH,
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/ready",
|
||||
processes: BOTH,
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/v1/{workspace_slug}/{agent_slug}",
|
||||
processes: &[MetricProcess::McpServer],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/v1/{workspace_slug}/{agent_slug}/approvals",
|
||||
processes: &[MetricProcess::McpServer],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/v1/{workspace_slug}/{agent_slug}/approvals/{approval_id}",
|
||||
processes: &[MetricProcess::McpServer],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/v1/{workspace_slug}/{agent_slug}/approvals/{approval_id}/approve",
|
||||
processes: &[MetricProcess::McpServer],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "/v1/{workspace_slug}/{agent_slug}/approvals/{approval_id}/deny",
|
||||
processes: &[MetricProcess::McpServer],
|
||||
},
|
||||
HttpRouteDefinition {
|
||||
route: "unmatched",
|
||||
processes: BOTH,
|
||||
},
|
||||
];
|
||||
|
||||
/// Structural validation of one candidate ownership table (used to reject
|
||||
/// duplicated routes, empty owner sets and duplicate owners in reviews/mutation
|
||||
/// tests). The production table itself is a `const`, so this is the typed gate
|
||||
/// that proves the same invariants on any candidate.
|
||||
pub fn validate_http_routes(routes: &[HttpRouteDefinition]) -> Result<(), SchemaError> {
|
||||
if routes.is_empty() {
|
||||
return Err(SchemaError::InvalidDomain);
|
||||
}
|
||||
let mut seen = BTreeSet::new();
|
||||
for row in routes {
|
||||
if !seen.insert(row.route) {
|
||||
return Err(SchemaError::DuplicateMetric);
|
||||
}
|
||||
if row.processes.is_empty() || row.processes.len() > 2 {
|
||||
return Err(SchemaError::InvalidMetric);
|
||||
}
|
||||
let mut owners = BTreeSet::new();
|
||||
for owner in row.processes {
|
||||
if !owners.insert(*owner) {
|
||||
return Err(SchemaError::InvalidMetric);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !seen.contains("unmatched") {
|
||||
return Err(SchemaError::InvalidDomain);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Owners of one declared route template (`None` = not a declared template).
|
||||
pub fn http_route_processes(route: &str) -> Option<&'static [MetricProcess]> {
|
||||
HTTP_ROUTES
|
||||
.iter()
|
||||
.find(|definition| definition.route == route)
|
||||
.map(|definition| definition.processes)
|
||||
}
|
||||
|
||||
pub(crate) fn service_route_domain(service: MetricService) -> &'static [&'static str] {
|
||||
match service {
|
||||
MetricService::AdminApi => ADMIN_HTTP_ROUTE_DOMAIN,
|
||||
MetricService::McpServer => MCP_HTTP_ROUTE_DOMAIN,
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user