From 35ff21c72e65d1e01678d67c7dd985e2959d4ebf Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 24 Aug 2021 15:17:58 +0200 Subject: Truncate operation result logs if too large --- bbot/worker/worker.cxx | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/bbot/worker/worker.cxx b/bbot/worker/worker.cxx index d7a2570..1f5c946 100644 --- a/bbot/worker/worker.cxx +++ b/bbot/worker/worker.cxx @@ -2070,6 +2070,46 @@ build (size_t argc, const char* argv[]) rm.status |= r.status; } + + // Truncate logs if they would exceed the upload limit. + // + // @@ TMP: currently this limit is hard-coded. In the future it should be + // sent along with the task manifest. + // + const size_t upload_limit (10 * 1024 * 1024); + { + // Reserve 10K for other manifest values (alternatively, we could do it + // exactly in upload_manifest()). + // + const size_t manifest_size (10 * 1024); + + size_t n (manifest_size); + for (const operation_result& r: rm.results) + n += r.log.size (); + + if (n > upload_limit) + { + // Divide the size equally among all the operations and truncate any + // that exceed their allowance. This way we will get some information + // for each operation. + // + n = (upload_limit - manifest_size) / rm.results.size (); + + for (operation_result& r: rm.results) + { + if (r.log.size () <= n) + continue; + + // We need to be careful not to truncate it in the middle of UTF-8 + // sequence. So we look for the last newline that still fits. + // + size_t p (n - 80 /* for the "log truncated" note */); + for (; p != 0 && r.log[p] != '\n'; --p) ; + r.log.resize (p != 0 ? p + 1 : 0); // Keep the newline. + r.log += "-------------------------------LOG TRUNCATED-------------------------------\n"; + } + } + } } else assert (rm.status == result_status::abort); -- cgit v1.1