From ca2be062f15bd0a0f22ce80c2d59059ed5b2489b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Santos=20Reis?= Date: Tue, 27 Feb 2024 15:39:15 +0000 Subject: [PATCH 1/2] Support simplified data reporting in node status service --- .../node_status_service.ml | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/lib/node_status_service/node_status_service.ml b/src/lib/node_status_service/node_status_service.ml index 90e604f616e..f0e0d3dbefc 100644 --- a/src/lib/node_status_service/node_status_service.ml +++ b/src/lib/node_status_service/node_status_service.ml @@ -74,7 +74,22 @@ type node_status_data = } [@@deriving to_yojson] -let send_node_status_data ~logger ~url node_status_data = +module Simplified = struct + type t = + { max_observed_block_height : int + ; commit_hash : string + ; git_branch : string + ; chain_id : string + ; peer_id : string + ; peer_count : int + ; timestamp : string + ; block_producer_public_key : string option + } + [@@deriving to_yojson] +end + +let send_node_status_data (type data) ~logger ~url (node_status_data : data) + (node_status_data_to_yojson : data -> Yojson.Safe.t) = let node_status_json = node_status_data_to_yojson node_status_data in let json = `Assoc [ ("data", node_status_json) ] in let headers = @@ -90,8 +105,10 @@ let send_node_status_data ~logger ~url node_status_data = let metadata = [ ("data", node_status_json); ("url", `String (Uri.to_string url)) ] in - if Cohttp.Code.code_of_status status = 200 then - [%log info] "Sent node status data to URL $url" ~metadata + if + Cohttp.Code.( + code_of_status status >= 200 && code_of_status status < 300) + then [%log info] "Sent node status data to URL $url" ~metadata else let extra_metadata = match body with @@ -354,9 +371,34 @@ let start ~logger ~node_status_url ~transition_frontier ~sync_status ~network reset_gauges () ; send_node_status_data ~logger ~url:(Uri.of_string node_status_url) - node_status_data + node_status_data node_status_data_to_yojson | Error e -> [%log info] ~metadata:[ ("error", `String (Error.to_string_hum e)) ] "Failed to get bandwidth info from libp2p" ; Deferred.unit ) + +let start_simplified ~logger ~node_status_url ~chain_id ~network + ~addrs_and_ports ~slot_duration ~block_producer_public_key_base58 = + [%log info] "Starting simplified node status service using URL $url" + ~metadata:[ ("url", `String node_status_url) ] ; + let five_slots = Time.Span.scale slot_duration 5. in + every ~start:(after five_slots) ~continue_on_error:true five_slots + @@ fun () -> + don't_wait_for + @@ let%bind peers = Mina_networking.peers network in + let node_status_data = + { Simplified.max_observed_block_height = + !Mina_metrics.Transition_frontier.max_blocklength_observed + ; commit_hash = Mina_version.commit_id + ; git_branch = Mina_version.branch + ; chain_id + ; peer_id = (Node_addrs_and_ports.to_peer_exn addrs_and_ports).peer_id + ; peer_count = List.length peers + ; timestamp = Rfc3339_time.get_rfc3339_time () + ; block_producer_public_key = block_producer_public_key_base58 + } + in + send_node_status_data ~logger + ~url:(Uri.of_string node_status_url) + node_status_data Simplified.to_yojson From 1e91dfce2ead44efed7b270c007251f5f3db8cdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joa=CC=83o=20Santos=20Reis?= Date: Tue, 27 Feb 2024 15:41:29 +0000 Subject: [PATCH 2/2] Add simplified node stats flag to CLI and configuration --- .../src/cli_entrypoint/mina_cli_entrypoint.ml | 7 +++- src/lib/mina_lib/config.ml | 1 + src/lib/mina_lib/mina_lib.ml | 36 ++++++++++++++----- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml index 2f40840c6a2..1d1f7fe136d 100644 --- a/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml +++ b/src/app/cli/src/cli_entrypoint/mina_cli_entrypoint.ml @@ -400,6 +400,10 @@ let setup_daemon logger = and node_error_url = flag "--node-error-url" ~aliases:[ "node-error-url" ] (optional string) ~doc:"URL of the node error collection service" + and simplified_node_stats = + flag "--simplified-node-stats" + ~aliases:[ "simplified-node-stats" ] + no_arg ~doc:"whether to report simplified node stats (default: false)" and contact_info = flag "--contact-info" ~aliases:[ "contact-info" ] (optional string) ~doc: @@ -1300,7 +1304,8 @@ Pass one of -peer, -peer-list-file, -seed, -peer-list-url.|} ; ~log_block_creation ~precomputed_values ~start_time ?precomputed_blocks_path ~log_precomputed_blocks ~upload_blocks_to_gcloud ~block_reward_threshold ~uptime_url - ~uptime_submitter_keypair ~stop_time ~node_status_url () ) + ~uptime_submitter_keypair ~stop_time ~node_status_url + ~simplified_node_stats () ) in { Coda_initialization.coda ; client_trustlist diff --git a/src/lib/mina_lib/config.ml b/src/lib/mina_lib/config.ml index 4bdf35b6045..328f5015d22 100644 --- a/src/lib/mina_lib/config.ml +++ b/src/lib/mina_lib/config.ml @@ -56,6 +56,7 @@ type t = ; upload_blocks_to_gcloud : bool ; block_reward_threshold : Currency.Amount.t option [@default None] ; node_status_url : string option [@default None] + ; simplified_node_stats : bool [@default false] ; uptime_url : Uri.t option [@default None] ; uptime_submitter_keypair : Keypair.t option [@default None] ; stop_time : int diff --git a/src/lib/mina_lib/mina_lib.ml b/src/lib/mina_lib/mina_lib.ml index 0b28a94a9b0..f0842f8a379 100644 --- a/src/lib/mina_lib/mina_lib.ml +++ b/src/lib/mina_lib/mina_lib.ml @@ -1219,15 +1219,33 @@ let start t = let () = match t.config.node_status_url with | Some node_status_url -> - Node_status_service.start ~logger:t.config.logger ~node_status_url - ~network:t.components.net - ~transition_frontier:t.components.transition_frontier - ~sync_status:t.sync_status - ~addrs_and_ports:t.config.gossip_net_params.addrs_and_ports - ~start_time:t.config.start_time - ~slot_duration: - (Block_time.Span.to_time_span - t.config.precomputed_values.consensus_constants.slot_duration_ms ) + if t.config.simplified_node_stats then + let block_producer_public_key_base58 = + Option.map ~f:(fun (_, pk) -> + Public_key.Compressed.to_base58_check pk ) + @@ Keypair.And_compressed_pk.Set.choose + t.config.block_production_keypairs + in + Node_status_service.start_simplified ~logger:t.config.logger + ~node_status_url ~network:t.components.net + ~chain_id:t.config.chain_id + ~addrs_and_ports:t.config.gossip_net_params.addrs_and_ports + ~slot_duration: + (Block_time.Span.to_time_span + t.config.precomputed_values.consensus_constants + .slot_duration_ms ) + ~block_producer_public_key_base58 + else + Node_status_service.start ~logger:t.config.logger ~node_status_url + ~network:t.components.net + ~transition_frontier:t.components.transition_frontier + ~sync_status:t.sync_status + ~addrs_and_ports:t.config.gossip_net_params.addrs_and_ports + ~start_time:t.config.start_time + ~slot_duration: + (Block_time.Span.to_time_span + t.config.precomputed_values.consensus_constants + .slot_duration_ms ) | None -> () in