From 5874c2db9825d91be9fd7c3aaf64f4ba7d45fd99 Mon Sep 17 00:00:00 2001 From: Gabriel Moise Date: Mon, 2 Dec 2024 17:31:17 +0000 Subject: [PATCH] Profiling: Allow children profiling in prometheus without parents being profiled --- src/bin_node/prometheus_profiler.ml | 20 ++++++++------------ src/bin_node/prometheus_profiler.mli | 6 +----- src/lib_store/unix/block_store.ml | 6 +----- src/lib_store/unix/store.ml | 8 +------- 4 files changed, 11 insertions(+), 29 deletions(-) diff --git a/src/bin_node/prometheus_profiler.ml b/src/bin_node/prometheus_profiler.ml index 6a51e167c20a..5e152a43605a 100644 --- a/src/bin_node/prometheus_profiler.ml +++ b/src/bin_node/prometheus_profiler.ml @@ -68,16 +68,11 @@ module Prometheus = struct "time" (** Because prometheus can't handle high cardinality in metrics names, - we treat only those who are specifically marked for the prometheus backend. - Returns a boolean that indicate if the entry has been registered or not. *) + we treat only those who are specifically marked for the prometheus backend. *) let output_entry subsystem (id, metadata) n d = let namespace = "profiling" in match Stdlib.List.assoc_opt "prometheus" metadata with - | None -> false - | Some "__ENABLE_CHILDREN_ONLY__" -> - (* We don't record the metric but pretend we did so that children of - the node will be processed *) - true + | None -> () | Some id' -> let id = if id' = "" then id else id' in if d.wall = 0. then @@ -88,8 +83,7 @@ module Prometheus = struct Prometheus.Summary.observe (summary ~namespace ~subsystem id) ~n:(Float.of_int n) - d.wall ; - true + d.wall let output_report = let output t r = @@ -100,13 +94,15 @@ module Prometheus = struct only recorded if the parent is. *) IdMap.iter (fun id {count = n; total = Span d; node_verbosity = _; children} -> - if output_entry t.name id n d then - output {recorded = []; aggregated = children}) + output_entry t.name id n d ; + output {recorded = []; aggregated = children}) aggregated ; List.iter (fun ( id, {start = _; duration = Span d; contents; item_verbosity = _} - ) -> if output_entry t.name id 1 d then output contents) + ) -> + output_entry t.name id 1 d ; + output contents) recorded in output r diff --git a/src/bin_node/prometheus_profiler.mli b/src/bin_node/prometheus_profiler.mli index b9a725bb65e6..f126b5fb6d5b 100644 --- a/src/bin_node/prometheus_profiler.mli +++ b/src/bin_node/prometheus_profiler.mli @@ -17,9 +17,5 @@ You MUST avoid metric names that are too unique such as block or operation hashes because prometheus will quickly fail at handling - a too high metrics cardinality otherwise. - - Note that if a parent node is not marked as the "prometheus" attribute, - its children will be skipped. In order to skip the node but not its - children, use the special value ["__ENABLE_CHILDREN_ONLY__"]. *) + a too high metrics cardinality otherwise. *) val prometheus : (string * Profiler.verbosity) Profiler.driver diff --git a/src/lib_store/unix/block_store.ml b/src/lib_store/unix/block_store.ml index 3ce6adbe8457..c217bfd2f202 100644 --- a/src/lib_store/unix/block_store.ml +++ b/src/lib_store/unix/block_store.ml @@ -1490,11 +1490,7 @@ let merge_stores ?(cycle_size_limit = default_cycle_size_limit) block_store previous merge. *) () [@profiler.reset_block_section - { - verbosity = Notice; - metadata = [("prometheus", "__ENABLE_CHILDREN_ONLY__")]; - } - (Block_repr.hash new_head)] ; + {verbosity = Notice} (Block_repr.hash new_head)] ; let*! () = Lwt_mutex.lock block_store.merge_mutex in protect ~on_error:(fun err -> diff --git a/src/lib_store/unix/store.ml b/src/lib_store/unix/store.ml index 40101ca0b302..9c81f9516f82 100644 --- a/src/lib_store/unix/store.ml +++ b/src/lib_store/unix/store.ml @@ -510,13 +510,7 @@ module Block = struct let open Lwt_result_syntax in let bytes = Block_header.to_bytes block_header in let hash = Block_header.hash_raw bytes in - () - [@profiler.reset_block_section - { - verbosity = Notice; - metadata = [("prometheus", "__ENABLE_CHILDREN_ONLY__")]; - } - hash] ; + () [@profiler.reset_block_section {verbosity = Notice} hash] ; (let { Block_validation.validation_store = { -- GitLab