1- use std:: collections:: BTreeMap ;
1+ use std:: {
2+ collections:: BTreeMap ,
3+ time:: {
4+ Duration ,
5+ Instant ,
6+ } ,
7+ } ;
28
39use anyhow:: {
410 anyhow,
@@ -95,7 +101,7 @@ pub struct GetConfigHashesResponse {
95101
96102#[ derive( Deserialize , Debug , Copy , Clone ) ]
97103#[ serde( rename_all = "camelCase" ) ]
98- pub struct PushMetrics {
104+ pub struct ClientPushMetrics {
99105 pub typecheck : f64 ,
100106 pub bundle : f64 ,
101107 pub schema_push : f64 ,
@@ -137,7 +143,7 @@ pub struct ConfigJson {
137143 // Used in CLI >= 0.14.0, None when there is no schema file.
138144 pub schema_id : Option < String > ,
139145 // Used in CLI >= future
140- pub push_metrics : Option < PushMetrics > ,
146+ pub push_metrics : Option < ClientPushMetrics > ,
141147 // Use for external node dependencies
142148 // TODO: add what version of CLI this is used for
143149 pub node_dependencies : Option < Vec < NodeDependencyJson > > ,
@@ -281,6 +287,12 @@ pub struct PushAnalytics {
281287 pub udf_server_version : Version ,
282288 pub analyze_results : BTreeMap < CanonicalizedModulePath , AnalyzedModule > ,
283289 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 ,
284296 pub occ_stats : OccRetryStats ,
285297}
286298
@@ -351,7 +363,7 @@ pub async fn push_config(
351363pub async fn push_config_handler (
352364 application : & Application < ProdRuntime > ,
353365 config : ConfigJson ,
354- ) -> anyhow:: Result < ( Identity , PushAnalytics ) > {
366+ ) -> anyhow:: Result < ( Identity , PushAnalytics , PushMetrics ) > {
355367 let modules: Vec < ModuleConfig > = config
356368 . modules
357369 . into_iter ( )
@@ -366,6 +378,7 @@ pub async fn push_config_handler(
366378 ErrorMetadata :: bad_request ( "InvalidVersion" , "The function version is invalid" ) ,
367379 ) ?;
368380
381+ let begin_build_external_deps = Instant :: now ( ) ;
369382 // Upload external node dependencies separately
370383 let external_deps_id_and_pkg = if let Some ( deps) = config. node_dependencies
371384 && !deps. is_empty ( )
@@ -375,6 +388,7 @@ pub async fn push_config_handler(
375388 } else {
376389 None
377390 } ;
391+ let end_build_external_deps = Instant :: now ( ) ;
378392 let external_deps_pkg_size = external_deps_id_and_pkg
379393 . as_ref ( )
380394 . map ( |( _, pkg) | pkg. package_size )
@@ -383,7 +397,7 @@ pub async fn push_config_handler(
383397 let source_package = application
384398 . upload_package ( & modules, external_deps_id_and_pkg)
385399 . await ?;
386-
400+ let end_upload_source_package = Instant :: now ( ) ;
387401 // Verify that we have not exceeded the max zipped or unzipped file size
388402 let combined_pkg_size = source_package
389403 . as_ref ( )
@@ -398,7 +412,7 @@ pub async fn push_config_handler(
398412 import_phase_rng_seed : application. runtime ( ) . with_rng ( |rng| rng. gen ( ) ) ,
399413 import_phase_unix_timestamp : application. runtime ( ) . unix_timestamp ( ) ,
400414 } ;
401-
415+ let begin_analyze = Instant :: now ( ) ;
402416 // Run analyze to make sure the new modules are valid.
403417 let ( auth_module, analyze_result) = analyze_modules_with_auth_config (
404418 application,
@@ -407,6 +421,7 @@ pub async fn push_config_handler(
407421 source_package. clone ( ) ,
408422 )
409423 . await ?;
424+ let end_analyze = Instant :: now ( ) ;
410425 let (
411426 ConfigMetadataAndSchema {
412427 config_metadata,
@@ -436,6 +451,11 @@ pub async fn push_config_handler(
436451 udf_server_version : udf_config. server_version ,
437452 analyze_results : analyze_result,
438453 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,
439459 occ_stats,
440460 } ,
441461 ) )
0 commit comments