From bfe352bae471cca05fdb45eb312fc74febca30ea Mon Sep 17 00:00:00 2001 From: Stanislau Hlebik Date: Wed, 17 Oct 2018 08:03:39 -0700 Subject: [PATCH] mononoke: change logging in hook_tailer Summary: Let's change level of logging for each hook/commit to debug, since it was spammy. Instead let's print a total statistics about how many hooks were accepted/rejected Reviewed By: jsgf Differential Revision: D10358786 fbshipit-source-id: 2e451d482ed5549e41975f9e3b57b05d90069788 --- hook_tailer/main.rs | 50 +++++++++++++++++++++++++++++++++++++++---- hook_tailer/tailer.rs | 4 ++-- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/hook_tailer/main.rs b/hook_tailer/main.rs index dfe38893e1..5ba8319e62 100644 --- a/hook_tailer/main.rs +++ b/hook_tailer/main.rs @@ -55,6 +55,7 @@ use slog::{Drain, Level, Logger}; use slog_glog_fmt::{kv_categorizer, kv_defaults, GlogFormat}; use slog_logview::LogViewDrain; use slog_scuba::ScubaDrain; +use std::fmt; use std::io; use std::path::PathBuf; use std::str::FromStr; @@ -161,10 +162,15 @@ fn create_poller(tailer: Tailer, logger: Logger) -> BoxFuture { tailer .run() .map(move |res| { + let mut file_hooks_stat = HookExecutionStat::new(); + let mut cs_hooks_stat = HookExecutionStat::new(); + res.into_iter().for_each(|(v_files, v_cs)| { - info!(logger, "==== File hooks results ===="); + debug!(logger, "==== File hooks results ===="); v_files.into_iter().for_each(|(exec_id, exec)| { - info!( + file_hooks_stat.record_hook_execution(&exec); + + debug!( logger, "changeset:{} hook_name:{} path:{} result:{:?}", exec_id.cs_id, @@ -173,9 +179,10 @@ fn create_poller(tailer: Tailer, logger: Logger) -> BoxFuture { exec ); }); - info!(logger, "==== Changeset hooks results ===="); + debug!(logger, "==== Changeset hooks results ===="); v_cs.into_iter().for_each(|(exec_id, exec)| { - info!( + cs_hooks_stat.record_hook_execution(&exec); + debug!( logger, "changeset:{} hook_name:{} result:{:?}", exec_id.cs_id, @@ -184,12 +191,47 @@ fn create_poller(tailer: Tailer, logger: Logger) -> BoxFuture { ); }); }); + + info!(logger, "==== File hooks stat: {} ====", file_hooks_stat); + info!(logger, "==== Changeset hooks stat: {} ====", cs_hooks_stat); + () }) .map(move |()| tailer) .boxify() } +struct HookExecutionStat { + accepted: usize, + rejected: usize, +} + +impl HookExecutionStat { + pub fn new() -> Self { + Self { + accepted: 0, + rejected: 0, + } + } + + pub fn record_hook_execution(&mut self, exec: &hooks::HookExecution) { + match exec { + hooks::HookExecution::Accepted => { + self.accepted += 1; + } + hooks::HookExecution::Rejected(_) => { + self.rejected += 1; + } + }; + } +} + +impl fmt::Display for HookExecutionStat { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "accepted: {}, rejected: {}", self.accepted, self.rejected) + } +} + fn setup_app<'a, 'b>() -> App<'a, 'b> { cmdlib::args::add_cachelib_args(App::new("mononoke hook server") .version("0.0.0") diff --git a/hook_tailer/tailer.rs b/hook_tailer/tailer.rs index 97ef0ce278..5e5ef9752c 100644 --- a/hook_tailer/tailer.rs +++ b/hook_tailer/tailer.rs @@ -106,12 +106,12 @@ impl Tailer { Ok(*hg_cs != HgChangesetId::new(last_rev)) }) .and_then(move |hg_cs| { - info!(logger, "Running file hooks for changeset {:?}", hg_cs); + debug!(logger, "Running file hooks for changeset {:?}", hg_cs); hm.run_file_hooks_for_bookmark(hg_cs.clone(), &bm, None) .map(move |res| (hg_cs, res)) }) .and_then(move |(hg_cs, file_res)| { - info!(logger2, "Running changeset hooks for changeset {:?}", hg_cs); + debug!(logger2, "Running changeset hooks for changeset {:?}", hg_cs); hm2.run_changeset_hooks_for_bookmark(hg_cs.clone(), &bm2, None) .map(|res| (file_res, res)) })