You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nifi.apache.org by fg...@apache.org on 2023/09/21 10:19:31 UTC
[nifi-minifi-cpp] 02/04: MINIFICPP-2193 - Add manifest to debug bundle
This is an automated email from the ASF dual-hosted git repository.
fgerlits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit 9ec2010a0dce27e67124eefe07e9182e2467c055
Author: Adam Debreceni <ad...@apache.org>
AuthorDate: Wed Sep 6 07:54:39 2023 +0200
MINIFICPP-2193 - Add manifest to debug bundle
Signed-off-by: Ferenc Gerlits <fg...@gmail.com>
This closes #1651
---
extensions/http-curl/tests/C2DebugBundleTest.cpp | 5 ++++-
libminifi/src/c2/C2Agent.cpp | 19 ++++++++++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/extensions/http-curl/tests/C2DebugBundleTest.cpp b/extensions/http-curl/tests/C2DebugBundleTest.cpp
index b68bd7b7c..315e73e2c 100644
--- a/extensions/http-curl/tests/C2DebugBundleTest.cpp
+++ b/extensions/http-curl/tests/C2DebugBundleTest.cpp
@@ -91,7 +91,9 @@ class C2DebugBundleHandler : public ServerAwareHandler {
}
static int field_get(const char* /*key*/, const char* value, size_t valuelen, void* user_data) {
auto& file_content = *static_cast<std::optional<std::string>*>(user_data);
- file_content = "";
+ if (!file_content) {
+ file_content = "";
+ }
(*file_content) += std::string(value, valuelen);
return MG_FORM_FIELD_HANDLE_GET;
}
@@ -183,6 +185,7 @@ int main() {
log_text.resize(log_stream->size());
log_stream->read(as_writable_bytes(std::span(log_text)));
assert(log_text.find("Tis but a scratch") != std::string::npos);
+ assert(archive_content["manifest.json"].find("minifi-archive-extensions") != std::string::npos);
return true;
});
diff --git a/libminifi/src/c2/C2Agent.cpp b/libminifi/src/c2/C2Agent.cpp
index 9891fb9de..64464a602 100644
--- a/libminifi/src/c2/C2Agent.cpp
+++ b/libminifi/src/c2/C2Agent.cpp
@@ -676,7 +676,7 @@ C2Payload C2Agent::bundleDebugInfo(std::map<std::string, std::unique_ptr<io::Inp
if (!archiver) {
throw C2DebugBundleError("Couldn't instantiate archiver");
}
- for (auto&[filename, stream] : files) {
+ for (auto& [filename, stream] : files) {
size_t file_size = stream->size();
if (!archiver->newEntry({filename, file_size})) {
throw C2DebugBundleError("Couldn't initialize archive entry for '" + filename + "'");
@@ -686,6 +686,23 @@ C2Payload C2Agent::bundleDebugInfo(std::map<std::string, std::unique_ptr<io::Inp
throw C2DebugBundleError("Error while writing file '" + filename + "' into the debug bundle");
}
}
+ if (auto node_reporter = node_reporter_.lock()) {
+ static constexpr const char* MANIFEST_FILE_NAME = "manifest.json";
+ auto reported_manifest = node_reporter->getAgentManifest();
+ std::string manifest_str = state::response::SerializedResponseNode{
+ .name = std::move(reported_manifest.name),
+ .array = reported_manifest.is_array,
+ .children = std::move(reported_manifest.serialized_nodes)
+ }.to_pretty_string();
+ if (!archiver->newEntry({MANIFEST_FILE_NAME, manifest_str.size()})) {
+ throw C2DebugBundleError(fmt::format("Couldn't initialize archive entry for '{}'", MANIFEST_FILE_NAME));
+ }
+ io::BufferStream manifest_stream;
+ manifest_stream.write(as_bytes(std::span(manifest_str)));
+ if (gsl::narrow<int64_t>(manifest_stream.size()) != internal::pipe(manifest_stream, *archiver)) {
+ throw C2DebugBundleError(fmt::format("Error while writing file '{}'", MANIFEST_FILE_NAME));
+ }
+ }
if (!archiver->finish()) {
throw C2DebugBundleError("Failed to complete debug bundle archive");
}