szaszm commented on a change in pull request #743: Minificpp 1169 - Simplify C2
metrics collection and reporting
URL: https://github.com/apache/nifi-minifi-cpp/pull/743#discussion_r393121094
##########
File path: extensions/http-curl/tests/C2JstackTest.cpp
##########
@@ -16,152 +16,63 @@
* limitations under the License.
*/
-#include <sys/stat.h>
#undef NDEBUG
-#include <cassert>
-#include <utility>
-#include <chrono>
-#include <fstream>
-#include <memory>
#include <string>
-#include <thread>
-#include <type_traits>
-#include <vector>
-#include <iostream>
-#include <sstream>
-#include "HTTPClient.h"
-#include "InvokeHTTP.h"
#include "TestBase.h"
-#include "utils/StringUtils.h"
-#include "core/Core.h"
-#include "core/logging/Logger.h"
-#include "core/ProcessGroup.h"
-#include "core/yaml/YamlConfiguration.h"
-#include "FlowController.h"
-#include "properties/Configure.h"
-#include "unit/ProvenanceTestHelper.h"
-#include "io/StreamFactory.h"
-#include "c2/C2Agent.h"
-#include "CivetServer.h"
-#include <cstring>
-#include "protocols/RESTSender.h"
+#include "HTTPIntegrationBase.h"
+#include "HTTPHandlers.h"
-void waitToVerifyProcessor() {
- std::this_thread::sleep_for(std::chrono::seconds(10));
-}
-
-
-class ConfigHandler : public CivetHandler {
+class VerifyC2DescribeJstack : public VerifyC2Describe {
public:
- ConfigHandler() {
- calls_ = 0;
- }
- bool handlePost(CivetServer *server, struct mg_connection *conn) {
- calls_++;
- std::string heartbeat_response = "{\"operation\" :
\"heartbeat\",\"requested_operations\": [ {"
- "\"operation\" : \"describe\", "
- "\"operationid\" : \"8675309\", "
- "\"name\": \"jstack\""
- "}]}";
- mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
- "text/plain\r\nContent-Length: %lu\r\nConnection:
close\r\n\r\n",
- heartbeat_response.length());
- mg_printf(conn, "%s", heartbeat_response.c_str());
-
-
- return true;
+ explicit VerifyC2DescribeJstack(bool isSecure)
+ : VerifyC2Describe(isSecure) {
}
- bool handleGet(CivetServer *server, struct mg_connection *conn) {
- std::ifstream myfile(test_file_location_.c_str());
-
- if (myfile.is_open()) {
- std::stringstream buffer;
- buffer << myfile.rdbuf();
- std::string str = buffer.str();
- myfile.close();
- mg_printf(conn, "HTTP/1.1 200 OK\r\nContent-Type: "
- "text/plain\r\nContent-Length: %lu\r\nConnection:
close\r\n\r\n",
- str.length());
- mg_printf(conn, "%s", str.c_str());
- } else {
- mg_printf(conn, "HTTP/1.1 500 Internal Server Error\r\n");
- }
-
- return true;
+ virtual void runAssertions() {
+ assert(LogTestController::getInstance().contains("SchedulingAgent") ==
true);
}
- std::string test_file_location_;
- std::atomic<size_t> calls_;
};
-int main(int argc, char **argv) {
- mg_init_library(0);
- LogTestController::getInstance().setInfo<minifi::FlowController>();
- LogTestController::getInstance().setDebug<minifi::utils::HTTPClient>();
- LogTestController::getInstance().setDebug<minifi::c2::RESTSender>();
- LogTestController::getInstance().setTrace<minifi::c2::C2Agent>();
+class DescribeJstackHandler : public HeartbeatHandler {
+ public:
+ explicit DescribeJstackHandler(bool isSecure)
+ : HeartbeatHandler(isSecure) {
+ }
- const char *options[] = { "document_root", ".", "listening_ports", "0", 0 };
- std::vector<std::string> cpp_options;
- for (int i = 0; i < (sizeof(options) / sizeof(options[0]) - 1); i++) {
- cpp_options.push_back(options[i]);
+ virtual void handleHeartbeat(const rapidjson::Document& root, struct
mg_connection * conn) {
+ sendHeartbeatResponse("DESCRIBE", "jstack", "889398", conn);
}
- CivetServer server(cpp_options);
+ virtual void handleAcknowledge(const rapidjson::Document& root) {
+ assert(root.HasMember("Flowcontroller threadpool #0") == true);
+ }
- std::string port_str = std::to_string(server.getListeningPorts()[0]);
+};
- ConfigHandler h_ex;
- server.addHandler("/update", h_ex);
- std::string key_dir, test_file_location;
+int main(int argc, char **argv) {
+ std::string key_dir, test_file_location, url;
+ url = "http://localhost:0/api/heartbeat";
if (argc > 1) {
- h_ex.test_file_location_ = test_file_location = argv[1];
- key_dir = argv[2];
+ test_file_location = argv[1];
+ if (argc > 2) {
+ url = "https://localhost:0/api/heartbeat";
+ key_dir = argv[2];
+ }
}
+ bool isSecure = false;
+ if (url.find("https") != std::string::npos) {
+ isSecure = true;
+ }
- std::shared_ptr<minifi::Configure> configuration =
std::make_shared<minifi::Configure>();
-
- std::string c2_rest_url = "http://localhost:" + port_str + "/update";
-
- configuration->set("c2.rest.url", c2_rest_url);
- configuration->set("c2.agent.heartbeat.period", "1000");
-
- std::shared_ptr<core::Repository> test_repo =
std::make_shared<TestRepository>();
- std::shared_ptr<core::Repository> test_flow_repo =
std::make_shared<TestFlowRepository>();
-
- configuration->set(minifi::Configure::nifi_flow_configuration_file,
test_file_location);
-
- std::shared_ptr<minifi::io::StreamFactory> stream_factory =
minifi::io::StreamFactory::getInstance(configuration);
- std::shared_ptr<core::ContentRepository> content_repo =
std::make_shared<core::repository::VolatileContentRepository>();
- std::unique_ptr<core::FlowConfiguration> yaml_ptr =
std::unique_ptr<core::YamlConfiguration>(
- new core::YamlConfiguration(test_repo, test_repo, content_repo,
stream_factory, configuration, test_file_location));
- std::shared_ptr<TestRepository> repo =
std::static_pointer_cast<TestRepository>(test_repo);
-
- std::shared_ptr<minifi::FlowController> controller =
std::make_shared<minifi::FlowController>(test_repo, test_flow_repo,
configuration, std::move(yaml_ptr), content_repo, DEFAULT_ROOT_GROUP_NAME,
- true);
-
- core::YamlConfiguration yaml_config(test_repo, test_repo, content_repo,
stream_factory, configuration, test_file_location);
+ VerifyC2DescribeJstack harness(isSecure);
- std::unique_ptr<core::ProcessGroup> ptr =
yaml_config.getRoot(test_file_location);
- std::shared_ptr<core::ProcessGroup> pg =
std::shared_ptr<core::ProcessGroup>(ptr.get());
- ptr.release();
- auto start = std::chrono::system_clock::now();
+ harness.setKeyDir(key_dir);
- controller->load();
- controller->start();
- waitToVerifyProcessor();
+ DescribeJstackHandler responder(isSecure);
- controller->waitUnload(60000);
- auto then = std::chrono::system_clock::now();
+ harness.setUrl(url, &responder);
- auto milliseconds =
std::chrono::duration_cast<std::chrono::milliseconds>(then - start).count();
- std::string logs = LogTestController::getInstance().log_output.str();
- #ifndef WIN32
- assert(logs.find("SchedulingAgent") != std::string::npos);
- #endif
- LogTestController::getInstance().reset();
- assert(h_ex.calls_ <= (milliseconds / 1000) + 1);
+ harness.run(test_file_location);
- return 0;
}
Review comment:
The new C2JstackTest sometimes crashes (segfault) during UUID generation, in
`IdGenerator::generateWithUuidImpl` because `uuid_impl_` is null for some
reason. I don't think the root cause is in your changes but we need to address
this before merging.
The interesting part of the backtrace:
```
#4 0x0000555555dc4bf3 in
org::apache::nifi::minifi::utils::IdGenerator::generateWithUuidImpl
(this=0x5555566c5e70, mode=1, output=0x7ffff5720a40 "`\vr\365\377\177") at
/home/szaszm/nifi-minifi-cpp-2/libminifi/src/utils/Id.cpp:288
#5 0x0000555555dc4e6b in
org::apache::nifi::minifi::utils::IdGenerator::generate (this=0x5555566c5e70,
ident=...) at /home/szaszm/nifi-minifi-cpp-2/libminifi/src/utils/Id.cpp:332
#6 0x0000555555bf5fc9 in
org::apache::nifi::minifi::core::CoreComponent::CoreComponent
(this=0x7ffff5720de0, name="HTTPClient") at
/home/szaszm/nifi-minifi-cpp-2/libminifi/include/core/Core.h:166
#7 0x0000555555d02989 in
org::apache::nifi::minifi::core::Connectable::Connectable (this=0x7ffff5720de0,
name="HTTPClient") at
/home/szaszm/nifi-minifi-cpp-2/libminifi/src/core/Connectable.cpp:43
#8 0x0000555555ee28b2 in
org::apache::nifi::minifi::utils::HTTPClient::HTTPClient (this=0x7ffff5720d70,
url="https://localhost:41931/api/heartbeat",
ssl_context_service=std::shared_ptr<org::apache::nifi::minifi::controllers::SSLContextService>
(empty) = {...}) at
/home/szaszm/nifi-minifi-cpp-2/extensions/http-curl/client/HTTPClient.cpp:51
#9 0x0000555555edc383 in
org::apache::nifi::minifi::c2::RESTSender::sendPayload (this=0x5555568e5b40,
url="https://localhost:41931/api/heartbeat",
direction=org::apache::nifi::minifi::c2::TRANSMIT, payload=...,
outputConfig="{\n \"operation\": \"heartbeat\",\n \"agentInfo\":
{\n \"status\": {\n", ' ' <repeats 12 times>, "\"repositories\": {\n", '
' <repeats 16 times>, "\"ff\": {\n", ' ' <repeats 20 times>, "\"size\": 0,\n",
' ' <repeats 20 times>, "\"running\": false,\n "...) at
/home/szaszm/nifi-minifi-cpp-2/extensions/http-curl/protocols/RESTSender.cpp:106
#10 0x0000555555edbd61 in
org::apache::nifi::minifi::c2::RESTSender::consumePayload (this=0x5555568e5b40,
url="https://localhost:41931/api/heartbeat", payload=...,
direction=org::apache::nifi::minifi::c2::TRANSMIT, async=false)
at
/home/szaszm/nifi-minifi-cpp-2/extensions/http-curl/protocols/RESTSender.cpp:69
#11 0x0000555555edbeab in
org::apache::nifi::minifi::c2::RESTSender::consumePayload (this=0x5555568e5b40,
payload=..., direction=org::apache::nifi::minifi::c2::TRANSMIT, async=false)
at
/home/szaszm/nifi-minifi-cpp-2/extensions/http-curl/protocols/RESTSender.cpp:76
#12 0x0000555555c90ad2 in
org::apache::nifi::minifi::c2::C2Agent::performHeartBeat (this=0x5555568db8b0)
at /home/szaszm/nifi-minifi-cpp-2/libminifi/src/c2/C2Agent.cpp:318
#13 0x0000555555c8dcbc in
org::apache::nifi::minifi::c2::C2Agent::<lambda()>::operator()(void) const
(__closure=0x7ffff5721b80) at
/home/szaszm/nifi-minifi-cpp-2/libminifi/src/c2/C2Agent.cpp:100
#14 0x0000555555c96478 in
std::_Function_handler<org::apache::nifi::minifi::utils::TaskRescheduleInfo(),
org::apache::nifi::minifi::c2::C2Agent::C2Agent(const
std::shared_ptr<org::apache::nifi::minifi::core::controller::ControllerServiceProvider>&,
const std::shared_ptr<org::apache::nifi::minifi::state::StateMonitor>&, const
std::shared_ptr<org::apache::nifi::minifi::Configure>&,
org::apache::nifi::minifi::utils::ThreadPool<org::apache::nifi::minifi::utils::TaskRescheduleInfo>&)::<lambda()>
>::_M_invoke(const std::_Any_data &) (__functor=...) at
/usr/include/c++/7/bits/std_function.h:302
#15 0x0000555555ca6fc6 in
std::function<org::apache::nifi::minifi::utils::TaskRescheduleInfo
()>::operator()() const (this=0x7ffff5721b80) at
/usr/include/c++/7/bits/std_function.h:706
#16 0x0000555555ca6c13 in
org::apache::nifi::minifi::utils::Worker<org::apache::nifi::minifi::utils::TaskRescheduleInfo>::run
(this=0x7ffff5721b50) at
/home/szaszm/nifi-minifi-cpp-2/libminifi/include/utils/ThreadPool.h:97
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services