Skip to content

Commit a807d34

Browse files
committed
chore(rivetkit): clean up metrics naming and dead collectors
- Rename rivetkit_core::metrics_endpoint to rivetkit_core::metrics; the module only renders the registry and records rivetkit_info now. - Start the tokio runtime sampler explicitly at the three startup call sites instead of as a side effect of record_rivetkit_info(). - Delete registry/process-metrics.ts, which had no importers and no NAPI counterparts. - Drop the unused --metrics-token flag and _RIVET_METRICS_TOKEN env passthrough from the kitchen-sink soak and mock-agentic scripts. Amp-Thread-ID: https://ampcode.com/threads/T-e7d8deec-a004-4884-a5b2-8d5c9064977c Co-authored-by: Amp <amp@ampcode.com>
1 parent 9fd72f2 commit a807d34

15 files changed

Lines changed: 23 additions & 284 deletions

File tree

‎docs-internal/engine/rivetkit-core-internals.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Legacy traces under `[7, 1, ...]` are intentionally skipped and are not copied t
6767

6868
- Registry startup builds configured `ActorContext`s with `ActorContext::build(...)` so state, queue, and connection managers inherit the actor config before lifecycle startup runs. `ActorContext::build(...)` must seed owned queue, connection, and sleep config storage from its `ActorConfig`; do not initialize those fields with `ActorConfig::default()`.
6969
- Registry actor task handles live in one `actor_instances: SccHashMap<String, ActorInstanceState>`. Use `entry_async` for Active/Stopping transitions.
70-
- `RegistryDispatcher::handle_fetch` owns framework HTTP routes `/metadata`, `/health`, `/inspector/*`, `/action/*`, and `/queue/*`. Prometheus metrics are process-wide and are never served by core itself; `metrics_endpoint::render_prometheus_metrics()` only backs the NAPI `metrics()` binding and `Registry::prometheus_metrics()` so hosts can mount the rendered response on their own router. TypeScript NAPI callbacks keep action/queue schema validation and queue `canPublish`.
70+
- `RegistryDispatcher::handle_fetch` owns framework HTTP routes `/metadata`, `/health`, `/inspector/*`, `/action/*`, and `/queue/*`. Prometheus metrics are process-wide and are never served by core itself; `metrics::render_prometheus_metrics()` only backs the NAPI `metrics()` binding and `Registry::prometheus_metrics()` so hosts can mount the rendered response on their own router. TypeScript NAPI callbacks keep action/queue schema validation and queue `canPublish`.
7171
- Raw `onRequest` HTTP fetches bypass `maxIncomingMessageSize` / `maxOutgoingMessageSize`. Those message-size guards apply only to `/action/*` and `/queue/*` framework routes, not unmatched user `onRequest` paths.
7272
- Framework HTTP error payloads omit absent `metadata` for JSON/CBOR responses so missing metadata stays `undefined`. Only explicit metadata `null` serializes as `null`.
7373

‎examples/kitchen-sink/scripts/mock-agentic-loop.ts‎

Lines changed: 0 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/kitchen-sink/scripts/sqlite-memory-soak.ts‎

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎rivetkit-rust/packages/rivetkit-core/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub mod engine_process;
1111
pub mod error;
1212
pub mod inspector;
1313
pub mod inspector_bundle;
14-
pub mod metrics_endpoint;
14+
pub mod metrics;
1515
pub mod registry;
1616
pub mod runtime;
1717
pub(crate) mod serde_metrics;

rivetkit-rust/packages/rivetkit-core/src/metrics_endpoint.rs renamed to rivetkit-rust/packages/rivetkit-core/src/metrics.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,6 @@ fn ensure_rivetkit_info_recorded() {
113113
}
114114

115115
fn record_rivetkit_info_inner(info: RivetKitInfo) {
116-
// Startup paths reach this from inside the runtime, which is the only place
117-
// a handle to sample can be taken.
118-
#[cfg(not(target_arch = "wasm32"))]
119-
crate::tokio_runtime_metrics::ensure_sampler_started();
120-
121116
let mut current = CURRENT_RIVETKIT_INFO.lock();
122117
if let Some(previous) = current.as_ref()
123118
&& previous != &info

‎rivetkit-rust/packages/rivetkit-core/src/registry/http.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ fn handle_metadata_fetch(
504504
&serde_json::json!({
505505
"runtime": "rivetkit",
506506
"version": env!("CARGO_PKG_VERSION"),
507-
"type": crate::metrics_endpoint::runtime_type(),
507+
"type": crate::metrics::runtime_type(),
508508
}),
509509
)
510510
}

‎rivetkit-rust/packages/rivetkit-core/src/registry/mod.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,14 @@ impl CoreRegistry {
618618
shutdown: CancellationToken,
619619
on_handle: impl FnOnce(CoreEnvoyHandle) + Send + 'static,
620620
) -> Result<()> {
621-
crate::metrics_endpoint::record_rivetkit_info(
621+
crate::metrics::record_rivetkit_info(
622622
config.serverless_package_version.clone(),
623623
config.version,
624624
"serverful",
625625
config.pool_name.clone(),
626626
);
627+
#[cfg(not(target_arch = "wasm32"))]
628+
crate::tokio_runtime_metrics::ensure_sampler_started();
627629

628630
let dispatcher = self.into_dispatcher(&config);
629631
let manage_engine = should_manage_engine(&config.endpoint, config.engine_spawn)?;

‎rivetkit-rust/packages/rivetkit-core/src/serverless.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,14 @@ impl CoreServerlessRuntime {
173173
config.handle_inspector_http_in_runtime,
174174
));
175175
let base_path = normalize_base_path(config.serverless_base_path.as_deref());
176-
crate::metrics_endpoint::record_rivetkit_info(
176+
crate::metrics::record_rivetkit_info(
177177
config.serverless_package_version.clone(),
178178
config.version,
179179
"serverless",
180180
config.pool_name.clone(),
181181
);
182+
#[cfg(not(target_arch = "wasm32"))]
183+
crate::tokio_runtime_metrics::ensure_sampler_started();
182184

183185
Ok(Self {
184186
settings: Arc::new(ServerlessSettings {
@@ -374,12 +376,14 @@ impl CoreServerlessRuntime {
374376
async fn start_response(&self, req: ServerlessRequest) -> Result<ServerlessResponse> {
375377
let headers = parse_start_headers(&req.headers)?;
376378
self.validate_start_headers(&headers)?;
377-
crate::metrics_endpoint::record_rivetkit_info(
379+
crate::metrics::record_rivetkit_info(
378380
self.settings.package_version.clone(),
379381
self.settings.version,
380382
"serverless",
381383
headers.pool_name.clone(),
382384
);
385+
#[cfg(not(target_arch = "wasm32"))]
386+
crate::tokio_runtime_metrics::ensure_sampler_started();
383387
if req.body.len() > self.settings.max_start_payload_bytes {
384388
return Err(IncomingMessageTooLong {
385389
limit: self.settings.max_start_payload_bytes,

‎rivetkit-rust/packages/rivetkit-core/tests/integration.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ mod common;
44
#[path = "integration/counter.rs"]
55
mod counter;
66

7-
#[path = "integration/metrics_endpoint.rs"]
8-
mod metrics_endpoint;
7+
#[path = "integration/metrics.rs"]
8+
mod metrics;
99

1010
#[path = "integration/sqlite_corruption_fuzz.rs"]
1111
mod sqlite_corruption_fuzz;

rivetkit-rust/packages/rivetkit-core/tests/integration/metrics_endpoint.rs renamed to rivetkit-rust/packages/rivetkit-core/tests/integration/metrics.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#[test]
22
fn render_prometheus_metrics_includes_rivetkit_info() {
3-
rivetkit_core::metrics_endpoint::record_rivetkit_info(
3+
rivetkit_core::metrics::record_rivetkit_info(
44
env!("CARGO_PKG_VERSION"),
55
42,
66
"serverful",
77
"metrics-test-pool",
88
);
99

10-
let metrics =
11-
rivetkit_core::metrics_endpoint::render_prometheus_metrics().expect("render metrics");
10+
let metrics = rivetkit_core::metrics::render_prometheus_metrics().expect("render metrics");
1211
let body = String::from_utf8(metrics.body).expect("metrics should be utf-8");
1312
let expected = format!(
1413
"rivet_rivetkit_info{{envoy_kind=\"serverful\",envoy_version=\"42\",pool_name=\"metrics-test-pool\",runtime=\"rivetkit\",type=\"local\",version=\"{}\"}} 1",

0 commit comments

Comments
 (0)