@@ -3,6 +3,10 @@ use std::time::Duration;
3
3
use common:: {
4
4
assert_obj,
5
5
bootstrap_model:: index:: IndexMetadata ,
6
+ components:: {
7
+ ComponentFunctionPath ,
8
+ ComponentPath ,
9
+ } ,
6
10
execution_context:: ExecutionId ,
7
11
maybe_val,
8
12
query:: {
@@ -22,6 +26,7 @@ use keybroker::Identity;
22
26
use maplit:: btreeset;
23
27
use pretty_assertions:: assert_eq;
24
28
use runtime:: testing:: TestRuntime ;
29
+ use sync_types:: CanonicalizedUdfPath ;
25
30
use usage_tracking:: {
26
31
CallType ,
27
32
FunctionUsageTracker ,
@@ -41,6 +46,16 @@ use crate::{
41
46
UserFacingModel ,
42
47
} ;
43
48
49
+ fn test_udf_identifier ( ) -> UdfIdentifier {
50
+ let udf_path: CanonicalizedUdfPath = "test.js:default" . parse ( ) . unwrap ( ) ;
51
+ let component = ComponentPath :: root ( ) ;
52
+ let path = ComponentFunctionPath {
53
+ component,
54
+ udf_path : udf_path. strip ( ) ,
55
+ } ;
56
+ UdfIdentifier :: Function ( path. canonicalize ( ) )
57
+ }
58
+
44
59
#[ convex_macro:: test_runtime]
45
60
async fn vector_insert_with_no_index_does_not_count_usage ( rt : TestRuntime ) -> anyhow:: Result < ( ) > {
46
61
let fixtures = VectorFixtures :: new ( rt) . await ?;
@@ -55,7 +70,7 @@ async fn vector_insert_with_no_index_does_not_count_usage(rt: TestRuntime) -> an
55
70
add_document_vec_array ( & mut tx, & table_name, [ 3f64 , 4f64 ] ) . await ?;
56
71
fixtures. db . commit ( tx) . await ?;
57
72
fixtures. db . usage_counter ( ) . track_call (
58
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
73
+ test_udf_identifier ( ) ,
59
74
ExecutionId :: new ( ) ,
60
75
CallType :: Action {
61
76
env : ModuleEnvironment :: Isolate ,
@@ -84,7 +99,7 @@ async fn vector_insert_counts_usage_for_backfilling_indexes(rt: TestRuntime) ->
84
99
add_document_vec_array ( & mut tx, index_name. table ( ) , [ 3f64 , 4f64 ] ) . await ?;
85
100
fixtures. db . commit ( tx) . await ?;
86
101
fixtures. db . usage_counter ( ) . track_call (
87
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
102
+ test_udf_identifier ( ) ,
88
103
ExecutionId :: new ( ) ,
89
104
CallType :: Mutation ,
90
105
tx_usage. gather_user_stats ( ) ,
@@ -117,7 +132,7 @@ async fn vector_insert_counts_usage_for_enabled_indexes(rt: TestRuntime) -> anyh
117
132
add_document_vec_array ( & mut tx, index_name. table ( ) , [ 3f64 , 4f64 ] ) . await ?;
118
133
fixtures. db . commit ( tx) . await ?;
119
134
fixtures. db . usage_counter ( ) . track_call (
120
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
135
+ test_udf_identifier ( ) ,
121
136
ExecutionId :: new ( ) ,
122
137
CallType :: Action {
123
138
env : ModuleEnvironment :: Isolate ,
@@ -150,7 +165,7 @@ async fn vectors_in_segment_count_as_usage(rt: TestRuntime) -> anyhow::Result<()
150
165
add_document_vec_array ( & mut tx, index_name. table ( ) , [ 3f64 , 4f64 ] ) . await ?;
151
166
fixtures. db . commit ( tx) . await ?;
152
167
fixtures. db . usage_counter ( ) . track_call (
153
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
168
+ test_udf_identifier ( ) ,
154
169
ExecutionId :: new ( ) ,
155
170
CallType :: Action {
156
171
env : ModuleEnvironment :: Isolate ,
@@ -199,7 +214,7 @@ async fn vector_query_counts_bandwidth(rt: TestRuntime) -> anyhow::Result<()> {
199
214
tx_usage. add ( usage_stats) ;
200
215
201
216
fixtures. db . usage_counter ( ) . track_call (
202
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
217
+ test_udf_identifier ( ) ,
203
218
ExecutionId :: new ( ) ,
204
219
CallType :: Action {
205
220
env : ModuleEnvironment :: Isolate ,
@@ -241,7 +256,7 @@ async fn test_usage_tracking_basic_insert_and_get(rt: TestRuntime) -> anyhow::Re
241
256
. await ?;
242
257
db. commit ( tx) . await ?;
243
258
db. usage_counter ( ) . track_call (
244
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
259
+ test_udf_identifier ( ) ,
245
260
ExecutionId :: new ( ) ,
246
261
CallType :: Mutation ,
247
262
tx_usage. gather_user_stats ( ) ,
@@ -266,7 +281,7 @@ async fn test_usage_tracking_basic_insert_and_get(rt: TestRuntime) -> anyhow::Re
266
281
. await ?;
267
282
db. commit ( tx) . await ?;
268
283
db. usage_counter ( ) . track_call (
269
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
284
+ test_udf_identifier ( ) ,
270
285
ExecutionId :: new ( ) ,
271
286
CallType :: Mutation ,
272
287
tx_usage. gather_user_stats ( ) ,
@@ -308,7 +323,7 @@ async fn test_usage_tracking_insert_with_index(rt: TestRuntime) -> anyhow::Resul
308
323
. unwrap_or_else ( |e| panic ! ( "Failed to add index for {} {:?}" , "by_key" , e) ) ;
309
324
db. commit ( tx) . await ?;
310
325
db. usage_counter ( ) . track_call (
311
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
326
+ test_udf_identifier ( ) ,
312
327
ExecutionId :: new ( ) ,
313
328
CallType :: Mutation ,
314
329
tx_usage. gather_user_stats ( ) ,
@@ -332,7 +347,7 @@ async fn test_usage_tracking_insert_with_index(rt: TestRuntime) -> anyhow::Resul
332
347
. await ?;
333
348
db. commit ( tx) . await ?;
334
349
db. usage_counter ( ) . track_call (
335
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
350
+ test_udf_identifier ( ) ,
336
351
ExecutionId :: new ( ) ,
337
352
CallType :: Mutation ,
338
353
tx_usage. gather_user_stats ( ) ,
@@ -359,7 +374,7 @@ async fn test_usage_tracking_insert_with_index(rt: TestRuntime) -> anyhow::Resul
359
374
while query_stream. next ( & mut tx, None ) . await ?. is_some ( ) { }
360
375
db. commit ( tx) . await ?;
361
376
db. usage_counter ( ) . track_call (
362
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
377
+ test_udf_identifier ( ) ,
363
378
ExecutionId :: new ( ) ,
364
379
CallType :: Mutation ,
365
380
tx_usage. gather_user_stats ( ) ,
@@ -386,7 +401,7 @@ async fn http_action_counts_compute(rt: TestRuntime) -> anyhow::Result<()> {
386
401
387
402
let tx_usage = FunctionUsageTracker :: new ( ) ;
388
403
db. usage_counter ( ) . track_call (
389
- UdfIdentifier :: Function ( "test.js:default" . parse ( ) ? ) ,
404
+ test_udf_identifier ( ) ,
390
405
ExecutionId :: new ( ) ,
391
406
CallType :: HttpAction {
392
407
duration : Duration :: from_secs ( 5 ) ,
0 commit comments