This is an automated email from the ASF dual-hosted git repository. martinzink pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi-minifi-cpp.git
commit f856bb60f46f251f0e57a5a8e68bbba0fc8bc8b5 Author: Ferenc Gerlits <[email protected]> AuthorDate: Wed Feb 25 14:52:55 2026 +0100 MINIFICPP-2730 Check if config.yml exists when creating the debug bundle At `FlowController.cpp` lines 484-486, we add `config.yml` to the debug bundle if it is configured, but we don't check if the file really exists. As a result, the debug bundle operation fails. Since #2069, the file may not exist initially, if C2 is enabled but no flow is configured on C2 for the agent class. Closes #2119 Signed-off-by: Martin Zink <[email protected]> --- libminifi/src/FlowController.cpp | 5 ++- libminifi/test/integration/C2DebugBundleTest.cpp | 39 +++++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/libminifi/src/FlowController.cpp b/libminifi/src/FlowController.cpp index bd7a38bd7..16a43ec13 100644 --- a/libminifi/src/FlowController.cpp +++ b/libminifi/src/FlowController.cpp @@ -36,6 +36,7 @@ #include "minifi-cpp/core/Connectable.h" #include "utils/file/PathUtils.h" #include "utils/file/FileSystem.h" +#include "utils/file/FileUtils.h" #include "http/BaseHTTPClient.h" #include "io/NetworkPrioritizer.h" #include "io/FileStream.h" @@ -482,7 +483,9 @@ std::map<std::string, std::unique_ptr<io::InputStream>> FlowController::getDebug debug_info["minifi.log" + index_str + ".gz"] = std::move(logs[i]); } if (auto opt_flow_path = flow_configuration_->getConfigurationPath()) { - debug_info["config.yml"] = std::make_unique<io::FileStream>(opt_flow_path.value(), 0, false); + if (utils::file::exists(opt_flow_path.value())) { + debug_info["config.yml"] = std::make_unique<io::FileStream>(opt_flow_path.value(), 0, false); + } } debug_info["minifi.properties"] = std::make_unique<io::FileStream>(configuration_->getFilePath(), 0, false); diff --git a/libminifi/test/integration/C2DebugBundleTest.cpp b/libminifi/test/integration/C2DebugBundleTest.cpp index 83c6f8b8e..6a5ab86b3 100644 --- a/libminifi/test/integration/C2DebugBundleTest.cpp +++ b/libminifi/test/integration/C2DebugBundleTest.cpp @@ -149,10 +149,10 @@ TEST_CASE("C2DebugBundleTest", "[c2test]") { std::filesystem::path home_dir = controller.createTempDirectory(); minifi::utils::file::PathUtils::create_dir(home_dir / "conf"); - std::ofstream{home_dir / "conf/minifi.properties", std::ios::binary} << properties_file; - std::ofstream{home_dir / "conf/config.yml", std::ios::binary} << flow_config_file; + std::ofstream{home_dir / "conf" / "minifi.properties", std::ios::binary} << properties_file; + std::ofstream{home_dir / "conf" / "config.yml", std::ios::binary} << flow_config_file; - VerifyDebugInfo harness(home_dir / "conf/config.yml", [&]() -> bool { + VerifyDebugInfo harness(home_dir / "conf" / "config.yml", [&]() -> bool { if (!ack_handler.isAcknowledged("79")) { return false; } @@ -190,7 +190,7 @@ TEST_CASE("C2DebugBundleTest", "[c2test]") { return true; }); - harness.getConfiguration()->loadConfigureFile(home_dir / "conf/minifi.properties"); + harness.getConfiguration()->loadConfigureFile(home_dir / "conf" / "minifi.properties"); harness.setUrl("http://localhost:0/heartbeat", &heartbeat_handler); harness.setUrl("http://localhost:0/acknowledge", &ack_handler); harness.setUrl("http://localhost:0/debug_bundle", &bundle_handler); @@ -203,4 +203,35 @@ TEST_CASE("C2DebugBundleTest", "[c2test]") { harness.run(); } +TEST_CASE("Test that the debug bundle operation works when config.yml does not exist", "[c2test]") { + TestController controller; + + C2HeartbeatHandler heartbeat_handler; + C2AcknowledgeHandler ack_handler; + C2DebugBundleHandler bundle_handler; + + std::filesystem::path home_dir = controller.createTempDirectory(); + minifi::utils::file::PathUtils::create_dir(home_dir / "conf"); + std::ofstream{home_dir / "conf" / "minifi.properties", std::ios::binary} << properties_file; + + VerifyDebugInfo harness(home_dir / "conf" / "config.yml", [&]() -> bool { + if (!ack_handler.isAcknowledged("79")) { + return false; + } + auto bundles = bundle_handler.getBundles(); + REQUIRE(bundles.size() == 1); + return true; + }); + + harness.getConfiguration()->loadConfigureFile(home_dir / "conf" / "minifi.properties"); + harness.setUrl("http://localhost:0/heartbeat", &heartbeat_handler); + harness.setUrl("http://localhost:0/acknowledge", &ack_handler); + harness.setUrl("http://localhost:0/debug_bundle", &bundle_handler); + harness.setC2Url("/heartbeat", "/acknowledge"); + + heartbeat_handler.setC2RestResponse("http://localhost:" + harness.getWebPort() + "/debug_bundle"); + + harness.run(); +} + } // namespace org::apache::nifi::minifi::test
