1
- use std:: collections:: BTreeMap ;
1
+ use std:: {
2
+ collections:: BTreeMap ,
3
+ time:: {
4
+ Duration ,
5
+ Instant ,
6
+ } ,
7
+ } ;
2
8
3
9
use anyhow:: {
4
10
anyhow,
@@ -95,7 +101,7 @@ pub struct GetConfigHashesResponse {
95
101
96
102
#[ derive( Deserialize , Debug , Copy , Clone ) ]
97
103
#[ serde( rename_all = "camelCase" ) ]
98
- pub struct PushMetrics {
104
+ pub struct ClientPushMetrics {
99
105
pub typecheck : f64 ,
100
106
pub bundle : f64 ,
101
107
pub schema_push : f64 ,
@@ -137,7 +143,7 @@ pub struct ConfigJson {
137
143
// Used in CLI >= 0.14.0, None when there is no schema file.
138
144
pub schema_id : Option < String > ,
139
145
// Used in CLI >= future
140
- pub push_metrics : Option < PushMetrics > ,
146
+ pub push_metrics : Option < ClientPushMetrics > ,
141
147
// Use for external node dependencies
142
148
// TODO: add what version of CLI this is used for
143
149
pub node_dependencies : Option < Vec < NodeDependencyJson > > ,
@@ -281,6 +287,12 @@ pub struct PushAnalytics {
281
287
pub udf_server_version : Version ,
282
288
pub analyze_results : BTreeMap < CanonicalizedModulePath , AnalyzedModule > ,
283
289
pub schema : Option < DatabaseSchema > ,
290
+ }
291
+
292
+ pub struct PushMetrics {
293
+ pub build_external_deps_time : Duration ,
294
+ pub upload_source_package_time : Duration ,
295
+ pub analyze_time : Duration ,
284
296
pub occ_stats : OccRetryStats ,
285
297
}
286
298
@@ -351,7 +363,7 @@ pub async fn push_config(
351
363
pub async fn push_config_handler (
352
364
application : & Application < ProdRuntime > ,
353
365
config : ConfigJson ,
354
- ) -> anyhow:: Result < ( Identity , PushAnalytics ) > {
366
+ ) -> anyhow:: Result < ( Identity , PushAnalytics , PushMetrics ) > {
355
367
let modules: Vec < ModuleConfig > = config
356
368
. modules
357
369
. into_iter ( )
@@ -366,6 +378,7 @@ pub async fn push_config_handler(
366
378
ErrorMetadata :: bad_request ( "InvalidVersion" , "The function version is invalid" ) ,
367
379
) ?;
368
380
381
+ let begin_build_external_deps = Instant :: now ( ) ;
369
382
// Upload external node dependencies separately
370
383
let external_deps_id_and_pkg = if let Some ( deps) = config. node_dependencies
371
384
&& !deps. is_empty ( )
@@ -375,6 +388,7 @@ pub async fn push_config_handler(
375
388
} else {
376
389
None
377
390
} ;
391
+ let end_build_external_deps = Instant :: now ( ) ;
378
392
let external_deps_pkg_size = external_deps_id_and_pkg
379
393
. as_ref ( )
380
394
. map ( |( _, pkg) | pkg. package_size )
@@ -383,7 +397,7 @@ pub async fn push_config_handler(
383
397
let source_package = application
384
398
. upload_package ( & modules, external_deps_id_and_pkg)
385
399
. await ?;
386
-
400
+ let end_upload_source_package = Instant :: now ( ) ;
387
401
// Verify that we have not exceeded the max zipped or unzipped file size
388
402
let combined_pkg_size = source_package
389
403
. as_ref ( )
@@ -398,7 +412,7 @@ pub async fn push_config_handler(
398
412
import_phase_rng_seed : application. runtime ( ) . with_rng ( |rng| rng. gen ( ) ) ,
399
413
import_phase_unix_timestamp : application. runtime ( ) . unix_timestamp ( ) ,
400
414
} ;
401
-
415
+ let begin_analyze = Instant :: now ( ) ;
402
416
// Run analyze to make sure the new modules are valid.
403
417
let ( auth_module, analyze_result) = analyze_modules_with_auth_config (
404
418
application,
@@ -407,6 +421,7 @@ pub async fn push_config_handler(
407
421
source_package. clone ( ) ,
408
422
)
409
423
. await ?;
424
+ let end_analyze = Instant :: now ( ) ;
410
425
let (
411
426
ConfigMetadataAndSchema {
412
427
config_metadata,
@@ -436,6 +451,11 @@ pub async fn push_config_handler(
436
451
udf_server_version : udf_config. server_version ,
437
452
analyze_results : analyze_result,
438
453
schema,
454
+ } ,
455
+ PushMetrics {
456
+ build_external_deps_time : end_build_external_deps - begin_build_external_deps,
457
+ upload_source_package_time : end_upload_source_package - end_build_external_deps,
458
+ analyze_time : end_analyze - begin_analyze,
439
459
occ_stats,
440
460
} ,
441
461
) )
0 commit comments