Skip to content

Commit df59472

Browse files
committed
chore(rivetkit): remove legacy metrics
1 parent 3b9f382 commit df59472

7 files changed

Lines changed: 60 additions & 113 deletions

File tree

rivetkit-rust/packages/rivetkit-core/src/actor/config.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ pub struct ActorConfigOverrides {
5353
pub wait_until_timeout: Option<Duration>,
5454
}
5555

56+
#[derive(Clone, Debug)]
57+
pub struct ActionDefinition {
58+
pub name: String,
59+
}
60+
5661
#[derive(Clone, Debug)]
5762
pub struct ActorConfig {
5863
pub name: Option<String>,
@@ -83,6 +88,7 @@ pub struct ActorConfig {
8388
pub preload_max_workflow_bytes: Option<u64>,
8489
pub preload_max_connections_bytes: Option<u64>,
8590
pub overrides: Option<ActorConfigOverrides>,
91+
pub actions: Vec<ActionDefinition>,
8692
}
8793

8894
/// Sparse, serialization-friendly actor configuration. All fields are optional with millisecond integers instead of Duration. Used at runtime boundaries (NAPI, config files). Convert to ActorConfig via ActorConfig::from_input().
@@ -110,6 +116,7 @@ pub struct ActorConfigInput {
110116
pub max_outgoing_message_size: Option<u32>,
111117
pub preload_max_workflow_bytes: Option<f64>,
112118
pub preload_max_connections_bytes: Option<f64>,
119+
pub actions: Option<Vec<ActionDefinition>>,
113120
}
114121

115122
impl ActorConfig {
@@ -180,6 +187,9 @@ impl ActorConfig {
180187
actor_config.preload_max_connections_bytes = config
181188
.preload_max_connections_bytes
182189
.map(|value| value as u64);
190+
if let Some(actions) = config.actions {
191+
actor_config.actions = actions;
192+
}
183193

184194
actor_config
185195
}
@@ -243,6 +253,7 @@ impl Default for ActorConfig {
243253
preload_max_workflow_bytes: None,
244254
preload_max_connections_bytes: None,
245255
overrides: None,
256+
actions: Vec::new(),
246257
}
247258
}
248259
}

rivetkit-rust/packages/rivetkit-core/src/actor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub mod task_types;
2020
pub(crate) mod work_registry;
2121

2222
pub use action::ActionDispatchError;
23-
pub use config::{ActorConfig, ActorConfigOverrides, CanHibernateWebSocket};
23+
pub use config::{ActionDefinition, ActorConfig, ActorConfigOverrides, CanHibernateWebSocket};
2424
pub use connection::ConnHandle;
2525
pub use context::{ActorContext, WebSocketCallbackRegion};
2626
pub use factory::{ActorEntryFn, ActorFactory};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use actor::{kv, sqlite};
1010

1111
pub use actor::action::ActionDispatchError;
1212
pub use actor::config::{
13-
ActorConfig, ActorConfigInput, ActorConfigOverrides, CanHibernateWebSocket,
13+
ActionDefinition, ActorConfig, ActorConfigInput, ActorConfigOverrides, CanHibernateWebSocket,
1414
};
1515
pub use actor::connection::ConnHandle;
1616
pub use actor::context::{ActorContext, WebSocketCallbackRegion};

rivetkit-rust/packages/rivetkit-core/src/registry/inspector.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,13 @@ pub(super) fn build_actor_inspector() -> Inspector {
573573
}
574574

575575
pub(super) fn inspector_rpcs(instance: &ActorTaskHandle) -> Vec<String> {
576-
let _ = instance;
577-
Vec::new()
576+
instance
577+
.factory
578+
.config()
579+
.actions
580+
.iter()
581+
.map(|action| action.name.clone())
582+
.collect()
578583
}
579584

580585
pub(super) fn inspector_request_url(request: &Request) -> Result<Url> {

rivetkit-typescript/packages/rivetkit-napi/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export interface JsQueueSendResult {
4444
status: string
4545
response?: Buffer
4646
}
47+
export interface JsActionDefinition {
48+
name: string
49+
}
4750
export interface JsActorConfig {
4851
name?: string
4952
icon?: string
@@ -72,6 +75,7 @@ export interface JsActorConfig {
7275
maxOutgoingMessageSize?: number
7376
preloadMaxWorkflowBytes?: number
7477
preloadMaxConnectionsBytes?: number
78+
actions?: Array<JsActionDefinition>
7579
}
7680
export interface JsBindParam {
7781
kind: string

rivetkit-typescript/packages/rivetkit-napi/src/actor_factory.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use napi::{Env, JsFunction, JsObject};
1010
use napi_derive::napi;
1111
use rivet_error::{MacroMarker, RivetError, RivetErrorSchema};
1212
use rivetkit_core::{
13-
ActorConfig, ActorConfigInput, ActorContext as CoreActorContext,
13+
ActionDefinition, ActorConfig, ActorConfigInput, ActorContext as CoreActorContext,
1414
ActorFactory as CoreActorFactory, ConnHandle as CoreConnHandle, Request, Response,
1515
WebSocket as CoreWebSocket,
1616
};
@@ -54,6 +54,12 @@ pub struct JsQueueSendResult {
5454
pub response: Option<Buffer>,
5555
}
5656

57+
#[napi(object)]
58+
#[derive(Clone, Default)]
59+
pub struct JsActionDefinition {
60+
pub name: String,
61+
}
62+
5763
#[napi(object)]
5864
#[derive(Clone, Default)]
5965
pub struct JsActorConfig {
@@ -84,6 +90,7 @@ pub struct JsActorConfig {
8490
pub max_outgoing_message_size: Option<u32>,
8591
pub preload_max_workflow_bytes: Option<f64>,
8692
pub preload_max_connections_bytes: Option<f64>,
93+
pub actions: Option<Vec<JsActionDefinition>>,
8794
}
8895

8996
#[derive(Clone)]
@@ -1048,6 +1055,12 @@ impl From<JsActorConfig> for ActorConfigInput {
10481055
max_outgoing_message_size: value.max_outgoing_message_size,
10491056
preload_max_workflow_bytes: value.preload_max_workflow_bytes,
10501057
preload_max_connections_bytes: value.preload_max_connections_bytes,
1058+
actions: value.actions.map(|actions| {
1059+
actions
1060+
.into_iter()
1061+
.map(|action| ActionDefinition { name: action.name })
1062+
.collect()
1063+
}),
10511064
}
10521065
}
10531066
}

rivetkit-typescript/packages/rivetkit/src/registry/native.ts

Lines changed: 22 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -3083,6 +3083,11 @@ function buildActorConfig(
30833083
preloadMaxConnectionsBytes: options.preloadMaxConnectionsBytes as
30843084
| number
30853085
| undefined,
3086+
actions: Object.keys(
3087+
(config.actions ?? {}) as Record<string, unknown>,
3088+
)
3089+
.sort()
3090+
.map((name) => ({ name })),
30863091
};
30873092
}
30883093

@@ -3230,106 +3235,6 @@ export function buildNativeFactory(
32303235
);
32313236
const workflowState = async () =>
32323237
(await getNativeWorkflowInspector(ctx)?.getState?.()) ?? null;
3233-
const metricsResponse = (actorCtx: NativeActorContextAdapter) => {
3234-
const sqliteMetrics =
3235-
databaseProvider !== undefined
3236-
? (actorCtx.sql.getSqliteVfsMetrics?.() ?? null)
3237-
: null;
3238-
const commitCount =
3239-
databaseProvider === undefined
3240-
? 0
3241-
: Math.max(sqliteMetrics?.commitCount ?? 0, 1);
3242-
const nsToMs = (ns: number) => ns / 1_000_000;
3243-
const phaseMs = (ns: number) =>
3244-
commitCount > 0 ? Math.max(nsToMs(ns), 0.001) : 0;
3245-
return {
3246-
kv_operations: {
3247-
type: "labeled_timing",
3248-
help: "KV round trips by operation type",
3249-
values: {
3250-
get: { calls: 0, totalMs: 0, keys: 0 },
3251-
getBatch: { calls: 0, totalMs: 0, keys: 0 },
3252-
put: { calls: 0, totalMs: 0, keys: 0 },
3253-
putBatch: { calls: 0, totalMs: 0, keys: 0 },
3254-
deleteBatch: { calls: 0, totalMs: 0, keys: 0 },
3255-
},
3256-
},
3257-
sqlite_commit_phases: {
3258-
type: "labeled_timing",
3259-
help: "SQLite VFS commit phase totals captured by the native VFS",
3260-
values: {
3261-
request_build: {
3262-
calls: commitCount,
3263-
totalMs: phaseMs(
3264-
sqliteMetrics?.requestBuildNs ?? 0,
3265-
),
3266-
keys: 0,
3267-
},
3268-
serialize: {
3269-
calls: commitCount,
3270-
totalMs: phaseMs(sqliteMetrics?.serializeNs ?? 0),
3271-
keys: 0,
3272-
},
3273-
transport: {
3274-
calls: commitCount,
3275-
totalMs: phaseMs(sqliteMetrics?.transportNs ?? 0),
3276-
keys: 0,
3277-
},
3278-
state_update: {
3279-
calls: commitCount,
3280-
totalMs: phaseMs(sqliteMetrics?.stateUpdateNs ?? 0),
3281-
keys: 0,
3282-
},
3283-
},
3284-
},
3285-
startup_total_ms: {
3286-
type: "gauge",
3287-
help: "Total actor startup time in milliseconds",
3288-
value: 1,
3289-
},
3290-
startup_kv_round_trips: {
3291-
type: "gauge",
3292-
help: "KV round-trips during startup",
3293-
value: 0,
3294-
},
3295-
startup_is_new: {
3296-
type: "gauge",
3297-
help: "1 if new actor, 0 if existing",
3298-
value: 0,
3299-
},
3300-
startup_internal_load_state_ms: {
3301-
type: "gauge",
3302-
help: "Time to load persisted state",
3303-
value: 0,
3304-
},
3305-
startup_internal_init_queue_ms: {
3306-
type: "gauge",
3307-
help: "Time to initialize queue state",
3308-
value: 0,
3309-
},
3310-
startup_internal_init_inspector_token_ms: {
3311-
type: "gauge",
3312-
help: "Time to initialize inspector token state",
3313-
value: 0,
3314-
},
3315-
startup_user_create_vars_ms: {
3316-
type: "gauge",
3317-
help: "Time spent running createVars",
3318-
value: 0,
3319-
},
3320-
startup_user_on_wake_ms: {
3321-
type: "gauge",
3322-
help: "Time spent running onWake",
3323-
value: 0,
3324-
},
3325-
startup_user_create_state_ms: {
3326-
type: "gauge",
3327-
help: "Time spent running createState",
3328-
value: 0,
3329-
},
3330-
};
3331-
};
3332-
33333238
const actorCtx = makeActorCtx(ctx, jsRequest);
33343239
try {
33353240
if (
@@ -3591,12 +3496,6 @@ export function buildNativeFactory(
35913496
workflowHistory: workflowHistory(),
35923497
});
35933498
}
3594-
if (
3595-
url.pathname === "/inspector/metrics" &&
3596-
jsRequest.method === "GET"
3597-
) {
3598-
return jsonResponse(metricsResponse(actorCtx));
3599-
}
36003499
if (
36013500
jsRequest.method === "POST" &&
36023501
url.pathname.startsWith("/inspector/action/")
@@ -3662,9 +3561,14 @@ export function buildNativeFactory(
36623561
const actorCtx = makeActorCtx(ctx);
36633562
try {
36643563
const decodedInput = decodeValue(input);
3564+
const startedAt = performance.now();
36653565
const state = hasStaticState
36663566
? structuredClone(config.state)
36673567
: await config.createState(actorCtx, decodedInput);
3568+
logger().debug({
3569+
msg: "perf user: createStateMs",
3570+
durationMs: performance.now() - startedAt,
3571+
});
36683572
actorCtx.initializeState(state);
36693573
return encodeValue(state);
36703574
} finally {
@@ -3703,9 +3607,14 @@ export function buildNativeFactory(
37033607
const { ctx } = unwrapTsfnPayload(error, payload);
37043608
const actorCtx = makeActorCtx(ctx);
37053609
try {
3610+
const startedAt = performance.now();
37063611
const vars = hasStaticVars
37073612
? structuredClone(config.vars)
37083613
: await config.createVars(actorCtx, undefined);
3614+
logger().debug({
3615+
msg: "perf user: createVarsMs",
3616+
durationMs: performance.now() - startedAt,
3617+
});
37093618
actorCtx.vars = vars;
37103619
} finally {
37113620
await actorCtx.dispose();
@@ -3756,7 +3665,12 @@ export function buildNativeFactory(
37563665
const { ctx } = unwrapTsfnPayload(error, payload);
37573666
const actorCtx = makeActorCtx(ctx);
37583667
try {
3668+
const startedAt = performance.now();
37593669
await config.onWake(actorCtx);
3670+
logger().debug({
3671+
msg: "perf user: onWakeMs",
3672+
durationMs: performance.now() - startedAt,
3673+
});
37603674
} finally {
37613675
await actorCtx.dispose();
37623676
}
@@ -4474,9 +4388,9 @@ export async function buildNativeRegistry(config: RegistryConfig): Promise<{
44744388
}> {
44754389
if (
44764390
config.test?.enabled &&
4477-
process.env.RIVET_INSPECTOR_TOKEN === undefined
4391+
process.env._RIVET_TEST_INSPECTOR_TOKEN === undefined
44784392
) {
4479-
process.env.RIVET_INSPECTOR_TOKEN = "token";
4393+
process.env._RIVET_TEST_INSPECTOR_TOKEN = "token";
44804394
}
44814395

44824396
const bindings = await loadNativeBindings();

0 commit comments

Comments
 (0)