From 9f55b991d0e54ed96f9abfae0109b392ca1390f3 Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Mon, 29 Aug 2016 17:06:47 +0200 Subject: [PATCH] Fixes #8871: missing rudder_expected_reports.csv.res when starting the agent for the first time after an update --- tree/30_generic_methods/logger_rudder.cf | 34 ++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tree/30_generic_methods/logger_rudder.cf b/tree/30_generic_methods/logger_rudder.cf index da8c0da79..e99633d79 100644 --- a/tree/30_generic_methods/logger_rudder.cf +++ b/tree/30_generic_methods/logger_rudder.cf @@ -30,8 +30,12 @@ bundle agent logger_rudder(message, class_prefix) vars: "expected_reports_source" string => "${sys.workdir}/inputs/rudder_expected_reports.csv"; - "expected_reports_temp" string => "${expected_reports_source}.tmp"; - "expected_reports_file" string => "${expected_reports_source}.res"; + "expected_reports_destination" string => "${sys.workdir}/state/rudder_expected_reports.${this.promiser_pid}.csv"; + # We put those files into the state directory to avoid purging them during each update + # (whoch would break the current run's reporting). + # We add the PID to the file name to be able to handle cuncurrent agent runs with separate expected reports + "expected_reports_temp" string => "${expected_reports_destination}.tmp"; + "expected_reports_file" string => "${expected_reports_destination}.res"; pass1.(!final_resfile_exists.logger_rudder_temp_resfile_reached|logger_rudder_temp_resfile_repaired):: # 2/ If the temporary file has been updated, read it to get all values in an array, and canonify the first entry @@ -94,6 +98,32 @@ bundle agent logger_rudder(message, class_prefix) } +# This bundle will delete the current expected reports file +# It is supposed to be called at the end of the run +bundle agent _clean_current_expected_reports_file { + + vars: + "files_to_remove" slist => { "${logger_rudder.expected_reports_temp}", + "${logger_rudder.expected_reports_file}" } + + files: + "${files_to_remove}" + delete => tidy; + +} + +# This bundle will delete expected reports files older than the given age +# It allows cleaning leftovers from interrupted executions +bundle agent _clean_old_expected_reports_file(days) { + + files: + "${sys.workdir}/state/rudder_expected_reports.*.csv.res" + + delete => tidy, + file_select => days_old("${days}"); + +} + # bundle backported from rudder (prefixed with _ to avoid conflicts) # all this whould be removed when we put this file back to rudder #