From 3fb7e5378db1055352d500a02ee7a943be92617e Mon Sep 17 00:00:00 2001 From: Jure Bajic Date: Thu, 17 Feb 2022 10:27:24 +0100 Subject: [PATCH] Add websocket port argument (#355) --- src/memgraph.cpp | 10 +++++++++- tests/e2e/websocket/common.hpp | 21 +++++++++++---------- tests/e2e/websocket/websocket.cpp | 4 +++- tests/e2e/websocket/websocket_ssl.cpp | 4 +++- tests/e2e/websocket/workloads.yaml | 7 +++++-- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/memgraph.cpp b/src/memgraph.cpp index dcd714614..a84ffba11 100644 --- a/src/memgraph.cpp +++ b/src/memgraph.cpp @@ -132,8 +132,15 @@ std::optional StringToEnum(const auto &value, const auto &mappings) { // Bolt server flags. DEFINE_string(bolt_address, "0.0.0.0", "IP address on which the Bolt server should listen."); +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +DEFINE_string(monitoring_address, "0.0.0.0", + "IP address on which the websocket server for Memgraph monitoring should listen."); DEFINE_VALIDATED_int32(bolt_port, 7687, "Port on which the Bolt server should listen.", FLAG_IN_RANGE(0, std::numeric_limits::max())); +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) +DEFINE_VALIDATED_int32(monitoring_port, 7444, + "Port on which the websocket server for Memgraph monitoring should listen.", + FLAG_IN_RANGE(0, std::numeric_limits::max())); DEFINE_VALIDATED_int32(bolt_num_workers, std::max(std::thread::hardware_concurrency(), 1U), "Number of workers used by the Bolt server. By default, this will be the " "number of processing units available on the machine.", @@ -1216,7 +1223,8 @@ int main(int argc, char **argv) { } communication::websocket::SafeAuth websocket_auth{&auth}; - communication::websocket::Server websocket_server{{"0.0.0.0", 7444}, &context, websocket_auth}; + communication::websocket::Server websocket_server{ + {FLAGS_monitoring_address, static_cast(FLAGS_monitoring_port)}, &context, websocket_auth}; AddLoggerSink(websocket_server.GetLoggingSink()); // Handler for regular termination signals diff --git a/tests/e2e/websocket/common.hpp b/tests/e2e/websocket/common.hpp index c6a448ade..bcdeb0559 100644 --- a/tests/e2e/websocket/common.hpp +++ b/tests/e2e/websocket/common.hpp @@ -238,10 +238,10 @@ inline void AssertLogMessage(const std::string &log_message) { } template -void TestWebsocketWithoutAnyUsers(std::unique_ptr &mg_client) { +void TestWebsocketWithoutAnyUsers(std::unique_ptr &mg_client, const std::string_view monitoring_port) { spdlog::info("Starting websocket connection without any users."); auto websocket_client = TWebsocketClient(); - websocket_client.Connect("127.0.0.1", "7444"); + websocket_client.Connect("127.0.0.1", monitoring_port); RunQueries(mg_client); std::this_thread::sleep_for(std::chrono::seconds(1)); @@ -257,12 +257,12 @@ void TestWebsocketWithoutAnyUsers(std::unique_ptr &mg_client) { } template -void TestWebsocketWithAuthentication(std::unique_ptr &mg_client) { +void TestWebsocketWithAuthentication(std::unique_ptr &mg_client, const std::string_view monitoring_port) { spdlog::info("Starting websocket connection with users."); AddUser(mg_client); std::this_thread::sleep_for(std::chrono::seconds(1)); auto websocket_client = TWebsocketClient({"test", "testing"}); - websocket_client.Connect("127.0.0.1", "7444"); + websocket_client.Connect("127.0.0.1", monitoring_port); RunQueries(mg_client); std::this_thread::sleep_for(std::chrono::seconds(1)); @@ -279,11 +279,12 @@ void TestWebsocketWithAuthentication(std::unique_ptr &mg_client) { } template -void TestWebsocketWithoutBeingAuthorized(std::unique_ptr &mg_client) { +void TestWebsocketWithoutBeingAuthorized(std::unique_ptr &mg_client, + const std::string_view monitoring_port) { spdlog::info("Starting websocket connection with users but without being authenticated."); std::this_thread::sleep_for(std::chrono::seconds(1)); auto websocket_client = TWebsocketClient({"wrong", "credentials"}); - websocket_client.Connect("127.0.0.1", "7444"); + websocket_client.Connect("127.0.0.1", monitoring_port); RunQueries(mg_client); std::this_thread::sleep_for(std::chrono::seconds(1)); @@ -302,8 +303,8 @@ void TestWebsocketWithoutBeingAuthorized(std::unique_ptr &mg_client) } template -void RunTestCases(std::unique_ptr &mg_client) { - TestWebsocketWithoutAnyUsers(mg_client); - TestWebsocketWithAuthentication(mg_client); - TestWebsocketWithoutBeingAuthorized(mg_client); +void RunTestCases(std::unique_ptr &mg_client, const std::string_view monitoring_port) { + TestWebsocketWithoutAnyUsers(mg_client, monitoring_port); + TestWebsocketWithAuthentication(mg_client, monitoring_port); + TestWebsocketWithoutBeingAuthorized(mg_client, monitoring_port); } diff --git a/tests/e2e/websocket/websocket.cpp b/tests/e2e/websocket/websocket.cpp index 1dfe21ad5..7321e5039 100644 --- a/tests/e2e/websocket/websocket.cpp +++ b/tests/e2e/websocket/websocket.cpp @@ -24,6 +24,7 @@ #include "utils/logging.hpp" DEFINE_uint64(bolt_port, 7687, "Bolt port"); +DEFINE_uint64(monitoring_port, 7444, "Monitoring port"); class WebsocketClient { public: @@ -57,12 +58,13 @@ int main(int argc, char **argv) { google::SetUsageMessage("Memgraph E2E websocket!"); gflags::ParseCommandLineFlags(&argc, &argv, true); MG_ASSERT(FLAGS_bolt_port != 0); + MG_ASSERT(FLAGS_monitoring_port != 0); logging::RedirectToStderr(); mg::Client::Init(); auto mg_client = GetBoltClient(static_cast(FLAGS_bolt_port), false); - RunTestCases(mg_client); + RunTestCases(mg_client, std::to_string(FLAGS_monitoring_port)); return 0; } diff --git a/tests/e2e/websocket/websocket_ssl.cpp b/tests/e2e/websocket/websocket_ssl.cpp index 28c4826a7..a9dafbfea 100644 --- a/tests/e2e/websocket/websocket_ssl.cpp +++ b/tests/e2e/websocket/websocket_ssl.cpp @@ -30,6 +30,7 @@ #include "utils/logging.hpp" DEFINE_uint64(bolt_port, 7687, "Bolt port"); +DEFINE_uint64(monitoring_port, 7444, "Monitoring port"); class WebsocketSSLClient { public: @@ -65,12 +66,13 @@ int main(int argc, char **argv) { google::SetUsageMessage("Memgraph E2E websocket SSL!"); gflags::ParseCommandLineFlags(&argc, &argv, true); MG_ASSERT(FLAGS_bolt_port != 0); + MG_ASSERT(FLAGS_monitoring_port != 0); logging::RedirectToStderr(); auto mg_client = GetBoltClient(static_cast(FLAGS_bolt_port), true); mg::Client::Init(); - RunTestCases(mg_client); + RunTestCases(mg_client, std::to_string(FLAGS_monitoring_port)); return 0; } diff --git a/tests/e2e/websocket/workloads.yaml b/tests/e2e/websocket/workloads.yaml index 883b366be..2f4f31725 100644 --- a/tests/e2e/websocket/workloads.yaml +++ b/tests/e2e/websocket/workloads.yaml @@ -1,6 +1,7 @@ cert_file: &cert_file "$PROJECT_DIR/tests/e2e/websocket/memgraph-selfsigned.crt" key_file: &key_file "$PROJECT_DIR/tests/e2e/websocket/memgraph-selfsigned.key" bolt_port: &bolt_port "7687" +monitoring_port: &monitoring_port "7444" template_cluster: &template_cluster cluster: websocket: @@ -13,6 +14,8 @@ template_cluster_ssl: &template_cluster_ssl [ "--bolt-port", *bolt_port, + "--monitoring-port", + *monitoring_port, "--log-level=TRACE", "--bolt-cert-file", *cert_file, @@ -26,9 +29,9 @@ template_cluster_ssl: &template_cluster_ssl workloads: - name: "Websocket" binary: "tests/e2e/websocket/memgraph__e2e__websocket" - args: ["--bolt-port", *bolt_port] + args: ["--bolt-port", *bolt_port, "--monitoring-port", *monitoring_port] <<: *template_cluster - name: "Websocket SSL" binary: "tests/e2e/websocket/memgraph__e2e__websocket_ssl" - args: ["--bolt-port", *bolt_port] + args: ["--bolt-port", *bolt_port, "--monitoring-port", *monitoring_port] <<: *template_cluster_ssl