pub static PUBLIC_METRICS: &[&str] = &[
"otel_scope_info",
"surrealdb_build_info",
"surrealdb_process_cpu_percent",
"surrealdb_process_memory_bytes",
"surrealdb_process_uptime_seconds",
"target_info",
];
pub fn is_public_metric(name: &str) -> bool {
PUBLIC_METRICS.contains(&name)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn metrics_are_sorted_alphabetically() {
let mut sorted = PUBLIC_METRICS.to_vec();
sorted.sort_unstable();
assert_eq!(PUBLIC_METRICS, sorted, "PUBLIC_METRICS must be kept sorted alphabetically",);
}
#[test]
fn has_no_rpc_query_or_session_names() {
const FORBIDDEN_PREFIXES: &[&str] = &[
"surrealdb_queries_",
"surrealdb_query_",
"surrealdb_statements_",
"surrealdb_statement_",
"surrealdb_rpcs_",
"surrealdb_rpc_",
"surrealdb_sessions_",
"surrealdb_session_",
"surrealdb_auth_",
"surrealdb_transactions_",
"surrealdb_transaction_",
"surrealdb_http_",
"surrealdb_ws_",
"surrealdb_network_",
"surrealdb_live_query_",
"surrealdb_audit_",
"surrealdb_slow_query_",
"surrealdb_storage_",
"surrealdb_tenant_",
"surrealdb_graphql_",
"surrealdb_mcp_",
];
for m in PUBLIC_METRICS {
for p in FORBIDDEN_PREFIXES {
assert!(
!m.starts_with(p),
"`{m}` starts with forbidden prefix `{p}`: keep per-call metrics authenticated-only",
);
}
}
}
#[test]
fn is_public_metric_matches_list() {
for m in PUBLIC_METRICS {
assert!(is_public_metric(m));
}
assert!(!is_public_metric("surrealdb_query_duration_seconds"));
assert!(!is_public_metric("surrealdb_rpcs_completed_total"));
assert!(!is_public_metric("surrealdb_statement_total"));
}
}