From 99f45d1ee520ceb808a4191ffbd3e7c1928c2412 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 15 Jul 2020 20:04:56 +0000 Subject: [PATCH 001/114] Adding a multiple path test to confirm that expected paths are hit Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 61 +++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index f6d67efe2..64bf0832e 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -1,5 +1,4 @@ #include - #include "external/envoy/source/common/common/random_generator.h" #include "external/envoy/source/common/http/header_map_impl.h" #include "external/envoy/source/common/network/utility.h" @@ -57,14 +56,22 @@ class BenchmarkClientHttpTest : public Test { }; } - void testBasicFunctionality(const uint64_t max_pending, const uint64_t connection_limit, - const uint64_t amount_of_request) { + void testBasicFunctionality( + const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, + const std::vector>& header_expectations = + std::vector>()) { if (client_ == nullptr) { setupBenchmarkClient(); cluster_info().resetResourceManager(connection_limit, max_pending, 1024, 0, 1024); } - - EXPECT_CALL(stream_encoder_, encodeHeaders(_, _)).Times(AtLeast(1)); + // this is where we store the properties of headers that are passed to the stream encoder. We + // verify later that these match expected headers. + std::vector> called_headers; + ON_CALL(stream_encoder_, encodeHeaders(_, _)) + .WillByDefault(WithArgs<0>( + ([this, &called_headers](const Envoy::Http::RequestHeaderMap& specific_request) { + called_headers.push_back(getTestRecordedProperties(specific_request)); + }))); EXPECT_CALL(pool_, newStream(_, _)) .WillRepeatedly(Invoke([&](Envoy::Http::ResponseDecoder& decoder, @@ -121,6 +128,16 @@ class BenchmarkClientHttpTest : public Test { decoders_.clear(); dispatcher_->run(Envoy::Event::Dispatcher::RunType::Block); EXPECT_EQ(0, inflight_response_count); + // If we have no expectations, then we don't test. + if (header_expectations.size() != 0) { + EXPECT_THAT(header_expectations, UnorderedElementsAreArray(called_headers)); + } + } + absl::flat_hash_map + getTestRecordedProperties(const Envoy::Http::RequestHeaderMap& header) { + absl::flat_hash_map properties_map; + properties_map["uri"] = std::string(header.getPathValue()); + return properties_map; } void setupBenchmarkClient() { @@ -279,5 +296,37 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { testBasicFunctionality(1, 1, 1); EXPECT_EQ(1, getCounter("http_2xx")); } - +TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { + std::vector requests_vector; + auto header1 = + std::initializer_list>({{":scheme", "http"}, + {":method", "GET"}, + {":path", "/a"}, + {":host", "localhost"}, + {"Content-Length", "1313"}}); + auto header2 = + std::initializer_list>({{":scheme", "http"}, + {":method", "GET"}, + {":path", "/b"}, + {":host", "localhost"}, + {"Content-Length", "1313"}}); + requests_vector.push_back(std::make_shared(header1)); + requests_vector.push_back(std::make_shared(header2)); + std::vector::iterator request_iterator; + request_iterator = requests_vector.begin(); + request_generator_ = [&]() { + auto item = *request_iterator; + request_iterator++; + return std::make_unique(item); + }; + std::vector> expected_requests_vector; + expected_requests_vector.push_back( + getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(header1))); + expected_requests_vector.push_back( + getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(header2))); + + EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); + testBasicFunctionality(1, 1, 2, expected_requests_vector); + EXPECT_EQ(2, getCounter("http_2xx")); +} } // namespace Nighthawk From 075a4cfc8b637585e8b3628744b86699adaea69d Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 17 Jul 2020 19:19:20 +0000 Subject: [PATCH 002/114] fixing asan problems Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 64bf0832e..23d1bc57b 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -1,4 +1,5 @@ #include + #include "external/envoy/source/common/common/random_generator.h" #include "external/envoy/source/common/http/header_map_impl.h" #include "external/envoy/source/common/network/utility.h" @@ -67,11 +68,13 @@ class BenchmarkClientHttpTest : public Test { // this is where we store the properties of headers that are passed to the stream encoder. We // verify later that these match expected headers. std::vector> called_headers; + EXPECT_CALL(stream_encoder_, encodeHeaders(_, _)).Times(AtLeast(1)); ON_CALL(stream_encoder_, encodeHeaders(_, _)) .WillByDefault(WithArgs<0>( ([this, &called_headers](const Envoy::Http::RequestHeaderMap& specific_request) { called_headers.push_back(getTestRecordedProperties(specific_request)); - }))); + } + ))); EXPECT_CALL(pool_, newStream(_, _)) .WillRepeatedly(Invoke([&](Envoy::Http::ResponseDecoder& decoder, @@ -133,6 +136,7 @@ class BenchmarkClientHttpTest : public Test { EXPECT_THAT(header_expectations, UnorderedElementsAreArray(called_headers)); } } + absl::flat_hash_map getTestRecordedProperties(const Envoy::Http::RequestHeaderMap& header) { absl::flat_hash_map properties_map; @@ -298,18 +302,18 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { } TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { std::vector requests_vector; - auto header1 = - std::initializer_list>({{":scheme", "http"}, - {":method", "GET"}, - {":path", "/a"}, - {":host", "localhost"}, - {"Content-Length", "1313"}}); - auto header2 = - std::initializer_list>({{":scheme", "http"}, - {":method", "GET"}, - {":path", "/b"}, - {":host", "localhost"}, - {"Content-Length", "1313"}}); + std::initializer_list> header1{{":scheme", "http"}, + {":method", "GET"}, + {":path", "/a"}, + {":host", "localhost"}, + {"Content-Length", "1313"}}; + std::initializer_list> header2{{":scheme", "http"}, + {":method", "GET"}, + {":path", "/b"}, + {":host", "localhost"}, + {"Content-Length", "1313"}}; + // HeaderMapPtr sharedHeader1 = std::make_shared(header1); + // HeaderMapPtr sharedHeader2 = std::make_shared(header2); requests_vector.push_back(std::make_shared(header1)); requests_vector.push_back(std::make_shared(header2)); std::vector::iterator request_iterator; From ecbf4073ea7f5378f87cbf2a0b19f7ed72f75d99 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 17 Jul 2020 19:52:29 +0000 Subject: [PATCH 003/114] Fix Format Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- benchmarks/envoy_proxy.py | 28 +++++++++---------- benchmarks/test/test_discovery.py | 5 ++-- test/benchmark_http_client_test.cc | 3 +- test/integration/integration_test_fixtures.py | 19 +++++++------ test/integration/nighthawk_test_server.py | 23 ++++++++------- .../integration/test_connection_management.py | 13 ++++----- test/integration/test_integration_basics.py | 21 +++++++------- test/integration/test_remote_execution.py | 5 ++-- tools/format_python_tools.py | 12 +++++--- tools/gen_compilation_database.py | 17 ++++++----- tools/update_cli_readme_documentation.py | 19 ++++++------- 11 files changed, 82 insertions(+), 83 deletions(-) diff --git a/benchmarks/envoy_proxy.py b/benchmarks/envoy_proxy.py index 9e7fd1909..06ce8bc08 100644 --- a/benchmarks/envoy_proxy.py +++ b/benchmarks/envoy_proxy.py @@ -39,13 +39,12 @@ def __init__(self, config_template_path, server_ip, ip_version, parameters=dict( tag: String. Supply this to get recognizeable output locations (optional). """ # If no explicit envoy path is passed, we'll use nighthawk_test_server. - super(EnvoyProxyServer, self).__init__( - os.getenv("ENVOY_PATH", "nighthawk_test_server"), - config_template_path, - server_ip, - ip_version, - parameters=parameters, - tag=tag) + super(EnvoyProxyServer, self).__init__(os.getenv("ENVOY_PATH", "nighthawk_test_server"), + config_template_path, + server_ip, + ip_version, + parameters=parameters, + tag=tag) self.docker_image = os.getenv("ENVOY_DOCKER_IMAGE_TO_TEST", "") @@ -83,15 +82,14 @@ def setUp(self): # TODO(oschaaf): how should this interact with multiple backends? self.parameters["proxy_ip"] = self.test_server.server_ip self.parameters["server_port"] = self.test_server.server_port - proxy_server = EnvoyProxyServer( - self._proxy_config, - self.server_ip, - self.ip_version, - parameters=self.parameters, - tag=self.tag) + proxy_server = EnvoyProxyServer(self._proxy_config, + self.server_ip, + self.ip_version, + parameters=self.parameters, + tag=self.tag) assert (proxy_server.start()) - logging.info("envoy proxy listening at {ip}:{port}".format( - ip=proxy_server.server_ip, port=proxy_server.server_port)) + logging.info("envoy proxy listening at {ip}:{port}".format(ip=proxy_server.server_ip, + port=proxy_server.server_port)) self.proxy_server = proxy_server def tearDown(self): diff --git a/benchmarks/test/test_discovery.py b/benchmarks/test/test_discovery.py index 09f5e1636..cf2a7ea96 100644 --- a/benchmarks/test/test_discovery.py +++ b/benchmarks/test/test_discovery.py @@ -76,9 +76,8 @@ def _run_benchmark(fixture, with open(os.path.join(fixture.test_server.tmpdir, "proxy_version.txt"), "w") as f: f.write(fixture.proxy_server.getCliVersionString()) r = runfiles.Create() - copyfile( - r.Rlocation("nighthawk/benchmarks/test/templates/simple_plot.html"), - os.path.join(fixture.test_server.tmpdir, "simple_plot.html")) + copyfile(r.Rlocation("nighthawk/benchmarks/test/templates/simple_plot.html"), + os.path.join(fixture.test_server.tmpdir, "simple_plot.html")) # Test via injected Envoy diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 23d1bc57b..37ccd0d83 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -73,8 +73,7 @@ class BenchmarkClientHttpTest : public Test { .WillByDefault(WithArgs<0>( ([this, &called_headers](const Envoy::Http::RequestHeaderMap& specific_request) { called_headers.push_back(getTestRecordedProperties(specific_request)); - } - ))); + }))); EXPECT_CALL(pool_, newStream(_, _)) .WillRepeatedly(Invoke([&](Envoy::Http::ResponseDecoder& decoder, diff --git a/test/integration/integration_test_fixtures.py b/test/integration/integration_test_fixtures.py index 2e73ce908..9b3cb4090 100644 --- a/test/integration/integration_test_fixtures.py +++ b/test/integration/integration_test_fixtures.py @@ -126,13 +126,12 @@ def tearDown(self): def _tryStartTestServers(self): for i in range(self._backend_count): - test_server = NighthawkTestServer( - self._nighthawk_test_server_path, - self._nighthawk_test_config_path, - self.server_ip, - self.ip_version, - parameters=self.parameters, - tag=self.tag) + test_server = NighthawkTestServer(self._nighthawk_test_server_path, + self._nighthawk_test_config_path, + self.server_ip, + self.ip_version, + parameters=self.parameters, + tag=self.tag) if not test_server.start(): return False self._test_servers.append(test_server) @@ -263,8 +262,10 @@ def transformNighthawkJson(self, json, format="human"): args = ["docker", "run", "--rm", "-i", os.getenv("NH_DOCKER_IMAGE")] args = args + [self._nighthawk_output_transform_path, "--output-format", format] logging.info("Nighthawk output transform popen() args: %s" % args) - client_process = subprocess.Popen( - args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + client_process = subprocess.Popen(args, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) logging.info("Nighthawk client popen() args: [%s]" % args) stdout, stderr = client_process.communicate(input=json.encode()) logs = stderr.decode('utf-8') diff --git a/test/integration/nighthawk_test_server.py b/test/integration/nighthawk_test_server.py index 4f3ddb202..a047da9d5 100644 --- a/test/integration/nighthawk_test_server.py +++ b/test/integration/nighthawk_test_server.py @@ -88,19 +88,18 @@ def _prepareForExecution(self): Path(self.tmpdir).mkdir(parents=True, exist_ok=True) - with tempfile.NamedTemporaryFile( - mode="w", delete=False, suffix=".config.yaml", dir=self.tmpdir) as tmp: + with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".config.yaml", + dir=self.tmpdir) as tmp: self._parameterized_config_path = tmp.name - yaml.safe_dump( - data, - tmp, - default_flow_style=False, - explicit_start=True, - allow_unicode=True, - encoding='utf-8') - - with tempfile.NamedTemporaryFile( - mode="w", delete=False, suffix=".adminport", dir=self.tmpdir) as tmp: + yaml.safe_dump(data, + tmp, + default_flow_style=False, + explicit_start=True, + allow_unicode=True, + encoding='utf-8') + + with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".adminport", + dir=self.tmpdir) as tmp: self._admin_address_path = tmp.name def serverThreadRunner(self): diff --git a/test/integration/test_connection_management.py b/test/integration/test_connection_management.py index 9f1fd5459..bec1acc4e 100644 --- a/test/integration/test_connection_management.py +++ b/test/integration/test_connection_management.py @@ -61,13 +61,12 @@ def test_http_h1_connection_management_with_queue_5(http_test_server_fixture): def connection_management_test_request_per_connection(fixture, requests_per_connection, use_h2): max_requests_per_conn = 5 - counters = run_with_number_of_connections( - fixture, - 1, - max_pending_requests=1, - requests_per_connection=max_requests_per_conn, - run_test_expectation=False, - h2=use_h2) + counters = run_with_number_of_connections(fixture, + 1, + max_pending_requests=1, + requests_per_connection=max_requests_per_conn, + run_test_expectation=False, + h2=use_h2) requests = counters["upstream_rq_total"] assertCounterBetweenInclusive(counters, "upstream_cx_total", (requests / max_requests_per_conn), (requests / max_requests_per_conn) + 1) diff --git a/test/integration/test_integration_basics.py b/test/integration/test_integration_basics.py index 8cc7e2fbd..1bbf6ef81 100644 --- a/test/integration/test_integration_basics.py +++ b/test/integration/test_integration_basics.py @@ -10,9 +10,11 @@ from threading import Thread from test.integration.common import IpVersion -from test.integration.integration_test_fixtures import ( - http_test_server_fixture, https_test_server_fixture, multi_http_test_server_fixture, - multi_https_test_server_fixture, server_config) +from test.integration.integration_test_fixtures import (http_test_server_fixture, + https_test_server_fixture, + multi_http_test_server_fixture, + multi_https_test_server_fixture, + server_config) from test.integration.utility import * # TODO(oschaaf): we mostly verify stats observed from the client-side. Add expectations @@ -74,8 +76,8 @@ def mini_stress_test(fixture, args): else: assertGreaterEqual(int(global_histograms["sequencer.blocking"]["count"]), 1) - assertGreaterEqual( - int(global_histograms["benchmark_http_client.request_to_response"]["count"]), 1) + assertGreaterEqual(int(global_histograms["benchmark_http_client.request_to_response"]["count"]), + 1) return counters @@ -674,11 +676,10 @@ def test_http_request_release_timing(http_test_server_fixture, qps_parameterizat global_histograms = http_test_server_fixture.getNighthawkGlobalHistogramsbyIdFromJson( parsed_json) counters = http_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json) - assertEqual( - int(global_histograms["benchmark_http_client.request_to_response"]["count"]), - total_requests) - assertEqual( - int(global_histograms["benchmark_http_client.queue_to_connect"]["count"]), total_requests) + assertEqual(int(global_histograms["benchmark_http_client.request_to_response"]["count"]), + total_requests) + assertEqual(int(global_histograms["benchmark_http_client.queue_to_connect"]["count"]), + total_requests) assertCounterEqual(counters, "benchmark.http_2xx", (total_requests)) diff --git a/test/integration/test_remote_execution.py b/test/integration/test_remote_execution.py index b4937a9c7..d7638fce8 100644 --- a/test/integration/test_remote_execution.py +++ b/test/integration/test_remote_execution.py @@ -42,6 +42,7 @@ def test_bad_service_uri(http_test_server_fixture): Test configuring a bad service uri. """ args = [http_test_server_fixture.getTestServerRootUri(), "--nighthawk-service", "a:-1"] - parsed_json, err = http_test_server_fixture.runNighthawkClient( - args, expect_failure=True, as_json=False) + parsed_json, err = http_test_server_fixture.runNighthawkClient(args, + expect_failure=True, + as_json=False) assert "Bad service uri" in err diff --git a/tools/format_python_tools.py b/tools/format_python_tools.py index e81cb11a6..6f40c7501 100755 --- a/tools/format_python_tools.py +++ b/tools/format_python_tools.py @@ -37,8 +37,10 @@ def validateFormat(fix=False): failed_update_files = set() successful_update_files = set() for python_file in collectFiles(): - reformatted_source, encoding, changed = FormatFile( - python_file, style_config='.style.yapf', in_place=fix, print_diff=not fix) + reformatted_source, encoding, changed = FormatFile(python_file, + style_config='.style.yapf', + in_place=fix, + print_diff=not fix) if not fix: fixes_required = True if changed else fixes_required if reformatted_source: @@ -64,8 +66,10 @@ def displayFixResults(successful_files, failed_files): if __name__ == '__main__': parser = argparse.ArgumentParser(description='Tool to format python files.') - parser.add_argument( - 'action', choices=['check', 'fix'], default='check', help='Fix invalid syntax in files.') + parser.add_argument('action', + choices=['check', 'fix'], + default='check', + help='Fix invalid syntax in files.') args = parser.parse_args() is_valid = validateFormat(args.action == 'fix') sys.exit(0 if is_valid else 1) diff --git a/tools/gen_compilation_database.py b/tools/gen_compilation_database.py index feba85957..73ec0ba57 100755 --- a/tools/gen_compilation_database.py +++ b/tools/gen_compilation_database.py @@ -39,8 +39,8 @@ def generateCompilationDatabase(args): compdb = [] for compdb_file in Path(execroot).glob("**/*.compile_commands.json"): - compdb.extend( - json.loads("[" + compdb_file.read_text().replace("__EXEC_ROOT__", execroot) + "]")) + compdb.extend(json.loads("[" + compdb_file.read_text().replace("__EXEC_ROOT__", execroot) + + "]")) return compdb @@ -103,12 +103,11 @@ def fixCompilationDatabase(args, db): parser.add_argument('--include_headers', action='store_true') parser.add_argument('--vscode', action='store_true') # @@@ - parser.add_argument( - 'bazel_targets', - nargs='*', - default=[ - "//source/...", "//test:*", "//test/integration/...", "//test/client/...", - "//test/server/...", "//tools/..." - ]) + parser.add_argument('bazel_targets', + nargs='*', + default=[ + "//source/...", "//test:*", "//test/integration/...", "//test/client/...", + "//test/server/...", "//tools/..." + ]) args = parser.parse_args() fixCompilationDatabase(args, generateCompilationDatabase(args)) diff --git a/tools/update_cli_readme_documentation.py b/tools/update_cli_readme_documentation.py index 4400e4440..2cb09f683 100644 --- a/tools/update_cli_readme_documentation.py +++ b/tools/update_cli_readme_documentation.py @@ -20,12 +20,11 @@ "--readme", required=True, help="Relative path to the target documentation file, for example: \"README.md\"") - parser.add_argument( - "--mode", - default="check", - required=True, - choices={"check", "fix"}, - help="Either \"check\" or \"fix\"") + parser.add_argument("--mode", + default="check", + required=True, + choices={"check", "fix"}, + help="Either \"check\" or \"fix\"") args = parser.parse_args() logging.getLogger().setLevel(logging.INFO) @@ -49,13 +48,13 @@ if replaced != original_contents: if args.mode == "check": - logging.info( - "CLI documentation in /%s needs to be updated for %s" % (args.readme, args.binary)) + logging.info("CLI documentation in /%s needs to be updated for %s" % + (args.readme, args.binary)) sys.exit(-1) elif args.mode == "fix": with target_path.open("w", encoding="utf-8") as f: - logging.error( - "CLI documentation in /%s needs to be updated for %s" % (args.readme, args.binary)) + logging.error("CLI documentation in /%s needs to be updated for %s" % + (args.readme, args.binary)) f.write("%s" % replaced) logging.info("Done") From 8fb11b62d725720e7a19618c3fa6d25259f004a7 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 17 Jul 2020 20:20:25 +0000 Subject: [PATCH 004/114] Removeing unused comments Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 37ccd0d83..8c00b58cd 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -311,8 +311,6 @@ TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { {":path", "/b"}, {":host", "localhost"}, {"Content-Length", "1313"}}; - // HeaderMapPtr sharedHeader1 = std::make_shared(header1); - // HeaderMapPtr sharedHeader2 = std::make_shared(header2); requests_vector.push_back(std::make_shared(header1)); requests_vector.push_back(std::make_shared(header2)); std::vector::iterator request_iterator; From 032dbba14c6026b34f6ea302868e46ff6cac2577 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 17 Jul 2020 20:30:36 +0000 Subject: [PATCH 005/114] Removing unnecessary invoke calls for cleanliness Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 8c00b58cd..22420843e 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -41,14 +41,13 @@ class BenchmarkClientHttpTest : public Test { auto& tracer = static_cast(*http_tracer_); EXPECT_CALL(tracer, startSpan_(_, _, _, _)) - .WillRepeatedly( - Invoke([&](const Envoy::Tracing::Config& config, const Envoy::Http::HeaderMap&, - const Envoy::StreamInfo::StreamInfo&, - const Envoy::Tracing::Decision) -> Envoy::Tracing::Span* { - EXPECT_EQ(Envoy::Tracing::OperationName::Egress, config.operationName()); - auto* span = new NiceMock(); - return span; - })); + .WillRepeatedly([&](const Envoy::Tracing::Config& config, const Envoy::Http::HeaderMap&, + const Envoy::StreamInfo::StreamInfo&, + const Envoy::Tracing::Decision) -> Envoy::Tracing::Span* { + EXPECT_EQ(Envoy::Tracing::OperationName::Egress, config.operationName()); + auto* span = new NiceMock(); + return span; + }); request_generator_ = []() { auto header = std::make_shared( std::initializer_list>( @@ -76,15 +75,15 @@ class BenchmarkClientHttpTest : public Test { }))); EXPECT_CALL(pool_, newStream(_, _)) - .WillRepeatedly(Invoke([&](Envoy::Http::ResponseDecoder& decoder, - Envoy::Http::ConnectionPool::Callbacks& callbacks) - -> Envoy::Http::ConnectionPool::Cancellable* { + .WillRepeatedly([&](Envoy::Http::ResponseDecoder& decoder, + Envoy::Http::ConnectionPool::Callbacks& callbacks) + -> Envoy::Http::ConnectionPool::Cancellable* { decoders_.push_back(&decoder); NiceMock stream_info; callbacks.onPoolReady(stream_encoder_, Envoy::Upstream::HostDescriptionConstSharedPtr{}, stream_info); return nullptr; - })); + }); client_->setMaxPendingRequests(max_pending); client_->setConnectionLimit(connection_limit); From 6185edbe8c501e487f12c8fc07863b4c8b4be8b4 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 20 Jul 2020 16:16:45 +0000 Subject: [PATCH 006/114] Refactoring test to take in request generator parameter instead of using a global request generator. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 44 ++++++++++++++++-------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 22420843e..2f2ba4630 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -48,20 +48,23 @@ class BenchmarkClientHttpTest : public Test { auto* span = new NiceMock(); return span; }); - request_generator_ = []() { + } + RequestGenerator getDefaultRequestGenerator() { + RequestGenerator request_generator = []() { auto header = std::make_shared( std::initializer_list>( {{":scheme", "http"}, {":method", "GET"}, {":path", "/"}, {":host", "localhost"}})); return std::make_unique(header); }; + return request_generator; } - void testBasicFunctionality( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, + RequestGenerator request_generator, const std::vector>& header_expectations = std::vector>()) { if (client_ == nullptr) { - setupBenchmarkClient(); + setupBenchmarkClient(request_generator); cluster_info().resetResourceManager(connection_limit, max_pending, 1024, 0, 1024); } // this is where we store the properties of headers that are passed to the stream encoder. We @@ -142,12 +145,12 @@ class BenchmarkClientHttpTest : public Test { return properties_map; } - void setupBenchmarkClient() { + void setupBenchmarkClient(RequestGenerator request_generator) { client_ = std::make_unique( *api_, *dispatcher_, store_, std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), false, cluster_manager_, http_tracer_, "benchmark", - request_generator_, true); + request_generator, true); } uint64_t getCounter(absl::string_view name) { @@ -179,41 +182,40 @@ class BenchmarkClientHttpTest : public Test { Envoy::Upstream::ClusterInfoConstSharedPtr cluster_info_; Envoy::Tracing::HttpTracerSharedPtr http_tracer_; std::string response_code_; - RequestGenerator request_generator_; }; TEST_F(BenchmarkClientHttpTest, BasicTestH1200) { response_code_ = "200"; - testBasicFunctionality(2, 3, 10); + testBasicFunctionality(2, 3, 10, getDefaultRequestGenerator()); EXPECT_EQ(5, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1300) { response_code_ = "300"; - testBasicFunctionality(0, 11, 10); + testBasicFunctionality(0, 11, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, getCounter("http_3xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1404) { response_code_ = "404"; - testBasicFunctionality(0, 1, 10); + testBasicFunctionality(0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_4xx")); } TEST_F(BenchmarkClientHttpTest, WeirdStatus) { response_code_ = "601"; - testBasicFunctionality(0, 1, 10); + testBasicFunctionality(0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_xxx")); } TEST_F(BenchmarkClientHttpTest, EnableLatencyMeasurement) { - setupBenchmarkClient(); + setupBenchmarkClient(getDefaultRequestGenerator()); EXPECT_EQ(false, client_->shouldMeasureLatencies()); - testBasicFunctionality(10, 1, 10); + testBasicFunctionality(10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.request_to_response"]->count()); client_->setShouldMeasureLatencies(true); - testBasicFunctionality(10, 1, 10); + testBasicFunctionality(10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.request_to_response"]->count()); } @@ -224,7 +226,7 @@ TEST_F(BenchmarkClientHttpTest, StatusTrackingInOnComplete) { *api_, *dispatcher_, *store, std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), false, cluster_manager_, http_tracer_, "foo", - request_generator_, true); + getDefaultRequestGenerator(), true); Envoy::Http::ResponseHeaderMapPtr header = Envoy::Http::ResponseHeaderMapImpl::create(); header->setStatus(1); @@ -256,7 +258,7 @@ TEST_F(BenchmarkClientHttpTest, StatusTrackingInOnComplete) { } TEST_F(BenchmarkClientHttpTest, PoolFailures) { - setupBenchmarkClient(); + setupBenchmarkClient(getDefaultRequestGenerator()); client_->onPoolFailure(Envoy::Http::ConnectionPool::PoolFailureReason::LocalConnectionFailure); client_->onPoolFailure(Envoy::Http::ConnectionPool::PoolFailureReason::RemoteConnectionFailure); client_->onPoolFailure(Envoy::Http::ConnectionPool::PoolFailureReason::Overflow); @@ -266,7 +268,7 @@ TEST_F(BenchmarkClientHttpTest, PoolFailures) { } TEST_F(BenchmarkClientHttpTest, RequestMethodPost) { - request_generator_ = []() { + RequestGenerator request_generator = []() { auto header = std::make_shared( std::initializer_list>({{":scheme", "http"}, {":method", "POST"}, @@ -279,12 +281,12 @@ TEST_F(BenchmarkClientHttpTest, RequestMethodPost) { }; EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(1); - testBasicFunctionality(1, 1, 1); + testBasicFunctionality(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, BadContentLength) { - request_generator_ = []() { + RequestGenerator request_generator = []() { auto header = std::make_shared( std::initializer_list>({{":scheme", "http"}, {":method", "POST"}, @@ -295,7 +297,7 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { }; EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(0); - testBasicFunctionality(1, 1, 1); + testBasicFunctionality(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { @@ -314,7 +316,7 @@ TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { requests_vector.push_back(std::make_shared(header2)); std::vector::iterator request_iterator; request_iterator = requests_vector.begin(); - request_generator_ = [&]() { + RequestGenerator request_generator = [&]() { auto item = *request_iterator; request_iterator++; return std::make_unique(item); @@ -326,7 +328,7 @@ TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(header2))); EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); - testBasicFunctionality(1, 1, 2, expected_requests_vector); + testBasicFunctionality(1, 1, 2, request_generator, expected_requests_vector); EXPECT_EQ(2, getCounter("http_2xx")); } } // namespace Nighthawk From cded6add6b77c7767fc6c04946c3e5ee148d31e4 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 20 Jul 2020 18:28:06 +0000 Subject: [PATCH 007/114] Changing to pass by reference. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 2f2ba4630..7101d559d 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -60,7 +60,7 @@ class BenchmarkClientHttpTest : public Test { } void testBasicFunctionality( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, - RequestGenerator request_generator, + const RequestGenerator& request_generator, const std::vector>& header_expectations = std::vector>()) { if (client_ == nullptr) { @@ -145,7 +145,7 @@ class BenchmarkClientHttpTest : public Test { return properties_map; } - void setupBenchmarkClient(RequestGenerator request_generator) { + void setupBenchmarkClient(const RequestGenerator& request_generator) { client_ = std::make_unique( *api_, *dispatcher_, store_, std::make_unique(), std::make_unique(), std::make_unique(), From cdb7efe01ecc53b6a0318d5cce208e8c5d02f685 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 21 Jul 2020 16:25:27 +0000 Subject: [PATCH 008/114] Refactoring per comments in PR. Moving helpers, renaming functions. Adding comments. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 48 +++++++++++++++--------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 7101d559d..d24c0bbaf 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -49,7 +49,7 @@ class BenchmarkClientHttpTest : public Test { return span; }); } - RequestGenerator getDefaultRequestGenerator() { + RequestGenerator getDefaultRequestGenerator() const { RequestGenerator request_generator = []() { auto header = std::make_shared( std::initializer_list>( @@ -58,6 +58,21 @@ class BenchmarkClientHttpTest : public Test { }; return request_generator; } + /// Helper function to get properties in a map that should be verified during the test + absl::flat_hash_map + getTestRecordedProperties(const Envoy::Http::RequestHeaderMap& header) { + absl::flat_hash_map properties_map; + properties_map["uri"] = std::string(header.getPathValue()); + return properties_map; + } + + void setupBenchmarkClient(const RequestGenerator& request_generator) { + client_ = std::make_unique( + *api_, *dispatcher_, store_, std::make_unique(), + std::make_unique(), std::make_unique(), + std::make_unique(), false, cluster_manager_, http_tracer_, "benchmark", + request_generator, true); + } void testBasicFunctionality( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, const RequestGenerator& request_generator, @@ -138,21 +153,6 @@ class BenchmarkClientHttpTest : public Test { } } - absl::flat_hash_map - getTestRecordedProperties(const Envoy::Http::RequestHeaderMap& header) { - absl::flat_hash_map properties_map; - properties_map["uri"] = std::string(header.getPathValue()); - return properties_map; - } - - void setupBenchmarkClient(const RequestGenerator& request_generator) { - client_ = std::make_unique( - *api_, *dispatcher_, store_, std::make_unique(), - std::make_unique(), std::make_unique(), - std::make_unique(), false, cluster_manager_, http_tracer_, "benchmark", - request_generator, true); - } - uint64_t getCounter(absl::string_view name) { return client_->scope().counterFromString(std::string(name)).value(); } @@ -301,21 +301,21 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { EXPECT_EQ(1, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { - std::vector requests_vector; - std::initializer_list> header1{{":scheme", "http"}, + std::vector requests_for_generator_to_send; + std::initializer_list> first_header_map_to_send{{":scheme", "http"}, {":method", "GET"}, {":path", "/a"}, {":host", "localhost"}, {"Content-Length", "1313"}}; - std::initializer_list> header2{{":scheme", "http"}, + std::initializer_list> second_header_map_to_send{{":scheme", "http"}, {":method", "GET"}, {":path", "/b"}, {":host", "localhost"}, {"Content-Length", "1313"}}; - requests_vector.push_back(std::make_shared(header1)); - requests_vector.push_back(std::make_shared(header2)); + requests_for_generator_to_send.push_back(std::make_shared(first_header_map_to_send)); + requests_for_generator_to_send.push_back(std::make_shared(second_header_map_to_send)); std::vector::iterator request_iterator; - request_iterator = requests_vector.begin(); + request_iterator = requests_for_generator_to_send.begin(); RequestGenerator request_generator = [&]() { auto item = *request_iterator; request_iterator++; @@ -323,9 +323,9 @@ TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { }; std::vector> expected_requests_vector; expected_requests_vector.push_back( - getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(header1))); + getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(first_header_map_to_send))); expected_requests_vector.push_back( - getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(header2))); + getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(second_header_map_to_send))); EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); testBasicFunctionality(1, 1, 2, request_generator, expected_requests_vector); From f15bb47d73d0819ce5b59b2ef220b41ceb121f7d Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 21 Jul 2020 17:45:32 +0000 Subject: [PATCH 009/114] Adding comments and renaming testbasicfunctionality for clarity Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index d24c0bbaf..a5f61c17b 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -65,7 +65,7 @@ class BenchmarkClientHttpTest : public Test { properties_map["uri"] = std::string(header.getPathValue()); return properties_map; } - + ///Used to set up benchmarkclient. Especially from within the testBenchmarkClientFunctionality. void setupBenchmarkClient(const RequestGenerator& request_generator) { client_ = std::make_unique( *api_, *dispatcher_, store_, std::make_unique(), @@ -73,7 +73,8 @@ class BenchmarkClientHttpTest : public Test { std::make_unique(), false, cluster_manager_, http_tracer_, "benchmark", request_generator, true); } - void testBasicFunctionality( + ///Primary testing method. Confirms that connection limits are met and number of requests are correct. If specified, also checks the header expectations, if not specified, it is ignored. + void testBenchmarkClientFunctionality( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, const RequestGenerator& request_generator, const std::vector>& header_expectations = @@ -186,36 +187,36 @@ class BenchmarkClientHttpTest : public Test { TEST_F(BenchmarkClientHttpTest, BasicTestH1200) { response_code_ = "200"; - testBasicFunctionality(2, 3, 10, getDefaultRequestGenerator()); + testBenchmarkClientFunctionality(2, 3, 10, getDefaultRequestGenerator()); EXPECT_EQ(5, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1300) { response_code_ = "300"; - testBasicFunctionality(0, 11, 10, getDefaultRequestGenerator()); + testBenchmarkClientFunctionality(0, 11, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, getCounter("http_3xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1404) { response_code_ = "404"; - testBasicFunctionality(0, 1, 10, getDefaultRequestGenerator()); + testBenchmarkClientFunctionality(0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_4xx")); } TEST_F(BenchmarkClientHttpTest, WeirdStatus) { response_code_ = "601"; - testBasicFunctionality(0, 1, 10, getDefaultRequestGenerator()); + testBenchmarkClientFunctionality(0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_xxx")); } TEST_F(BenchmarkClientHttpTest, EnableLatencyMeasurement) { setupBenchmarkClient(getDefaultRequestGenerator()); EXPECT_EQ(false, client_->shouldMeasureLatencies()); - testBasicFunctionality(10, 1, 10, getDefaultRequestGenerator()); + testBenchmarkClientFunctionality(10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.request_to_response"]->count()); client_->setShouldMeasureLatencies(true); - testBasicFunctionality(10, 1, 10, getDefaultRequestGenerator()); + testBenchmarkClientFunctionality(10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.request_to_response"]->count()); } @@ -281,7 +282,7 @@ TEST_F(BenchmarkClientHttpTest, RequestMethodPost) { }; EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(1); - testBasicFunctionality(1, 1, 1, request_generator); + testBenchmarkClientFunctionality(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } @@ -297,7 +298,7 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { }; EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(0); - testBasicFunctionality(1, 1, 1, request_generator); + testBenchmarkClientFunctionality(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { @@ -328,7 +329,7 @@ TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(second_header_map_to_send))); EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); - testBasicFunctionality(1, 1, 2, request_generator, expected_requests_vector); + testBenchmarkClientFunctionality(1, 1, 2, request_generator, expected_requests_vector); EXPECT_EQ(2, getCounter("http_2xx")); } } // namespace Nighthawk From 59359a233494130cc6c67cc5b1f1cfcf1978999f Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 21 Jul 2020 18:17:01 +0000 Subject: [PATCH 010/114] Consistent unit test naming convention using should. Clarifying comments Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index a5f61c17b..72437805d 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -301,14 +301,14 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { testBenchmarkClientFunctionality(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } -TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { +TEST_F(BenchmarkClientHttpTest, ShouldSupportRequestSupportThatGoesToDifferentPaths) { std::vector requests_for_generator_to_send; - std::initializer_list> first_header_map_to_send{{":scheme", "http"}, + const std::initializer_list> first_header_map_to_send{{":scheme", "http"}, {":method", "GET"}, {":path", "/a"}, {":host", "localhost"}, {"Content-Length", "1313"}}; - std::initializer_list> second_header_map_to_send{{":scheme", "http"}, + const std::initializer_list> second_header_map_to_send{{":scheme", "http"}, {":method", "GET"}, {":path", "/b"}, {":host", "localhost"}, @@ -329,6 +329,7 @@ TEST_F(BenchmarkClientHttpTest, MultipleRequestsDifferentPath) { getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(second_header_map_to_send))); EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); + //Most of the testing happens inside of this call. Will confirm that the requests received match the expected requests vector. testBenchmarkClientFunctionality(1, 1, 2, request_generator, expected_requests_vector); EXPECT_EQ(2, getCounter("http_2xx")); } From f63df91ff7770f8e83946970a42fbdaa92fa8eb2 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 21 Jul 2020 18:29:32 +0000 Subject: [PATCH 011/114] Fix format Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 36 +++++++++++++++++------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 72437805d..cc5faf465 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -65,7 +65,7 @@ class BenchmarkClientHttpTest : public Test { properties_map["uri"] = std::string(header.getPathValue()); return properties_map; } - ///Used to set up benchmarkclient. Especially from within the testBenchmarkClientFunctionality. + /// Used to set up benchmarkclient. Especially from within the testBenchmarkClientFunctionality. void setupBenchmarkClient(const RequestGenerator& request_generator) { client_ = std::make_unique( *api_, *dispatcher_, store_, std::make_unique(), @@ -73,7 +73,8 @@ class BenchmarkClientHttpTest : public Test { std::make_unique(), false, cluster_manager_, http_tracer_, "benchmark", request_generator, true); } - ///Primary testing method. Confirms that connection limits are met and number of requests are correct. If specified, also checks the header expectations, if not specified, it is ignored. + /// Primary testing method. Confirms that connection limits are met and number of requests are + /// correct. If specified, also checks the header expectations, if not specified, it is ignored. void testBenchmarkClientFunctionality( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, const RequestGenerator& request_generator, @@ -303,18 +304,22 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { } TEST_F(BenchmarkClientHttpTest, ShouldSupportRequestSupportThatGoesToDifferentPaths) { std::vector requests_for_generator_to_send; - const std::initializer_list> first_header_map_to_send{{":scheme", "http"}, - {":method", "GET"}, - {":path", "/a"}, - {":host", "localhost"}, - {"Content-Length", "1313"}}; - const std::initializer_list> second_header_map_to_send{{":scheme", "http"}, - {":method", "GET"}, - {":path", "/b"}, - {":host", "localhost"}, - {"Content-Length", "1313"}}; - requests_for_generator_to_send.push_back(std::make_shared(first_header_map_to_send)); - requests_for_generator_to_send.push_back(std::make_shared(second_header_map_to_send)); + const std::initializer_list> first_header_map_to_send{ + {":scheme", "http"}, + {":method", "GET"}, + {":path", "/a"}, + {":host", "localhost"}, + {"Content-Length", "1313"}}; + const std::initializer_list> second_header_map_to_send{ + {":scheme", "http"}, + {":method", "GET"}, + {":path", "/b"}, + {":host", "localhost"}, + {"Content-Length", "1313"}}; + requests_for_generator_to_send.push_back( + std::make_shared(first_header_map_to_send)); + requests_for_generator_to_send.push_back( + std::make_shared(second_header_map_to_send)); std::vector::iterator request_iterator; request_iterator = requests_for_generator_to_send.begin(); RequestGenerator request_generator = [&]() { @@ -329,7 +334,8 @@ TEST_F(BenchmarkClientHttpTest, ShouldSupportRequestSupportThatGoesToDifferentPa getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(second_header_map_to_send))); EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); - //Most of the testing happens inside of this call. Will confirm that the requests received match the expected requests vector. + // Most of the testing happens inside of this call. Will confirm that the requests received match + // the expected requests vector. testBenchmarkClientFunctionality(1, 1, 2, request_generator, expected_requests_vector); EXPECT_EQ(2, getCounter("http_2xx")); } From 406bd6bbf63ab190999f7713376764754ee8cd7f Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 22 Jul 2020 21:52:44 +0000 Subject: [PATCH 012/114] Adding a clarifying comment for helper function. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index cc5faf465..8d65cced4 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -49,6 +49,7 @@ class BenchmarkClientHttpTest : public Test { return span; }); } + //Default function for request generator when the content doesn't matter. RequestGenerator getDefaultRequestGenerator() const { RequestGenerator request_generator = []() { auto header = std::make_shared( From f0b697b194678af255a4806f1f9c7e17e6588868 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 23 Jul 2020 21:54:39 +0000 Subject: [PATCH 013/114] Fixing typo and other nits Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 8d65cced4..05a19aefd 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -49,7 +49,7 @@ class BenchmarkClientHttpTest : public Test { return span; }); } - //Default function for request generator when the content doesn't matter. + // Default function for request generator when the content doesn't matter. RequestGenerator getDefaultRequestGenerator() const { RequestGenerator request_generator = []() { auto header = std::make_shared( @@ -85,7 +85,7 @@ class BenchmarkClientHttpTest : public Test { setupBenchmarkClient(request_generator); cluster_info().resetResourceManager(connection_limit, max_pending, 1024, 0, 1024); } - // this is where we store the properties of headers that are passed to the stream encoder. We + // This is where we store the properties of headers that are passed to the stream encoder. We // verify later that these match expected headers. std::vector> called_headers; EXPECT_CALL(stream_encoder_, encodeHeaders(_, _)).Times(AtLeast(1)); From 8425e484b706f49cea1eb6b936a0b859ec0d8179 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 23 Jul 2020 22:04:00 +0000 Subject: [PATCH 014/114] Renaming testBenchmarkClient for clarity Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 05a19aefd..f46d63b3d 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -76,7 +76,7 @@ class BenchmarkClientHttpTest : public Test { } /// Primary testing method. Confirms that connection limits are met and number of requests are /// correct. If specified, also checks the header expectations, if not specified, it is ignored. - void testBenchmarkClientFunctionality( + void TestBenchmarkClientProcessesExpectedInflightRequests( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, const RequestGenerator& request_generator, const std::vector>& header_expectations = @@ -189,36 +189,36 @@ class BenchmarkClientHttpTest : public Test { TEST_F(BenchmarkClientHttpTest, BasicTestH1200) { response_code_ = "200"; - testBenchmarkClientFunctionality(2, 3, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(2, 3, 10, getDefaultRequestGenerator()); EXPECT_EQ(5, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1300) { response_code_ = "300"; - testBenchmarkClientFunctionality(0, 11, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(0, 11, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, getCounter("http_3xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1404) { response_code_ = "404"; - testBenchmarkClientFunctionality(0, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_4xx")); } TEST_F(BenchmarkClientHttpTest, WeirdStatus) { response_code_ = "601"; - testBenchmarkClientFunctionality(0, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_xxx")); } TEST_F(BenchmarkClientHttpTest, EnableLatencyMeasurement) { setupBenchmarkClient(getDefaultRequestGenerator()); EXPECT_EQ(false, client_->shouldMeasureLatencies()); - testBenchmarkClientFunctionality(10, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.request_to_response"]->count()); client_->setShouldMeasureLatencies(true); - testBenchmarkClientFunctionality(10, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.request_to_response"]->count()); } @@ -284,7 +284,7 @@ TEST_F(BenchmarkClientHttpTest, RequestMethodPost) { }; EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(1); - testBenchmarkClientFunctionality(1, 1, 1, request_generator); + TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } @@ -300,7 +300,7 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { }; EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(0); - testBenchmarkClientFunctionality(1, 1, 1, request_generator); + TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, ShouldSupportRequestSupportThatGoesToDifferentPaths) { @@ -337,7 +337,7 @@ TEST_F(BenchmarkClientHttpTest, ShouldSupportRequestSupportThatGoesToDifferentPa EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); // Most of the testing happens inside of this call. Will confirm that the requests received match // the expected requests vector. - testBenchmarkClientFunctionality(1, 1, 2, request_generator, expected_requests_vector); + TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 2, request_generator, expected_requests_vector); EXPECT_EQ(2, getCounter("http_2xx")); } } // namespace Nighthawk From fb4f372d1dbecffa30fe2cd19c9741dfae75aab0 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 24 Jul 2020 16:31:16 +0000 Subject: [PATCH 015/114] Replacing Flat hash map with flat hash set for simplicity. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index f46d63b3d..674923223 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -59,14 +59,14 @@ class BenchmarkClientHttpTest : public Test { }; return request_generator; } - /// Helper function to get properties in a map that should be verified during the test - absl::flat_hash_map + // Helper function to get properties in a map that should be verified during the test + absl::flat_hash_set getTestRecordedProperties(const Envoy::Http::RequestHeaderMap& header) { - absl::flat_hash_map properties_map; - properties_map["uri"] = std::string(header.getPathValue()); + absl::flat_hash_set properties_map; + properties_map.insert(std::string(header.getPathValue())); return properties_map; } - /// Used to set up benchmarkclient. Especially from within the testBenchmarkClientFunctionality. + // Used to set up benchmarkclient. Especially from within the testBenchmarkClientFunctionality. void setupBenchmarkClient(const RequestGenerator& request_generator) { client_ = std::make_unique( *api_, *dispatcher_, store_, std::make_unique(), @@ -74,20 +74,20 @@ class BenchmarkClientHttpTest : public Test { std::make_unique(), false, cluster_manager_, http_tracer_, "benchmark", request_generator, true); } - /// Primary testing method. Confirms that connection limits are met and number of requests are - /// correct. If specified, also checks the header expectations, if not specified, it is ignored. + // Primary testing method. Confirms that connection limits are met and number of requests are + // correct. If specified, also checks the header expectations, if not specified, it is ignored. void TestBenchmarkClientProcessesExpectedInflightRequests( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, const RequestGenerator& request_generator, - const std::vector>& header_expectations = - std::vector>()) { + const std::vector>& header_expectations = + std::vector>()) { if (client_ == nullptr) { setupBenchmarkClient(request_generator); cluster_info().resetResourceManager(connection_limit, max_pending, 1024, 0, 1024); } // This is where we store the properties of headers that are passed to the stream encoder. We // verify later that these match expected headers. - std::vector> called_headers; + std::vector> called_headers; EXPECT_CALL(stream_encoder_, encodeHeaders(_, _)).Times(AtLeast(1)); ON_CALL(stream_encoder_, encodeHeaders(_, _)) .WillByDefault(WithArgs<0>( @@ -303,7 +303,7 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } -TEST_F(BenchmarkClientHttpTest, ShouldSupportRequestSupportThatGoesToDifferentPaths) { +TEST_F(BenchmarkClientHttpTest, RequestGeneratorProvidingDifferentPathsSendsRequestsOnThosePaths) { std::vector requests_for_generator_to_send; const std::initializer_list> first_header_map_to_send{ {":scheme", "http"}, @@ -328,7 +328,7 @@ TEST_F(BenchmarkClientHttpTest, ShouldSupportRequestSupportThatGoesToDifferentPa request_iterator++; return std::make_unique(item); }; - std::vector> expected_requests_vector; + std::vector> expected_requests_vector; expected_requests_vector.push_back( getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(first_header_map_to_send))); expected_requests_vector.push_back( From c6eae6ce3b6fe333a1d667c0d1f57383f18bfa55 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 24 Jul 2020 16:36:27 +0000 Subject: [PATCH 016/114] Comment clarification. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 674923223..1aa9970d4 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -75,7 +75,7 @@ class BenchmarkClientHttpTest : public Test { request_generator, true); } // Primary testing method. Confirms that connection limits are met and number of requests are - // correct. If specified, also checks the header expectations, if not specified, it is ignored. + // correct. If not empty, also checks the header expectations, if empty, it is ignored. void TestBenchmarkClientProcessesExpectedInflightRequests( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, const RequestGenerator& request_generator, From 96ae38bc2fe8090d72438b4485f9f089c58ccb50 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 27 Jul 2020 15:04:54 +0000 Subject: [PATCH 017/114] Small refactor for factory method for more dependency injection. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/factories.h | 9 +++++++++ source/client/factories_impl.cc | 26 ++++++++++++++++++++++---- source/client/factories_impl.h | 17 ++++++++++++++++- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/include/nighthawk/common/factories.h b/include/nighthawk/common/factories.h index c6111e79d..f90bf3577 100644 --- a/include/nighthawk/common/factories.h +++ b/include/nighthawk/common/factories.h @@ -32,6 +32,15 @@ class StatisticFactory { virtual StatisticPtr create() const PURE; }; +class RequestSourceConstructorInterface { + public: + virtual ~RequestSourceConstructorInterface() = default; + virtual RequestSourcePtr createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&&, + const uint64_t max_yields = UINT64_MAX) const PURE; + virtual RequestSourcePtr createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, + uint32_t header_buffer_length) const PURE; +}; + class RequestSourceFactory { public: virtual ~RequestSourceFactory() = default; diff --git a/source/client/factories_impl.cc b/source/client/factories_impl.cc index a2e3eb611..42ba529e8 100644 --- a/source/client/factories_impl.cc +++ b/source/client/factories_impl.cc @@ -103,6 +103,21 @@ OutputFormatterPtr OutputFormatterFactoryImpl::create( NOT_REACHED_GCOVR_EXCL_LINE; } } +RequestSourceConstructorImpl::RequestSourceConstructorImpl(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, + Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, + absl::string_view service_cluster_name) : cluster_manager_(cluster_manager), dispatcher_(dispatcher), scope_(scope), service_cluster_name_(service_cluster_name) + { + } +RequestSourcePtr RequestSourceConstructorImpl::createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, + const uint64_t max_yields) const + { + return std::make_unique(std::move(base_header), max_yields); + } +RequestSourcePtr RequestSourceConstructorImpl::createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, + uint32_t header_buffer_length) const + { + return std::make_unique(cluster_manager_, dispatcher_, scope_, service_cluster_name_, std::move(base_header), header_buffer_length); + } RequestSourceFactoryImpl::RequestSourceFactoryImpl(const Options& options) : OptionBasedFactoryImpl(options) {} @@ -120,6 +135,7 @@ RequestSourcePtr RequestSourceFactoryImpl::create(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, absl::string_view service_cluster_name) const { + RequestSourceConstructorImpl request_source_constructor(cluster_manager, dispatcher, scope, service_cluster_name); Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); if (options_.uri().has_value()) { // We set headers based on the URI, but we don't have all the prerequisites to call the @@ -157,14 +173,16 @@ RequestSourceFactoryImpl::create(const Envoy::Upstream::ClusterManagerPtr& clust } if (options_.requestSource() == "") { - return std::make_unique(std::move(header)); + return request_source_constructor.createStaticRequestSource(std::move(header)); +// return std::make_unique(std::move(header)); } else { RELEASE_ASSERT(!service_cluster_name.empty(), "expected cluster name to be set"); // We pass in options_.requestsPerSecond() as the header buffer length so the grpc client // will shoot for maintaining an amount of headers of at least one second. - return std::make_unique(cluster_manager, dispatcher, scope, - service_cluster_name, std::move(header), - options_.requestsPerSecond()); + return request_source_constructor.createRemoteRequestSource(std::move(header), options_.requestsPerSecond()); + // return std::make_unique(cluster_manager, dispatcher, scope, + // service_cluster_name, std::move(header), + // options_.requestsPerSecond()); } } diff --git a/source/client/factories_impl.h b/source/client/factories_impl.h index 928b63f99..163dbd26b 100644 --- a/source/client/factories_impl.h +++ b/source/client/factories_impl.h @@ -55,7 +55,22 @@ class OutputFormatterFactoryImpl : public OutputFormatterFactory { OutputFormatterPtr create(const nighthawk::client::OutputFormat_OutputFormatOptions output_format) const override; }; - +class RequestSourceConstructorImpl : public RequestSourceConstructorInterface { +public: + virtual ~RequestSourceConstructorImpl() = default; + RequestSourceConstructorImpl(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, + Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, + absl::string_view service_cluster_name); + RequestSourcePtr createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, + const uint64_t max_yields = UINT64_MAX) const override; + RequestSourcePtr createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, + uint32_t header_buffer_length) const override; +protected: + const Envoy::Upstream::ClusterManagerPtr& cluster_manager_; + Envoy::Event::Dispatcher& dispatcher_; + Envoy::Stats::Scope& scope_; + absl::string_view service_cluster_name_; +}; class RequestSourceFactoryImpl : public OptionBasedFactoryImpl, public RequestSourceFactory { public: RequestSourceFactoryImpl(const Options& options); From b17240f4ab6f6911462f200d10cc7f763bee2435 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 27 Jul 2020 15:08:31 +0000 Subject: [PATCH 018/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/factories.h | 13 ++++----- source/client/factories_impl.cc | 40 +++++++++++++++------------- source/client/factories_impl.h | 27 ++++++++++--------- 3 files changed, 42 insertions(+), 38 deletions(-) diff --git a/include/nighthawk/common/factories.h b/include/nighthawk/common/factories.h index f90bf3577..481b11827 100644 --- a/include/nighthawk/common/factories.h +++ b/include/nighthawk/common/factories.h @@ -33,12 +33,13 @@ class StatisticFactory { }; class RequestSourceConstructorInterface { - public: - virtual ~RequestSourceConstructorInterface() = default; - virtual RequestSourcePtr createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&&, - const uint64_t max_yields = UINT64_MAX) const PURE; - virtual RequestSourcePtr createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, - uint32_t header_buffer_length) const PURE; +public: + virtual ~RequestSourceConstructorInterface() = default; + virtual RequestSourcePtr + createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&&, + const uint64_t max_yields = UINT64_MAX) const PURE; + virtual RequestSourcePtr createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, + uint32_t header_buffer_length) const PURE; }; class RequestSourceFactory { diff --git a/source/client/factories_impl.cc b/source/client/factories_impl.cc index 42ba529e8..e9790afbf 100644 --- a/source/client/factories_impl.cc +++ b/source/client/factories_impl.cc @@ -103,21 +103,21 @@ OutputFormatterPtr OutputFormatterFactoryImpl::create( NOT_REACHED_GCOVR_EXCL_LINE; } } -RequestSourceConstructorImpl::RequestSourceConstructorImpl(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, - Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, - absl::string_view service_cluster_name) : cluster_manager_(cluster_manager), dispatcher_(dispatcher), scope_(scope), service_cluster_name_(service_cluster_name) - { - } -RequestSourcePtr RequestSourceConstructorImpl::createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, - const uint64_t max_yields) const - { - return std::make_unique(std::move(base_header), max_yields); - } -RequestSourcePtr RequestSourceConstructorImpl::createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, - uint32_t header_buffer_length) const - { - return std::make_unique(cluster_manager_, dispatcher_, scope_, service_cluster_name_, std::move(base_header), header_buffer_length); - } +RequestSourceConstructorImpl::RequestSourceConstructorImpl( + const Envoy::Upstream::ClusterManagerPtr& cluster_manager, Envoy::Event::Dispatcher& dispatcher, + Envoy::Stats::Scope& scope, absl::string_view service_cluster_name) + : cluster_manager_(cluster_manager), dispatcher_(dispatcher), scope_(scope), + service_cluster_name_(service_cluster_name) {} +RequestSourcePtr RequestSourceConstructorImpl::createStaticRequestSource( + Envoy::Http::RequestHeaderMapPtr&& base_header, const uint64_t max_yields) const { + return std::make_unique(std::move(base_header), max_yields); +} +RequestSourcePtr RequestSourceConstructorImpl::createRemoteRequestSource( + Envoy::Http::RequestHeaderMapPtr&& base_header, uint32_t header_buffer_length) const { + return std::make_unique(cluster_manager_, dispatcher_, scope_, + service_cluster_name_, std::move(base_header), + header_buffer_length); +} RequestSourceFactoryImpl::RequestSourceFactoryImpl(const Options& options) : OptionBasedFactoryImpl(options) {} @@ -135,7 +135,8 @@ RequestSourcePtr RequestSourceFactoryImpl::create(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, absl::string_view service_cluster_name) const { - RequestSourceConstructorImpl request_source_constructor(cluster_manager, dispatcher, scope, service_cluster_name); + RequestSourceConstructorImpl request_source_constructor(cluster_manager, dispatcher, scope, + service_cluster_name); Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); if (options_.uri().has_value()) { // We set headers based on the URI, but we don't have all the prerequisites to call the @@ -173,13 +174,14 @@ RequestSourceFactoryImpl::create(const Envoy::Upstream::ClusterManagerPtr& clust } if (options_.requestSource() == "") { - return request_source_constructor.createStaticRequestSource(std::move(header)); -// return std::make_unique(std::move(header)); + return request_source_constructor.createStaticRequestSource(std::move(header)); + // return std::make_unique(std::move(header)); } else { RELEASE_ASSERT(!service_cluster_name.empty(), "expected cluster name to be set"); // We pass in options_.requestsPerSecond() as the header buffer length so the grpc client // will shoot for maintaining an amount of headers of at least one second. - return request_source_constructor.createRemoteRequestSource(std::move(header), options_.requestsPerSecond()); + return request_source_constructor.createRemoteRequestSource(std::move(header), + options_.requestsPerSecond()); // return std::make_unique(cluster_manager, dispatcher, scope, // service_cluster_name, std::move(header), // options_.requestsPerSecond()); diff --git a/source/client/factories_impl.h b/source/client/factories_impl.h index 163dbd26b..262e08ad7 100644 --- a/source/client/factories_impl.h +++ b/source/client/factories_impl.h @@ -56,20 +56,21 @@ class OutputFormatterFactoryImpl : public OutputFormatterFactory { create(const nighthawk::client::OutputFormat_OutputFormatOptions output_format) const override; }; class RequestSourceConstructorImpl : public RequestSourceConstructorInterface { -public: - virtual ~RequestSourceConstructorImpl() = default; - RequestSourceConstructorImpl(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, - Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, - absl::string_view service_cluster_name); - RequestSourcePtr createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, - const uint64_t max_yields = UINT64_MAX) const override; - RequestSourcePtr createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, - uint32_t header_buffer_length) const override; +public: + virtual ~RequestSourceConstructorImpl() = default; + RequestSourceConstructorImpl(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, + Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, + absl::string_view service_cluster_name); + RequestSourcePtr createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, + const uint64_t max_yields = UINT64_MAX) const override; + RequestSourcePtr createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, + uint32_t header_buffer_length) const override; + protected: - const Envoy::Upstream::ClusterManagerPtr& cluster_manager_; - Envoy::Event::Dispatcher& dispatcher_; - Envoy::Stats::Scope& scope_; - absl::string_view service_cluster_name_; + const Envoy::Upstream::ClusterManagerPtr& cluster_manager_; + Envoy::Event::Dispatcher& dispatcher_; + Envoy::Stats::Scope& scope_; + absl::string_view service_cluster_name_; }; class RequestSourceFactoryImpl : public OptionBasedFactoryImpl, public RequestSourceFactory { public: From 5c5a146c98b58dac48014b42c7dee6df0ec59157 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 27 Jul 2020 17:24:36 +0000 Subject: [PATCH 019/114] Refactor to inject the requestsourceconstructor. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/factories.h | 4 +--- source/client/client_worker_impl.cc | 6 +++--- source/client/factories_impl.cc | 8 ++------ source/client/factories_impl.h | 4 +--- test/factories_test.cc | 3 ++- 5 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/nighthawk/common/factories.h b/include/nighthawk/common/factories.h index 481b11827..3204c9b1c 100644 --- a/include/nighthawk/common/factories.h +++ b/include/nighthawk/common/factories.h @@ -45,9 +45,7 @@ class RequestSourceConstructorInterface { class RequestSourceFactory { public: virtual ~RequestSourceFactory() = default; - virtual RequestSourcePtr create(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, - Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, - absl::string_view service_cluster_name) const PURE; + virtual RequestSourcePtr create(const RequestSourceConstructorInterface& request_source_constructor) const PURE; }; class TerminationPredicateFactory { diff --git a/source/client/client_worker_impl.cc b/source/client/client_worker_impl.cc index 09aaba66a..07dc27797 100644 --- a/source/client/client_worker_impl.cc +++ b/source/client/client_worker_impl.cc @@ -1,7 +1,7 @@ #include "client/client_worker_impl.h" +#include "client/factories_impl.h" #include "external/envoy/source/common/stats/symbol_table_impl.h" - #include "common/cached_time_source_impl.h" #include "common/phase_impl.h" #include "common/termination_predicate_impl.h" @@ -29,8 +29,8 @@ ClientWorkerImpl::ClientWorkerImpl(Envoy::Api::Api& api, Envoy::ThreadLocal::Ins worker_number_scope_(worker_scope_->createScope(fmt::format("{}.", worker_number))), worker_number_(worker_number), http_tracer_(http_tracer), request_generator_( - request_generator_factory.create(cluster_manager, *dispatcher_, *worker_number_scope_, - fmt::format("{}.requestsource", worker_number))), + request_generator_factory.create(RequestSourceConstructorImpl(cluster_manager, *dispatcher_, *worker_number_scope_, + fmt::format("{}.requestsource", worker_number)))), benchmark_client_(benchmark_client_factory.create( api, *dispatcher_, *worker_number_scope_, cluster_manager, http_tracer_, fmt::format("{}", worker_number), *request_generator_)), diff --git a/source/client/factories_impl.cc b/source/client/factories_impl.cc index e9790afbf..8cc4d310e 100644 --- a/source/client/factories_impl.cc +++ b/source/client/factories_impl.cc @@ -114,6 +114,7 @@ RequestSourcePtr RequestSourceConstructorImpl::createStaticRequestSource( } RequestSourcePtr RequestSourceConstructorImpl::createRemoteRequestSource( Envoy::Http::RequestHeaderMapPtr&& base_header, uint32_t header_buffer_length) const { + RELEASE_ASSERT(!service_cluster_name_.empty(), "expected cluster name to be set"); return std::make_unique(cluster_manager_, dispatcher_, scope_, service_cluster_name_, std::move(base_header), header_buffer_length); @@ -132,11 +133,7 @@ void RequestSourceFactoryImpl::setRequestHeader(Envoy::Http::RequestHeaderMap& h } RequestSourcePtr -RequestSourceFactoryImpl::create(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, - Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, - absl::string_view service_cluster_name) const { - RequestSourceConstructorImpl request_source_constructor(cluster_manager, dispatcher, scope, - service_cluster_name); +RequestSourceFactoryImpl::create(const RequestSourceConstructorInterface& request_source_constructor) const { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); if (options_.uri().has_value()) { // We set headers based on the URI, but we don't have all the prerequisites to call the @@ -177,7 +174,6 @@ RequestSourceFactoryImpl::create(const Envoy::Upstream::ClusterManagerPtr& clust return request_source_constructor.createStaticRequestSource(std::move(header)); // return std::make_unique(std::move(header)); } else { - RELEASE_ASSERT(!service_cluster_name.empty(), "expected cluster name to be set"); // We pass in options_.requestsPerSecond() as the header buffer length so the grpc client // will shoot for maintaining an amount of headers of at least one second. return request_source_constructor.createRemoteRequestSource(std::move(header), diff --git a/source/client/factories_impl.h b/source/client/factories_impl.h index 262e08ad7..c7850225d 100644 --- a/source/client/factories_impl.h +++ b/source/client/factories_impl.h @@ -75,9 +75,7 @@ class RequestSourceConstructorImpl : public RequestSourceConstructorInterface { class RequestSourceFactoryImpl : public OptionBasedFactoryImpl, public RequestSourceFactory { public: RequestSourceFactoryImpl(const Options& options); - RequestSourcePtr create(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, - Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, - absl::string_view service_cluster_name) const override; + RequestSourcePtr create(const RequestSourceConstructorInterface& request_source_constructor) const override; private: void setRequestHeader(Envoy::Http::RequestHeaderMap& header, absl::string_view key, diff --git a/test/factories_test.cc b/test/factories_test.cc index 2f82f96e5..88d9a2f69 100644 --- a/test/factories_test.cc +++ b/test/factories_test.cc @@ -62,8 +62,9 @@ TEST_F(FactoriesTest, CreateRequestSource) { EXPECT_CALL(options_, toCommandLineOptions()).Times(1).WillOnce(Return(ByMove(std::move(cmd)))); RequestSourceFactoryImpl factory(options_); Envoy::Upstream::ClusterManagerPtr cluster_manager; - auto request_generator = factory.create(cluster_manager, dispatcher_, + RequestSourceConstructorImpl constructor(cluster_manager, dispatcher_, *stats_store_.createScope("foo."), "requestsource"); + auto request_generator = factory.create(constructor); EXPECT_NE(nullptr, request_generator.get()); } From 29591fff86b37e972fe2e15f53ed779fcc88a851 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 27 Jul 2020 18:12:22 +0000 Subject: [PATCH 020/114] Moving helper functions. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 80 +++++++++++++++++------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 1aa9970d4..1d3fa8f7a 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -26,6 +26,26 @@ using namespace testing; namespace Nighthawk { +namespace BenchmarkClientTestHelperFunctions { +// Default function for request generator when the content doesn't matter. +RequestGenerator getDefaultRequestGenerator() { + RequestGenerator request_generator = []() { + auto header = std::make_shared( + std::initializer_list>( + {{":scheme", "http"}, {":method", "GET"}, {":path", "/"}, {":host", "localhost"}})); + return std::make_unique(header); + }; + return request_generator; +} +// Helper function to get headers in a set that should be verified during the test. +absl::flat_hash_set +getTestRecordedProperties(const Envoy::Http::RequestHeaderMap& header) { + absl::flat_hash_set header_set; + header_set.insert(std::string(header.getPathValue())); + return header_set; +} +} // namespace BenchmarkClientTestHelperFunctions + class BenchmarkClientHttpTest : public Test { public: BenchmarkClientHttpTest() @@ -49,23 +69,7 @@ class BenchmarkClientHttpTest : public Test { return span; }); } - // Default function for request generator when the content doesn't matter. - RequestGenerator getDefaultRequestGenerator() const { - RequestGenerator request_generator = []() { - auto header = std::make_shared( - std::initializer_list>( - {{":scheme", "http"}, {":method", "GET"}, {":path", "/"}, {":host", "localhost"}})); - return std::make_unique(header); - }; - return request_generator; - } - // Helper function to get properties in a map that should be verified during the test - absl::flat_hash_set - getTestRecordedProperties(const Envoy::Http::RequestHeaderMap& header) { - absl::flat_hash_set properties_map; - properties_map.insert(std::string(header.getPathValue())); - return properties_map; - } + // Used to set up benchmarkclient. Especially from within the testBenchmarkClientFunctionality. void setupBenchmarkClient(const RequestGenerator& request_generator) { client_ = std::make_unique( @@ -90,9 +94,10 @@ class BenchmarkClientHttpTest : public Test { std::vector> called_headers; EXPECT_CALL(stream_encoder_, encodeHeaders(_, _)).Times(AtLeast(1)); ON_CALL(stream_encoder_, encodeHeaders(_, _)) - .WillByDefault(WithArgs<0>( - ([this, &called_headers](const Envoy::Http::RequestHeaderMap& specific_request) { - called_headers.push_back(getTestRecordedProperties(specific_request)); + .WillByDefault( + WithArgs<0>(([&called_headers](const Envoy::Http::RequestHeaderMap& specific_request) { + called_headers.push_back( + BenchmarkClientTestHelperFunctions::getTestRecordedProperties(specific_request)); }))); EXPECT_CALL(pool_, newStream(_, _)) @@ -189,36 +194,42 @@ class BenchmarkClientHttpTest : public Test { TEST_F(BenchmarkClientHttpTest, BasicTestH1200) { response_code_ = "200"; - TestBenchmarkClientProcessesExpectedInflightRequests(2, 3, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests( + 2, 3, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); EXPECT_EQ(5, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1300) { response_code_ = "300"; - TestBenchmarkClientProcessesExpectedInflightRequests(0, 11, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests( + 0, 11, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); EXPECT_EQ(10, getCounter("http_3xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1404) { response_code_ = "404"; - TestBenchmarkClientProcessesExpectedInflightRequests(0, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests( + 0, 1, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_4xx")); } TEST_F(BenchmarkClientHttpTest, WeirdStatus) { response_code_ = "601"; - TestBenchmarkClientProcessesExpectedInflightRequests(0, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests( + 0, 1, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_xxx")); } TEST_F(BenchmarkClientHttpTest, EnableLatencyMeasurement) { - setupBenchmarkClient(getDefaultRequestGenerator()); + setupBenchmarkClient(BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); EXPECT_EQ(false, client_->shouldMeasureLatencies()); - TestBenchmarkClientProcessesExpectedInflightRequests(10, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests( + 10, 1, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.request_to_response"]->count()); client_->setShouldMeasureLatencies(true); - TestBenchmarkClientProcessesExpectedInflightRequests(10, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests( + 10, 1, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.request_to_response"]->count()); } @@ -229,7 +240,7 @@ TEST_F(BenchmarkClientHttpTest, StatusTrackingInOnComplete) { *api_, *dispatcher_, *store, std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), false, cluster_manager_, http_tracer_, "foo", - getDefaultRequestGenerator(), true); + BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator(), true); Envoy::Http::ResponseHeaderMapPtr header = Envoy::Http::ResponseHeaderMapImpl::create(); header->setStatus(1); @@ -261,7 +272,7 @@ TEST_F(BenchmarkClientHttpTest, StatusTrackingInOnComplete) { } TEST_F(BenchmarkClientHttpTest, PoolFailures) { - setupBenchmarkClient(getDefaultRequestGenerator()); + setupBenchmarkClient(BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); client_->onPoolFailure(Envoy::Http::ConnectionPool::PoolFailureReason::LocalConnectionFailure); client_->onPoolFailure(Envoy::Http::ConnectionPool::PoolFailureReason::RemoteConnectionFailure); client_->onPoolFailure(Envoy::Http::ConnectionPool::PoolFailureReason::Overflow); @@ -329,15 +340,16 @@ TEST_F(BenchmarkClientHttpTest, RequestGeneratorProvidingDifferentPathsSendsRequ return std::make_unique(item); }; std::vector> expected_requests_vector; - expected_requests_vector.push_back( - getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(first_header_map_to_send))); - expected_requests_vector.push_back( - getTestRecordedProperties(Envoy::Http::TestRequestHeaderMapImpl(second_header_map_to_send))); + expected_requests_vector.push_back(BenchmarkClientTestHelperFunctions::getTestRecordedProperties( + Envoy::Http::TestRequestHeaderMapImpl(first_header_map_to_send))); + expected_requests_vector.push_back(BenchmarkClientTestHelperFunctions::getTestRecordedProperties( + Envoy::Http::TestRequestHeaderMapImpl(second_header_map_to_send))); EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); // Most of the testing happens inside of this call. Will confirm that the requests received match // the expected requests vector. - TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 2, request_generator, expected_requests_vector); + TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 2, request_generator, + expected_requests_vector); EXPECT_EQ(2, getCounter("http_2xx")); } } // namespace Nighthawk From ff82d95c21bcdd2b8af3a3d58ceed82679b5ec27 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 27 Jul 2020 18:44:49 +0000 Subject: [PATCH 021/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/factories.h | 3 ++- source/client/client_worker_impl.cc | 10 ++++++---- source/client/factories_impl.cc | 4 ++-- source/client/factories_impl.h | 3 ++- test/factories_test.cc | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/nighthawk/common/factories.h b/include/nighthawk/common/factories.h index 3204c9b1c..89243cef6 100644 --- a/include/nighthawk/common/factories.h +++ b/include/nighthawk/common/factories.h @@ -45,7 +45,8 @@ class RequestSourceConstructorInterface { class RequestSourceFactory { public: virtual ~RequestSourceFactory() = default; - virtual RequestSourcePtr create(const RequestSourceConstructorInterface& request_source_constructor) const PURE; + virtual RequestSourcePtr + create(const RequestSourceConstructorInterface& request_source_constructor) const PURE; }; class TerminationPredicateFactory { diff --git a/source/client/client_worker_impl.cc b/source/client/client_worker_impl.cc index 07dc27797..401cbaf7f 100644 --- a/source/client/client_worker_impl.cc +++ b/source/client/client_worker_impl.cc @@ -1,12 +1,14 @@ #include "client/client_worker_impl.h" -#include "client/factories_impl.h" #include "external/envoy/source/common/stats/symbol_table_impl.h" + #include "common/cached_time_source_impl.h" #include "common/phase_impl.h" #include "common/termination_predicate_impl.h" #include "common/utility.h" +#include "client/factories_impl.h" + namespace Nighthawk { namespace Client { @@ -28,9 +30,9 @@ ClientWorkerImpl::ClientWorkerImpl(Envoy::Api::Api& api, Envoy::ThreadLocal::Ins sequencer_factory_(sequencer_factory), worker_scope_(store_.createScope("cluster.")), worker_number_scope_(worker_scope_->createScope(fmt::format("{}.", worker_number))), worker_number_(worker_number), http_tracer_(http_tracer), - request_generator_( - request_generator_factory.create(RequestSourceConstructorImpl(cluster_manager, *dispatcher_, *worker_number_scope_, - fmt::format("{}.requestsource", worker_number)))), + request_generator_(request_generator_factory.create( + RequestSourceConstructorImpl(cluster_manager, *dispatcher_, *worker_number_scope_, + fmt::format("{}.requestsource", worker_number)))), benchmark_client_(benchmark_client_factory.create( api, *dispatcher_, *worker_number_scope_, cluster_manager, http_tracer_, fmt::format("{}", worker_number), *request_generator_)), diff --git a/source/client/factories_impl.cc b/source/client/factories_impl.cc index 8cc4d310e..23e4562b5 100644 --- a/source/client/factories_impl.cc +++ b/source/client/factories_impl.cc @@ -132,8 +132,8 @@ void RequestSourceFactoryImpl::setRequestHeader(Envoy::Http::RequestHeaderMap& h header.addCopy(lower_case_key, std::string(value)); } -RequestSourcePtr -RequestSourceFactoryImpl::create(const RequestSourceConstructorInterface& request_source_constructor) const { +RequestSourcePtr RequestSourceFactoryImpl::create( + const RequestSourceConstructorInterface& request_source_constructor) const { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); if (options_.uri().has_value()) { // We set headers based on the URI, but we don't have all the prerequisites to call the diff --git a/source/client/factories_impl.h b/source/client/factories_impl.h index c7850225d..ec3e4b30d 100644 --- a/source/client/factories_impl.h +++ b/source/client/factories_impl.h @@ -75,7 +75,8 @@ class RequestSourceConstructorImpl : public RequestSourceConstructorInterface { class RequestSourceFactoryImpl : public OptionBasedFactoryImpl, public RequestSourceFactory { public: RequestSourceFactoryImpl(const Options& options); - RequestSourcePtr create(const RequestSourceConstructorInterface& request_source_constructor) const override; + RequestSourcePtr + create(const RequestSourceConstructorInterface& request_source_constructor) const override; private: void setRequestHeader(Envoy::Http::RequestHeaderMap& header, absl::string_view key, diff --git a/test/factories_test.cc b/test/factories_test.cc index 88d9a2f69..0458c07a8 100644 --- a/test/factories_test.cc +++ b/test/factories_test.cc @@ -63,7 +63,7 @@ TEST_F(FactoriesTest, CreateRequestSource) { RequestSourceFactoryImpl factory(options_); Envoy::Upstream::ClusterManagerPtr cluster_manager; RequestSourceConstructorImpl constructor(cluster_manager, dispatcher_, - *stats_store_.createScope("foo."), "requestsource"); + *stats_store_.createScope("foo."), "requestsource"); auto request_generator = factory.create(constructor); EXPECT_NE(nullptr, request_generator.get()); } From 98381a496589d9546bd532569cd6e635d5daa2fc Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 28 Jul 2020 18:25:34 +0000 Subject: [PATCH 022/114] Adding test using the new mock requestsourceconstructor to get remote request source. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/BUILD | 2 ++ test/factories_test.cc | 26 ++++++++++++++++++++++++-- test/mocks/common/BUILD | 9 +++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/test/BUILD b/test/BUILD index ac7cdcacc..1d8d0ab90 100644 --- a/test/BUILD +++ b/test/BUILD @@ -71,6 +71,8 @@ envoy_cc_test( "//test/mocks/client:mock_benchmark_client", "//test/mocks/client:mock_options", "//test/mocks/common:mock_termination_predicate", + "//test/mocks/common:mock_request_source_constructor", + "//test/mocks/common:mock_request_source", "@envoy//test/mocks/event:event_mocks", "@envoy//test/mocks/tracing:tracing_mocks", "@envoy//test/test_common:simulated_time_system_lib", diff --git a/test/factories_test.cc b/test/factories_test.cc index 0458c07a8..f0de0f5ce 100644 --- a/test/factories_test.cc +++ b/test/factories_test.cc @@ -11,6 +11,8 @@ #include "test/mocks/client/mock_benchmark_client.h" #include "test/mocks/client/mock_options.h" #include "test/mocks/common/mock_termination_predicate.h" +#include "test/mocks/common/mock_request_source_constructor.h" +#include "test/mocks/common/mock_request_source.h" #include "gtest/gtest.h" @@ -23,13 +25,16 @@ class FactoriesTest : public Test { public: FactoriesTest() : api_(Envoy::Api::createApiForTest(stats_store_)), - http_tracer_(std::make_unique()) {} + http_tracer_(std::make_unique()) { + } Envoy::Api::ApiPtr api_; Envoy::Stats::MockIsolatedStatsStore stats_store_; Envoy::Event::MockDispatcher dispatcher_; MockOptions options_; Envoy::Tracing::HttpTracerSharedPtr http_tracer_; + MockRequestSourceConstructor mock_request_constructor_; + MockRequestSource mock_request_source_; }; TEST_F(FactoriesTest, CreateBenchmarkClient) { @@ -50,7 +55,7 @@ TEST_F(FactoriesTest, CreateBenchmarkClient) { EXPECT_NE(nullptr, benchmark_client.get()); } -TEST_F(FactoriesTest, CreateRequestSource) { +TEST_F(FactoriesTest, CreateStaticRequestSource) { EXPECT_CALL(options_, requestMethod()).Times(1); EXPECT_CALL(options_, requestBodySize()).Times(1); EXPECT_CALL(options_, uri()).Times(2).WillRepeatedly(Return("http://foo/")); @@ -68,6 +73,23 @@ TEST_F(FactoriesTest, CreateRequestSource) { EXPECT_NE(nullptr, request_generator.get()); } +TEST_F(FactoriesTest, CreateRequestSourceWithRequestSourceUriOptionReturnsRemoteRequestSource) { + EXPECT_CALL(options_, requestMethod()).Times(1); + EXPECT_CALL(options_, requestBodySize()).Times(1); + EXPECT_CALL(options_, requestsPerSecond()).Times(1).WillRepeatedly(Return(1)); + EXPECT_CALL(options_, uri()).Times(2).WillRepeatedly(Return("http://foo/")); + EXPECT_CALL(options_, requestSource()).Times(1).WillRepeatedly(Return("requestSourceUri")); + EXPECT_CALL(mock_request_constructor_, createRemoteRequestSource(_, _)).Times(1); + auto cmd = std::make_unique(); + auto request_headers = cmd->mutable_request_options()->add_request_headers(); + request_headers->mutable_header()->set_key("foo"); + request_headers->mutable_header()->set_value("bar"); + EXPECT_CALL(options_, toCommandLineOptions()).Times(1).WillOnce(Return(ByMove(std::move(cmd)))); + RequestSourceFactoryImpl factory(options_); + Envoy::Upstream::ClusterManagerPtr cluster_manager; + factory.create(mock_request_constructor_); +} + TEST_F(FactoriesTest, CreateSequencer) {} class SequencerFactoryTest : public FactoriesTest, diff --git a/test/mocks/common/BUILD b/test/mocks/common/BUILD index e74f25e1c..522e6541e 100644 --- a/test/mocks/common/BUILD +++ b/test/mocks/common/BUILD @@ -87,3 +87,12 @@ envoy_cc_mock( "//include/nighthawk/common:base_includes", ], ) +envoy_cc_mock( + name = "mock_request_source_constructor", + srcs = ["mock_request_source_constructor.cc"], + hdrs = ["mock_request_source_constructor.h"], + repository = "@envoy", + deps = [ + "//include/nighthawk/common:base_includes", + ], +) \ No newline at end of file From 83ac5564a3276db2905d875af6017095e3ea4398 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 28 Jul 2020 18:26:51 +0000 Subject: [PATCH 023/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/BUILD | 4 ++-- test/factories_test.cc | 7 +++---- test/mocks/common/BUILD | 3 ++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/BUILD b/test/BUILD index 1d8d0ab90..5a00474db 100644 --- a/test/BUILD +++ b/test/BUILD @@ -70,9 +70,9 @@ envoy_cc_test( "//source/client:nighthawk_client_lib", "//test/mocks/client:mock_benchmark_client", "//test/mocks/client:mock_options", - "//test/mocks/common:mock_termination_predicate", - "//test/mocks/common:mock_request_source_constructor", "//test/mocks/common:mock_request_source", + "//test/mocks/common:mock_request_source_constructor", + "//test/mocks/common:mock_termination_predicate", "@envoy//test/mocks/event:event_mocks", "@envoy//test/mocks/tracing:tracing_mocks", "@envoy//test/test_common:simulated_time_system_lib", diff --git a/test/factories_test.cc b/test/factories_test.cc index f0de0f5ce..9e2dab34b 100644 --- a/test/factories_test.cc +++ b/test/factories_test.cc @@ -10,9 +10,9 @@ #include "test/mocks/client/mock_benchmark_client.h" #include "test/mocks/client/mock_options.h" -#include "test/mocks/common/mock_termination_predicate.h" -#include "test/mocks/common/mock_request_source_constructor.h" #include "test/mocks/common/mock_request_source.h" +#include "test/mocks/common/mock_request_source_constructor.h" +#include "test/mocks/common/mock_termination_predicate.h" #include "gtest/gtest.h" @@ -25,8 +25,7 @@ class FactoriesTest : public Test { public: FactoriesTest() : api_(Envoy::Api::createApiForTest(stats_store_)), - http_tracer_(std::make_unique()) { - } + http_tracer_(std::make_unique()) {} Envoy::Api::ApiPtr api_; Envoy::Stats::MockIsolatedStatsStore stats_store_; diff --git a/test/mocks/common/BUILD b/test/mocks/common/BUILD index 522e6541e..0b78b7560 100644 --- a/test/mocks/common/BUILD +++ b/test/mocks/common/BUILD @@ -87,6 +87,7 @@ envoy_cc_mock( "//include/nighthawk/common:base_includes", ], ) + envoy_cc_mock( name = "mock_request_source_constructor", srcs = ["mock_request_source_constructor.cc"], @@ -95,4 +96,4 @@ envoy_cc_mock( deps = [ "//include/nighthawk/common:base_includes", ], -) \ No newline at end of file +) From 38c50845b802655e41d552152fa1fb9c4ae3aa5e Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 28 Jul 2020 18:27:17 +0000 Subject: [PATCH 024/114] Adding missing request source constructor files. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../common/mock_request_source_constructor.cc | 7 +++++++ .../common/mock_request_source_constructor.h | 17 +++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/mocks/common/mock_request_source_constructor.cc create mode 100644 test/mocks/common/mock_request_source_constructor.h diff --git a/test/mocks/common/mock_request_source_constructor.cc b/test/mocks/common/mock_request_source_constructor.cc new file mode 100644 index 000000000..da515d7f7 --- /dev/null +++ b/test/mocks/common/mock_request_source_constructor.cc @@ -0,0 +1,7 @@ +#include "test/mocks/common/mock_request_source_constructor.h" + +namespace Nighthawk { + +MockRequestSourceConstructor::MockRequestSourceConstructor() = default; + +} // namespace Nighthawk \ No newline at end of file diff --git a/test/mocks/common/mock_request_source_constructor.h b/test/mocks/common/mock_request_source_constructor.h new file mode 100644 index 000000000..c29adc5e2 --- /dev/null +++ b/test/mocks/common/mock_request_source_constructor.h @@ -0,0 +1,17 @@ +#include "nighthawk/common/factories.h" + +#include "gmock/gmock.h" + +namespace Nighthawk { + +class MockRequestSourceConstructor : public RequestSourceConstructorInterface { +public: + MockRequestSourceConstructor(); + MOCK_METHOD(RequestSourcePtr, createStaticRequestSource, + (Envoy::Http::RequestHeaderMapPtr&&, const uint64_t max_yields), (const, override)); + MOCK_METHOD(RequestSourcePtr, createRemoteRequestSource, + (Envoy::Http::RequestHeaderMapPtr && base_header, uint32_t header_buffer_length), + (const, override)); +}; + +} // namespace Nighthawk \ No newline at end of file From fa4e285efbe1ab48e997b961510fc86d5433249e Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 28 Jul 2020 19:49:04 +0000 Subject: [PATCH 025/114] Changing helper functions to anonymous namespace. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 1d3fa8f7a..565b3839f 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -26,7 +26,7 @@ using namespace testing; namespace Nighthawk { -namespace BenchmarkClientTestHelperFunctions { +namespace { // Default function for request generator when the content doesn't matter. RequestGenerator getDefaultRequestGenerator() { RequestGenerator request_generator = []() { @@ -44,7 +44,7 @@ getTestRecordedProperties(const Envoy::Http::RequestHeaderMap& header) { header_set.insert(std::string(header.getPathValue())); return header_set; } -} // namespace BenchmarkClientTestHelperFunctions +} //Helper function namespace class BenchmarkClientHttpTest : public Test { public: @@ -97,7 +97,7 @@ class BenchmarkClientHttpTest : public Test { .WillByDefault( WithArgs<0>(([&called_headers](const Envoy::Http::RequestHeaderMap& specific_request) { called_headers.push_back( - BenchmarkClientTestHelperFunctions::getTestRecordedProperties(specific_request)); + getTestRecordedProperties(specific_request)); }))); EXPECT_CALL(pool_, newStream(_, _)) @@ -195,41 +195,41 @@ class BenchmarkClientHttpTest : public Test { TEST_F(BenchmarkClientHttpTest, BasicTestH1200) { response_code_ = "200"; TestBenchmarkClientProcessesExpectedInflightRequests( - 2, 3, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); + 2, 3, 10, getDefaultRequestGenerator()); EXPECT_EQ(5, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1300) { response_code_ = "300"; TestBenchmarkClientProcessesExpectedInflightRequests( - 0, 11, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); + 0, 11, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, getCounter("http_3xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1404) { response_code_ = "404"; TestBenchmarkClientProcessesExpectedInflightRequests( - 0, 1, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); + 0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_4xx")); } TEST_F(BenchmarkClientHttpTest, WeirdStatus) { response_code_ = "601"; TestBenchmarkClientProcessesExpectedInflightRequests( - 0, 1, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); + 0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_xxx")); } TEST_F(BenchmarkClientHttpTest, EnableLatencyMeasurement) { - setupBenchmarkClient(BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); + setupBenchmarkClient(getDefaultRequestGenerator()); EXPECT_EQ(false, client_->shouldMeasureLatencies()); TestBenchmarkClientProcessesExpectedInflightRequests( - 10, 1, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); + 10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.request_to_response"]->count()); client_->setShouldMeasureLatencies(true); TestBenchmarkClientProcessesExpectedInflightRequests( - 10, 1, 10, BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); + 10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.request_to_response"]->count()); } @@ -240,7 +240,7 @@ TEST_F(BenchmarkClientHttpTest, StatusTrackingInOnComplete) { *api_, *dispatcher_, *store, std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), false, cluster_manager_, http_tracer_, "foo", - BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator(), true); + getDefaultRequestGenerator(), true); Envoy::Http::ResponseHeaderMapPtr header = Envoy::Http::ResponseHeaderMapImpl::create(); header->setStatus(1); @@ -272,7 +272,7 @@ TEST_F(BenchmarkClientHttpTest, StatusTrackingInOnComplete) { } TEST_F(BenchmarkClientHttpTest, PoolFailures) { - setupBenchmarkClient(BenchmarkClientTestHelperFunctions::getDefaultRequestGenerator()); + setupBenchmarkClient(getDefaultRequestGenerator()); client_->onPoolFailure(Envoy::Http::ConnectionPool::PoolFailureReason::LocalConnectionFailure); client_->onPoolFailure(Envoy::Http::ConnectionPool::PoolFailureReason::RemoteConnectionFailure); client_->onPoolFailure(Envoy::Http::ConnectionPool::PoolFailureReason::Overflow); @@ -340,9 +340,9 @@ TEST_F(BenchmarkClientHttpTest, RequestGeneratorProvidingDifferentPathsSendsRequ return std::make_unique(item); }; std::vector> expected_requests_vector; - expected_requests_vector.push_back(BenchmarkClientTestHelperFunctions::getTestRecordedProperties( + expected_requests_vector.push_back(getTestRecordedProperties( Envoy::Http::TestRequestHeaderMapImpl(first_header_map_to_send))); - expected_requests_vector.push_back(BenchmarkClientTestHelperFunctions::getTestRecordedProperties( + expected_requests_vector.push_back(getTestRecordedProperties( Envoy::Http::TestRequestHeaderMapImpl(second_header_map_to_send))); EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); From 8551c7693ba5120550fceb74a428a9f393462e09 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 28 Jul 2020 20:36:11 +0000 Subject: [PATCH 026/114] Changing to use a nullable pointer instead of reference for clarity. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 565b3839f..a934f00a4 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -19,7 +19,6 @@ #include "common/utility.h" #include "client/benchmark_client_impl.h" - #include "gtest/gtest.h" using namespace testing; @@ -83,8 +82,8 @@ class BenchmarkClientHttpTest : public Test { void TestBenchmarkClientProcessesExpectedInflightRequests( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, const RequestGenerator& request_generator, - const std::vector>& header_expectations = - std::vector>()) { + const std::vector>* header_expectations = + nullptr) { if (client_ == nullptr) { setupBenchmarkClient(request_generator); cluster_info().resetResourceManager(connection_limit, max_pending, 1024, 0, 1024); @@ -156,8 +155,8 @@ class BenchmarkClientHttpTest : public Test { dispatcher_->run(Envoy::Event::Dispatcher::RunType::Block); EXPECT_EQ(0, inflight_response_count); // If we have no expectations, then we don't test. - if (header_expectations.size() != 0) { - EXPECT_THAT(header_expectations, UnorderedElementsAreArray(called_headers)); + if (header_expectations != nullptr) { + EXPECT_THAT((*header_expectations), UnorderedElementsAreArray(called_headers)); } } @@ -349,7 +348,7 @@ TEST_F(BenchmarkClientHttpTest, RequestGeneratorProvidingDifferentPathsSendsRequ // Most of the testing happens inside of this call. Will confirm that the requests received match // the expected requests vector. TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 2, request_generator, - expected_requests_vector); + &expected_requests_vector); EXPECT_EQ(2, getCounter("http_2xx")); } } // namespace Nighthawk From 437de5e945b095cf6dc8f3093d74bd5dd26fcc68 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 28 Jul 2020 20:49:17 +0000 Subject: [PATCH 027/114] Formatting fixes per PR. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index a934f00a4..e960ee5be 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -26,6 +26,7 @@ using namespace testing; namespace Nighthawk { namespace { + // Default function for request generator when the content doesn't matter. RequestGenerator getDefaultRequestGenerator() { RequestGenerator request_generator = []() { @@ -222,11 +223,13 @@ TEST_F(BenchmarkClientHttpTest, WeirdStatus) { TEST_F(BenchmarkClientHttpTest, EnableLatencyMeasurement) { setupBenchmarkClient(getDefaultRequestGenerator()); EXPECT_EQ(false, client_->shouldMeasureLatencies()); + TestBenchmarkClientProcessesExpectedInflightRequests( 10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.request_to_response"]->count()); client_->setShouldMeasureLatencies(true); + TestBenchmarkClientProcessesExpectedInflightRequests( 10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); @@ -294,6 +297,7 @@ TEST_F(BenchmarkClientHttpTest, RequestMethodPost) { }; EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(1); + TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } @@ -310,27 +314,29 @@ TEST_F(BenchmarkClientHttpTest, BadContentLength) { }; EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(0); + TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 1, request_generator); EXPECT_EQ(1, getCounter("http_2xx")); } + TEST_F(BenchmarkClientHttpTest, RequestGeneratorProvidingDifferentPathsSendsRequestsOnThosePaths) { std::vector requests_for_generator_to_send; - const std::initializer_list> first_header_map_to_send{ + const std::initializer_list> header_map_for_first_request{ {":scheme", "http"}, {":method", "GET"}, {":path", "/a"}, {":host", "localhost"}, {"Content-Length", "1313"}}; - const std::initializer_list> second_header_map_to_send{ + const std::initializer_list> header_map_for_second_request{ {":scheme", "http"}, {":method", "GET"}, {":path", "/b"}, {":host", "localhost"}, {"Content-Length", "1313"}}; requests_for_generator_to_send.push_back( - std::make_shared(first_header_map_to_send)); + std::make_shared(header_map_for_first_request)); requests_for_generator_to_send.push_back( - std::make_shared(second_header_map_to_send)); + std::make_shared(header_map_for_second_request)); std::vector::iterator request_iterator; request_iterator = requests_for_generator_to_send.begin(); RequestGenerator request_generator = [&]() { @@ -340,11 +346,12 @@ TEST_F(BenchmarkClientHttpTest, RequestGeneratorProvidingDifferentPathsSendsRequ }; std::vector> expected_requests_vector; expected_requests_vector.push_back(getTestRecordedProperties( - Envoy::Http::TestRequestHeaderMapImpl(first_header_map_to_send))); + Envoy::Http::TestRequestHeaderMapImpl(header_map_for_first_request))); expected_requests_vector.push_back(getTestRecordedProperties( - Envoy::Http::TestRequestHeaderMapImpl(second_header_map_to_send))); + Envoy::Http::TestRequestHeaderMapImpl(header_map_for_second_request))); EXPECT_CALL(stream_encoder_, encodeData(_, _)).Times(2); + // Most of the testing happens inside of this call. Will confirm that the requests received match // the expected requests vector. TestBenchmarkClientProcessesExpectedInflightRequests(1, 1, 2, request_generator, From 6cef87e344be7ea92b00e082fb9ed3acda7a9bc4 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 28 Jul 2020 20:51:31 +0000 Subject: [PATCH 028/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index e960ee5be..bac9c31f0 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -19,6 +19,7 @@ #include "common/utility.h" #include "client/benchmark_client_impl.h" + #include "gtest/gtest.h" using namespace testing; @@ -44,7 +45,7 @@ getTestRecordedProperties(const Envoy::Http::RequestHeaderMap& header) { header_set.insert(std::string(header.getPathValue())); return header_set; } -} //Helper function namespace +} // namespace class BenchmarkClientHttpTest : public Test { public: @@ -83,8 +84,7 @@ class BenchmarkClientHttpTest : public Test { void TestBenchmarkClientProcessesExpectedInflightRequests( const uint64_t max_pending, const uint64_t connection_limit, const uint64_t amount_of_request, const RequestGenerator& request_generator, - const std::vector>* header_expectations = - nullptr) { + const std::vector>* header_expectations = nullptr) { if (client_ == nullptr) { setupBenchmarkClient(request_generator); cluster_info().resetResourceManager(connection_limit, max_pending, 1024, 0, 1024); @@ -96,8 +96,7 @@ class BenchmarkClientHttpTest : public Test { ON_CALL(stream_encoder_, encodeHeaders(_, _)) .WillByDefault( WithArgs<0>(([&called_headers](const Envoy::Http::RequestHeaderMap& specific_request) { - called_headers.push_back( - getTestRecordedProperties(specific_request)); + called_headers.push_back(getTestRecordedProperties(specific_request)); }))); EXPECT_CALL(pool_, newStream(_, _)) @@ -194,29 +193,25 @@ class BenchmarkClientHttpTest : public Test { TEST_F(BenchmarkClientHttpTest, BasicTestH1200) { response_code_ = "200"; - TestBenchmarkClientProcessesExpectedInflightRequests( - 2, 3, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(2, 3, 10, getDefaultRequestGenerator()); EXPECT_EQ(5, getCounter("http_2xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1300) { response_code_ = "300"; - TestBenchmarkClientProcessesExpectedInflightRequests( - 0, 11, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(0, 11, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, getCounter("http_3xx")); } TEST_F(BenchmarkClientHttpTest, BasicTestH1404) { response_code_ = "404"; - TestBenchmarkClientProcessesExpectedInflightRequests( - 0, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_4xx")); } TEST_F(BenchmarkClientHttpTest, WeirdStatus) { response_code_ = "601"; - TestBenchmarkClientProcessesExpectedInflightRequests( - 0, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(0, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(1, getCounter("http_xxx")); } @@ -224,14 +219,12 @@ TEST_F(BenchmarkClientHttpTest, EnableLatencyMeasurement) { setupBenchmarkClient(getDefaultRequestGenerator()); EXPECT_EQ(false, client_->shouldMeasureLatencies()); - TestBenchmarkClientProcessesExpectedInflightRequests( - 10, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(0, client_->statistics()["benchmark_http_client.request_to_response"]->count()); client_->setShouldMeasureLatencies(true); - TestBenchmarkClientProcessesExpectedInflightRequests( - 10, 1, 10, getDefaultRequestGenerator()); + TestBenchmarkClientProcessesExpectedInflightRequests(10, 1, 10, getDefaultRequestGenerator()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.queue_to_connect"]->count()); EXPECT_EQ(10, client_->statistics()["benchmark_http_client.request_to_response"]->count()); } From 77d33f9e22919b278d9a51836f602ed5fb45e6dd Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 29 Jul 2020 00:10:04 +0000 Subject: [PATCH 029/114] Fix format after merge. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 95b7cc6fa..deb2b0338 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -80,8 +80,8 @@ class BenchmarkClientHttpTest : public Test { // client_ = std::make_unique( // *api_, *dispatcher_, store_, std::make_unique(), // std::make_unique(), std::make_unique(), - // std::make_unique(), false, cluster_manager_, http_tracer_, "benchmark", - // request_generator, true); + // std::make_unique(), false, cluster_manager_, http_tracer_, + // "benchmark", request_generator, true); // } // Primary testing method. Confirms that connection limits are met and number of requests are // correct. If not empty, also checks the header expectations, if empty, it is ignored. From 73aa68611fa5c3082bb2b33dccf115eb5403eac5 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 29 Jul 2020 00:52:30 +0000 Subject: [PATCH 030/114] Testing a theory. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index deb2b0338..71b91dfe4 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -59,7 +59,8 @@ class BenchmarkClientHttpTest : public Test { std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), - std::make_unique(), std::make_unique()) { + std::make_unique(), std::make_unique()) + { EXPECT_CALL(cluster_manager(), httpConnPoolForCluster(_, _, _, _)) .WillRepeatedly(Return(&pool_)); EXPECT_CALL(cluster_manager(), get(_)).WillRepeatedly(Return(&thread_local_cluster_)); From ef77d653fbb70931eb90c63fc11061c69f942808 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 29 Jul 2020 15:54:44 +0000 Subject: [PATCH 031/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/benchmark_http_client_test.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/benchmark_http_client_test.cc b/test/benchmark_http_client_test.cc index 71b91dfe4..deb2b0338 100644 --- a/test/benchmark_http_client_test.cc +++ b/test/benchmark_http_client_test.cc @@ -59,8 +59,7 @@ class BenchmarkClientHttpTest : public Test { std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), std::make_unique(), - std::make_unique(), std::make_unique()) - { + std::make_unique(), std::make_unique()) { EXPECT_CALL(cluster_manager(), httpConnPoolForCluster(_, _, _, _)) .WillRepeatedly(Return(&pool_)); EXPECT_CALL(cluster_manager(), get(_)).WillRepeatedly(Return(&thread_local_cluster_)); From f827acac47504aff4cc9a7b133899edfccb46850 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 19 Aug 2020 17:58:03 +0000 Subject: [PATCH 032/114] Adding initial protos and stubs. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/request_source/BUILD | 12 ++++- .../request_source_plugin_impl.proto | 12 +++++ include/nighthawk/common/BUILD | 13 ++++++ .../nighthawk/common/request_source_plugin.h | 44 +++++++++++++++++++ source/common/request_source_plugin_impl.cc | 0 source/common/request_source_plugin_impl.h | 36 +++++++++++++++ 6 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 api/request_source/request_source_plugin_impl.proto create mode 100644 include/nighthawk/common/request_source_plugin.h create mode 100644 source/common/request_source_plugin_impl.cc create mode 100644 source/common/request_source_plugin_impl.h diff --git a/api/request_source/BUILD b/api/request_source/BUILD index 4e808f691..da25df27d 100644 --- a/api/request_source/BUILD +++ b/api/request_source/BUILD @@ -15,7 +15,17 @@ api_cc_py_proto_library( "@envoy_api//envoy/api/v2/core:pkg", ], ) - +api_cc_py_proto_library( + name = "request_source_plugin", + srcs = [ + "request_source_plugin_impl.proto", + ], + visibility = ["//visibility:public"], + deps = [ + "@envoy_api//envoy/config/core/v3:pkg", + "@nighthawk//api/client:base", + ], +) cc_grpc_library( name = "grpc_request_source_service_lib", srcs = [ diff --git a/api/request_source/request_source_plugin_impl.proto b/api/request_source/request_source_plugin_impl.proto new file mode 100644 index 000000000..55d2126ae --- /dev/null +++ b/api/request_source/request_source_plugin_impl.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package nighthawk.request_source; + +import "google/protobuf/wrappers.proto"; + +// Configuration for DummyPluginRequestSource (plugin name: "nighthawk.dummy") that does nothing +message DummyPluginRequestSourceConfig { + // Dummy input value. + google.protobuf.DoubleValue dummy_value = 1; + } + \ No newline at end of file diff --git a/include/nighthawk/common/BUILD b/include/nighthawk/common/BUILD index c6eb60b40..75ed4e894 100644 --- a/include/nighthawk/common/BUILD +++ b/include/nighthawk/common/BUILD @@ -47,6 +47,19 @@ envoy_basic_cc_library( "@envoy//source/common/http:headers_lib", ], ) +envoy_basic_cc_library( + name = "request_source_plugin_lib", + hdrs = [ + "request_source_plugin.h", + ], + include_prefix = "nighthawk/common", + deps = [ + ":request_source_lib", + "//api/request_source:request_source_plugin_cc_proto", + "@envoy//include/envoy/common:base_includes", + "@envoy//include/envoy/config:typed_config_interface", + ], +) envoy_basic_cc_library( name = "request_source_lib", diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h new file mode 100644 index 000000000..d6e4191e1 --- /dev/null +++ b/include/nighthawk/common/request_source_plugin.h @@ -0,0 +1,44 @@ +#pragma once + +#include "envoy/common/pure.h" +#include "envoy/config/typed_config.h" +#include "external/envoy/source/common/common/statusor.h" +#include "nighthawk/common/request_source.h" + + +namespace Nighthawk { + +/** + * An interface for different RequestSource plugins. + * Uses a plugin-specific config proto. + */ +class RequestSourcePlugin : RequestSource { +public: + virtual ~RequestSourcePlugin() = default; + +}; + + +/** + * A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific + * RequestSourcePlugin class after unpacking the plugin-specific config proto. + */ +class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { +public: + ~RequestSourcePluginConfigFactory() override = default; + std::string category() const override { return "nighthawk.request_source_plugin"; } + /** + * Instantiates the specific RequestSourcePlugin class. Casts |message| to Any, unpacks it to the + * plugin-specific proto, and passes the strongly typed proto to the plugin constructor. + * + * @param message Any typed_config proto taken from the TypedExtensionConfig. + * + * @return RequestSourcePtr Pointer to the new plugin instance. + * + * @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the + * plugin. + */ + virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) PURE; +}; + +} // namespace Nighthawk \ No newline at end of file diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc new file mode 100644 index 000000000..e69de29bb diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h new file mode 100644 index 000000000..f2296b499 --- /dev/null +++ b/source/common/request_source_plugin_impl.h @@ -0,0 +1,36 @@ +#pragma once + +#include "envoy/registry/registry.h" + +#include "nighthawk/common/request_source_plugin.h" + +#include "api/request_source/request_source_plugin_impl.pb.h" + +namespace Nighthawk { + +/** + */ +class DummyRequestSourcePlugin : public RequestSourcePlugin { +public: + explicit DummyRequestSourcePlugin( + const nighthawk::request_source_plugin::DummyPluginRequestSourceConfig& config); + +private: + const double dummy_value_; +}; + +/** + * Factory that creates a DummyRequestSourcePlugin from a DummyRequestSourcePluginConfig proto. + * Registered as an Envoy plugin. + */ +class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory +{ +public: + std::string name() const override; + Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; + RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) override; +}; + +// This factory is activated through ???. +DECLARE_FACTORY(DummyRequestSourceConfigFactory); +} \ No newline at end of file From d1947361c03f9fbc6817b7502a667d50c78bc660 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 19 Aug 2020 18:59:31 +0000 Subject: [PATCH 033/114] Adding impl for Dummy request source plugin. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../nighthawk/common/request_source_plugin.h | 9 ++-- source/common/BUILD | 18 ++++++++ source/common/request_source_plugin_impl.cc | 41 +++++++++++++++++++ source/common/request_source_plugin_impl.h | 11 ++++- 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index d6e4191e1..eae0c9c62 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -2,7 +2,6 @@ #include "envoy/common/pure.h" #include "envoy/config/typed_config.h" -#include "external/envoy/source/common/common/statusor.h" #include "nighthawk/common/request_source.h" @@ -15,9 +14,11 @@ namespace Nighthawk { class RequestSourcePlugin : RequestSource { public: virtual ~RequestSourcePlugin() = default; + virtual RequestGenerator get() PURE; + virtual void initOnThread() PURE; }; - +using RequestSourcePluginPtr = std::unique_ptr; /** * A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific @@ -33,12 +34,12 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * * @param message Any typed_config proto taken from the TypedExtensionConfig. * - * @return RequestSourcePtr Pointer to the new plugin instance. + * @return RequestSourcePluginPtr Pointer to the new plugin instance. * * @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the * plugin. */ - virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) PURE; + virtual RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) PURE; }; } // namespace Nighthawk \ No newline at end of file diff --git a/source/common/BUILD b/source/common/BUILD index a18abb833..83f0292b7 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -60,6 +60,24 @@ envoy_cc_library( "//include/nighthawk/common:request_source_lib", ], ) +envoy_cc_library( + name = "request_source_plugin_impl", + srcs = [ + "request_source_plugin_impl.cc", + ], + hdrs = [ + "request_source_plugin_impl.h", + ], + repository = "@envoy", + visibility = ["//visibility:public"], + deps = [ + "//include/nighthawk/common:request_source_plugin_lib", + ":request_impl_lib", + ":request_source_impl_lib", + "@envoy//source/common/config:utility_lib_with_external_headers", + "@envoy//source/common/protobuf:protobuf_with_external_headers", + ], +) envoy_cc_library( name = "version_linkstamp", diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index e69de29bb..f1885686f 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -0,0 +1,41 @@ +#include "common/request_source_plugin_impl.h" +#include "common/request_impl.h" +#include "common/request_source_impl.h" +#include "external/envoy/source/common/protobuf/protobuf.h" + +#include "api/request_source/request_source_plugin_impl.pb.h" + +namespace Nighthawk { + +std::string DummyRequestSourceConfigFactory::name() const { + return "nighthawk.dummy-request-source-plugin"; +} + +Envoy::ProtobufTypes::MessagePtr DummyRequestSourceConfigFactory::createEmptyConfigProto() { + return std::make_unique(); +} + +RequestSourcePluginPtr DummyRequestSourceConfigFactory::createRequestSourcePlugin( + const Envoy::Protobuf::Message& message) { + const auto& any = dynamic_cast(message); + nighthawk::request_source::DummyPluginRequestSourceConfig config; + Envoy::MessageUtil::unpackTo(any, config); + return std::make_unique(config); +} + +REGISTER_FACTORY(DummyRequestSourceConfigFactory, RequestSourcePluginConfigFactory); + +DummyRequestSourcePlugin::DummyRequestSourcePlugin( + const nighthawk::request_source::DummyPluginRequestSourceConfig& config) + : dummy_value_{config.has_dummy_value() ? config.dummy_value().value() + : std::numeric_limits::infinity()} {} +RequestGenerator DummyRequestSourcePlugin::get() { + RequestGenerator request_generator = []() { + Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); + auto returned_request_impl = std::make_unique(std::move(header)); + return returned_request_impl; + }; + return request_generator; +} +void DummyRequestSourcePlugin::initOnThread() {} +} // namespace Nighthawk \ No newline at end of file diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index f2296b499..2ac495028 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -13,7 +13,14 @@ namespace Nighthawk { class DummyRequestSourcePlugin : public RequestSourcePlugin { public: explicit DummyRequestSourcePlugin( - const nighthawk::request_source_plugin::DummyPluginRequestSourceConfig& config); + const nighthawk::request_source::DummyPluginRequestSourceConfig& config); + RequestGenerator get() override; + /** + * Will be called on an intialized and running worker thread, before commencing actual work. + * Can be used to prepare the request source implementation (opening any connection or files + * needed, for example). + */ + void initOnThread() override; private: const double dummy_value_; @@ -28,7 +35,7 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig public: std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) override; + RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) override; }; // This factory is activated through ???. From 7820cf90beff1dd9bf407e44fe1ea8ced0ea5066 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 19 Aug 2020 20:51:38 +0000 Subject: [PATCH 034/114] Adding test for request source factory creation. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/request_source/BUILD | 19 +++++++++ .../request_source_plugin_test.cc | 41 +++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 test/request_source/BUILD create mode 100644 test/request_source/request_source_plugin_test.cc diff --git a/test/request_source/BUILD b/test/request_source/BUILD new file mode 100644 index 000000000..0059b7e8b --- /dev/null +++ b/test/request_source/BUILD @@ -0,0 +1,19 @@ +load( + "@envoy//bazel:envoy_build_system.bzl", + "envoy_cc_test", + "envoy_cc_test_library", + "envoy_package", +) + +licenses(["notice"]) # Apache 2 + +envoy_package() + +envoy_cc_test( + name = "request_source_plugin_test", + srcs = ["request_source_plugin_test.cc"], + repository = "@envoy", + deps = [ + "//source/common:request_source_plugin_impl", + ], +) diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc new file mode 100644 index 000000000..6f706512f --- /dev/null +++ b/test/request_source/request_source_plugin_test.cc @@ -0,0 +1,41 @@ +#include "envoy/common/exception.h" +#include "common/request_source_plugin_impl.h" +#include "external/envoy/source/common/config/utility.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +namespace Nighthawk { + +namespace { +using nighthawk::request_source::DummyPluginRequestSourceConfig; +TEST(DummyPluginRequestSourceConfigFactory, CreateEmptyConfigProtoCreatesCorrectType) { + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.dummy-request-source-plugin"); + const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); + const nighthawk::request_source::DummyPluginRequestSourceConfig expected_config; + EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); + EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); +} +TEST(DummyPluginRequestSourceConfigFactory, FactoryRegistrationUsesCorrectPluginName) { + nighthawk::request_source::DummyPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.dummy-request-source-plugin"); + EXPECT_EQ(config_factory.name(), "nighthawk.dummy-request-source-plugin"); +} +TEST(DummyPluginRequestSourceConfigFactory, CreateRequestSourcePluginCreatesCorrectPluginType) { + nighthawk::request_source::DummyPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.dummy-request-source-plugin"); + RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any); + EXPECT_NE(dynamic_cast(plugin.get()), nullptr); +} +} // namespace +} // namespace Nighthawk From bee7805bd657069fec03b5b20b41aab7497e42fa Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 19 Aug 2020 21:52:34 +0000 Subject: [PATCH 035/114] Adding some more protos. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/request_source/request_source_plugin_impl.proto | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/api/request_source/request_source_plugin_impl.proto b/api/request_source/request_source_plugin_impl.proto index 55d2126ae..76ad22ce3 100644 --- a/api/request_source/request_source_plugin_impl.proto +++ b/api/request_source/request_source_plugin_impl.proto @@ -4,9 +4,16 @@ package nighthawk.request_source; import "google/protobuf/wrappers.proto"; -// Configuration for DummyPluginRequestSource (plugin name: "nighthawk.dummy") that does nothing +// Configuration for DummyPluginRequestSource (plugin name: "nighthawk.dummy-request-source-plugin") that does nothing message DummyPluginRequestSourceConfig { // Dummy input value. google.protobuf.DoubleValue dummy_value = 1; } - \ No newline at end of file +// Configuration for RPCPluginRequestSource (plugin name: "nighthawk.rpc-request-source-plugin") that uses rpc +message RPCPluginRequestSourceConfig { + string uri = 1; +} +// Configuration for FileBasedPluginRequestSource (plugin name: "nighthawk.file-based-request-source-plugin") that uses rpc +message FileBasedPluginRequestSourceConfig { + string uri = 1; +} From a1dd3f26baeea7568afe234549a1f0ebd1e8c80a Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 20 Aug 2020 18:48:18 +0000 Subject: [PATCH 036/114] Fixing mockrequestsourcefactory impacted by the refactor. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/client_worker_test.cc | 2 +- test/mocks/common/mock_request_source_factory.h | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/test/client_worker_test.cc b/test/client_worker_test.cc index 8ffdf6680..5cf26d0e7 100644 --- a/test/client_worker_test.cc +++ b/test/client_worker_test.cc @@ -51,7 +51,7 @@ class ClientWorkerTest : public Test { .Times(1) .WillOnce(Return(ByMove(std::unique_ptr(sequencer_)))); - EXPECT_CALL(request_generator_factory_, create(_, _, _, _)) + EXPECT_CALL(request_generator_factory_, create(_)) .Times(1) .WillOnce(Return(ByMove(std::unique_ptr(request_generator_)))); EXPECT_CALL(*request_generator_, initOnThread()).Times(1); diff --git a/test/mocks/common/mock_request_source_factory.h b/test/mocks/common/mock_request_source_factory.h index 60f277e5b..8defaa9bb 100644 --- a/test/mocks/common/mock_request_source_factory.h +++ b/test/mocks/common/mock_request_source_factory.h @@ -9,11 +9,8 @@ namespace Nighthawk { class MockRequestSourceFactory : public RequestSourceFactory { public: MockRequestSourceFactory(); - MOCK_CONST_METHOD4(create, - RequestSourcePtr(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, - Envoy::Event::Dispatcher& dispatcher, - Envoy::Stats::Scope& scope, - absl::string_view service_cluster_name)); + MOCK_CONST_METHOD1(create, + RequestSourcePtr(const RequestSourceConstructorInterface& request_source_constructor)); }; } // namespace Nighthawk \ No newline at end of file From 0b25261f686c7d6096c4354aa03e7393fa6e13b5 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 20 Aug 2020 19:28:56 +0000 Subject: [PATCH 037/114] Adding more factories to the impl.h Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.h | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 2ac495028..b4878e4e6 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -40,4 +40,69 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig // This factory is activated through ???. DECLARE_FACTORY(DummyRequestSourceConfigFactory); + +/** + */ +class RPCRequestSourcePlugin : public RequestSourcePlugin { +public: + explicit RPCRequestSourcePlugin( + const nighthawk::request_source::RPCPluginRequestSourceConfig& config); + RequestGenerator get() override; + /** + * Will be called on an intialized and running worker thread, before commencing actual work. + * Can be used to prepare the request source implementation (opening any connection or files + * needed, for example). + */ + void initOnThread() override; + +private: + const std::string uri_; +}; + +/** + * Registered as an Envoy plugin. + */ +class RPCRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory +{ +public: + std::string name() const override; + Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; + RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) override; +}; + +// This factory is activated through ???. +DECLARE_FACTORY(RPCRequestSourceConfigFactory); + +/** + */ +class FileBasedRequestSourcePlugin : public RequestSourcePlugin { +public: + explicit FileBasedRequestSourcePlugin( + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config); + RequestGenerator get() override; + /** + * Will be called on an intialized and running worker thread, before commencing actual work. + * Can be used to prepare the request source implementation (opening any connection or files + * needed, for example). + */ + void initOnThread() override; + +private: + const std::string uri_; +}; + +/** + * Registered as an Envoy plugin. + */ +class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory +{ +public: + std::string name() const override; + Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; + RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) override; +}; + +// This factory is activated through ???. +DECLARE_FACTORY(FileBasedRequestSourceConfigFactory); + } \ No newline at end of file From c3fa23c45ff729f801908d93bbecbd5f1de12c46 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 20 Aug 2020 19:30:48 +0000 Subject: [PATCH 038/114] Fixing clang tidy. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/client/factories_impl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/source/client/factories_impl.h b/source/client/factories_impl.h index be612ba94..53ad1308d 100644 --- a/source/client/factories_impl.h +++ b/source/client/factories_impl.h @@ -57,7 +57,6 @@ class OutputFormatterFactoryImpl : public OutputFormatterFactory { }; class RequestSourceConstructorImpl : public RequestSourceConstructorInterface { public: - virtual ~RequestSourceConstructorImpl() = default; RequestSourceConstructorImpl(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, absl::string_view service_cluster_name); From 547977e9637285af0ff4cacbb6675d89a8159053 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 20 Aug 2020 21:01:37 +0000 Subject: [PATCH 039/114] Updating the impl.cc with a stub for the new factories. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 65 +++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index f1885686f..520acba42 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -38,4 +38,69 @@ RequestGenerator DummyRequestSourcePlugin::get() { return request_generator; } void DummyRequestSourcePlugin::initOnThread() {} + + +std::string RPCRequestSourceConfigFactory::name() const { + return "nighthawk.rpc-request-source-plugin"; +} + +Envoy::ProtobufTypes::MessagePtr RPCRequestSourceConfigFactory::createEmptyConfigProto() { + return std::make_unique(); +} + +RequestSourcePluginPtr RPCRequestSourceConfigFactory::createRequestSourcePlugin( + const Envoy::Protobuf::Message& message) { + const auto& any = dynamic_cast(message); + nighthawk::request_source::RPCPluginRequestSourceConfig config; + Envoy::MessageUtil::unpackTo(any, config); + return std::make_unique(config); +} + +REGISTER_FACTORY(RPCRequestSourceConfigFactory, RequestSourcePluginConfigFactory); + +RPCRequestSourcePlugin::RPCRequestSourcePlugin( + const nighthawk::request_source::RPCPluginRequestSourceConfig& config) + : uri_(config.uri()) {} +RequestGenerator RPCRequestSourcePlugin::get() { + RequestGenerator request_generator = []() { + Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); + auto returned_request_impl = std::make_unique(std::move(header)); + return returned_request_impl; + }; + return request_generator; +} +void RPCRequestSourcePlugin::initOnThread() {} + + +std::string FileBasedRequestSourceConfigFactory::name() const { + return "nighthawk.file-based-request-source-plugin"; +} + +Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourceConfigFactory::createEmptyConfigProto() { + return std::make_unique(); +} + +RequestSourcePluginPtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( + const Envoy::Protobuf::Message& message) { + const auto& any = dynamic_cast(message); + nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + Envoy::MessageUtil::unpackTo(any, config); + return std::make_unique(config); +} + +REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); + +FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config) + : uri_(config.uri()) {} +RequestGenerator FileBasedRequestSourcePlugin::get() { + RequestGenerator request_generator = []() { + Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); + auto returned_request_impl = std::make_unique(std::move(header)); + return returned_request_impl; + }; + return request_generator; +} +void FileBasedRequestSourcePlugin::initOnThread() {} + } // namespace Nighthawk \ No newline at end of file From c300203d530b71af953cb4c1d622b46b2d5d6730 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 26 Aug 2020 05:48:30 +0000 Subject: [PATCH 040/114] Adding test for file based request source plugin Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 29 +++++++++---- source/common/request_source_plugin_impl.h | 3 ++ .../request_source_plugin_test.cc | 41 +++++++++++++++++++ 3 files changed, 65 insertions(+), 8 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 520acba42..6685b97da 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -3,8 +3,11 @@ #include "common/request_source_impl.h" #include "external/envoy/source/common/protobuf/protobuf.h" +#include "api/client/options.pb.h" #include "api/request_source/request_source_plugin_impl.pb.h" - +#include +#include +#include namespace Nighthawk { std::string DummyRequestSourceConfigFactory::name() const { @@ -39,7 +42,6 @@ RequestGenerator DummyRequestSourcePlugin::get() { } void DummyRequestSourcePlugin::initOnThread() {} - std::string RPCRequestSourceConfigFactory::name() const { return "nighthawk.rpc-request-source-plugin"; } @@ -48,8 +50,8 @@ Envoy::ProtobufTypes::MessagePtr RPCRequestSourceConfigFactory::createEmptyConfi return std::make_unique(); } -RequestSourcePluginPtr RPCRequestSourceConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message) { +RequestSourcePluginPtr +RPCRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message) { const auto& any = dynamic_cast(message); nighthawk::request_source::RPCPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); @@ -71,7 +73,6 @@ RequestGenerator RPCRequestSourcePlugin::get() { } void RPCRequestSourcePlugin::initOnThread() {} - std::string FileBasedRequestSourceConfigFactory::name() const { return "nighthawk.file-based-request-source-plugin"; } @@ -92,15 +93,27 @@ REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigF FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config) - : uri_(config.uri()) {} + : uri_(config.uri()) { + // Envoy::MessageUtil::loadFromJson() + std::ifstream options_file(uri_, std::ifstream::binary); + options_.ParseFromIstream(&options_file); + options_file.close(); +} RequestGenerator FileBasedRequestSourcePlugin::get() { RequestGenerator request_generator = []() { - Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); + // auto returned_request_impl = std::make_unique(std::move(options_.request_headers())); + Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); auto returned_request_impl = std::make_unique(std::move(header)); return returned_request_impl; }; return request_generator; } -void FileBasedRequestSourcePlugin::initOnThread() {} +void FileBasedRequestSourcePlugin::initOnThread() { + // options_.set_request_method(::envoy::config::core::v3::RequestMethod::GET); + // auto request_headers = options_.add_request_headers(); + // request_headers->mutable_header()->set_key("foo"); + // request_headers->mutable_header()->set_value("bar"); + // options_.set_allocated_request_body_size(0); +} } // namespace Nighthawk \ No newline at end of file diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index b4878e4e6..c7a440af7 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -5,6 +5,8 @@ #include "nighthawk/common/request_source_plugin.h" #include "api/request_source/request_source_plugin_impl.pb.h" +#include "api/client/options.pb.h" +#include namespace Nighthawk { @@ -89,6 +91,7 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { private: const std::string uri_; + nighthawk::client::RequestOptions options_; }; /** diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 6f706512f..9bd8f735d 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -9,6 +9,13 @@ namespace Nighthawk { namespace { using nighthawk::request_source::DummyPluginRequestSourceConfig; +using nighthawk::request_source::FileBasedPluginRequestSourceConfig; + +nighthawk::request_source::FileBasedPluginRequestSourceConfig MakeFileBasedPluginConfigWithTestYaml(std::string request_file) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + config.mutable_uri()->assign(request_file); + return config; +} TEST(DummyPluginRequestSourceConfigFactory, CreateEmptyConfigProtoCreatesCorrectType) { auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( @@ -37,5 +44,39 @@ TEST(DummyPluginRequestSourceConfigFactory, CreateRequestSourcePluginCreatesCorr RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } +TEST(FileBasedPluginRequestSourceConfigFactory, CreateEmptyConfigProtoCreatesCorrectType) { + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); + const nighthawk::request_source::FileBasedPluginRequestSourceConfig expected_config; + EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); + EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); +} +TEST(FileBasedPluginRequestSourceConfigFactory, FactoryRegistrationUsesCorrectPluginName) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + EXPECT_EQ(config_factory.name(), "nighthawk.file-based-request-source-plugin"); +} +TEST(FileBasedPluginRequestSourceConfigFactory, CreateRequestSourcePluginCreatesCorrectPluginType) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any); + EXPECT_NE(dynamic_cast(plugin.get()), nullptr); +} +TEST(FileBasedPluginRequestSourceConfigFactory, CreateRequestSourcePluginGetsWorkingRequestGenerator) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml("test-config.yaml"); + FileBasedRequestSourcePlugin file_based_request_source(config); + // auto generator = file_based_request_source.get(); + // auto request = generator(); +} } // namespace } // namespace Nighthawk From 8f4d4d9df57eac23d979c6f2feec7617ea90a42d Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 26 Aug 2020 05:49:40 +0000 Subject: [PATCH 041/114] Adding test yaml file. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test-config.yaml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 test-config.yaml diff --git a/test-config.yaml b/test-config.yaml new file mode 100644 index 000000000..43bcb55ea --- /dev/null +++ b/test-config.yaml @@ -0,0 +1,6 @@ +config: +response_body_size: 10 +response_headers: + - { header: { key: "foo", value: "bar" } } + - { header: { key: "foo", value: "bar2" }, append: true, } + - { header: { key: "x-nh", value: "1" } } From fe74b6d9514d64bd505f400a9587ba1d800c114f Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 27 Aug 2020 21:21:31 +0000 Subject: [PATCH 042/114] First try getting requests working. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/BUILD | 4 +++- source/common/request_source_plugin_impl.cc | 23 ++++++++++++++++--- test-config.yaml | 6 ----- test/request_source/BUILD | 5 ++++ .../request_source_plugin_test.cc | 3 ++- .../request_source/test_data/test-config.yaml | 5 ++++ 6 files changed, 35 insertions(+), 11 deletions(-) delete mode 100644 test-config.yaml create mode 100644 test/request_source/test_data/test-config.yaml diff --git a/source/common/BUILD b/source/common/BUILD index 83f0292b7..57e77b045 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -71,10 +71,12 @@ envoy_cc_library( repository = "@envoy", visibility = ["//visibility:public"], deps = [ + "//source/common:nighthawk_common_lib", "//include/nighthawk/common:request_source_plugin_lib", + "@envoy//source/common/protobuf:message_validator_lib", ":request_impl_lib", ":request_source_impl_lib", - "@envoy//source/common/config:utility_lib_with_external_headers", + "@envoy//source/common/protobuf:utility_lib_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", ], ) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 6685b97da..bd7d7ccaf 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -1,7 +1,9 @@ #include "common/request_source_plugin_impl.h" #include "common/request_impl.h" #include "common/request_source_impl.h" -#include "external/envoy/source/common/protobuf/protobuf.h" +// #include "external/envoy/source/common/protobuf/protobuf.h" +#include "external/envoy/source/common/protobuf/utility.h" +#include "common/protobuf/message_validator_impl.h" #include "api/client/options.pb.h" #include "api/request_source/request_source_plugin_impl.pb.h" @@ -95,9 +97,24 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config) : uri_(config.uri()) { // Envoy::MessageUtil::loadFromJson() - std::ifstream options_file(uri_, std::ifstream::binary); - options_.ParseFromIstream(&options_file); + std::ifstream options_file(uri_); + if (options_file.is_open()) + { + std::cerr << "Opened file: " + uri_; + } + // options_.ParseFromIstream(&options_file); + std::stringstream file_string_stream; + file_string_stream << options_file.rdbuf(); + std::string test_string = file_string_stream.str(); + Envoy::MessageUtil util; + util.loadFromYaml(test_string, options_, Envoy::ProtobufMessage::getStrictValidationVisitor()); + for (const auto& option_header : options_.request_headers()) { + std::cerr << option_header.header().key() +":"+ option_header.header().value()+"\n"; + } options_file.close(); + std::cerr << "\ntest_string" +test_string; + std::cerr << "\nI was here"; + std::cerr << "header size:" + std::to_string(options_.request_headers_size()); } RequestGenerator FileBasedRequestSourcePlugin::get() { RequestGenerator request_generator = []() { diff --git a/test-config.yaml b/test-config.yaml deleted file mode 100644 index 43bcb55ea..000000000 --- a/test-config.yaml +++ /dev/null @@ -1,6 +0,0 @@ -config: -response_body_size: 10 -response_headers: - - { header: { key: "foo", value: "bar" } } - - { header: { key: "foo", value: "bar2" }, append: true, } - - { header: { key: "x-nh", value: "1" } } diff --git a/test/request_source/BUILD b/test/request_source/BUILD index 0059b7e8b..d70bc01f7 100644 --- a/test/request_source/BUILD +++ b/test/request_source/BUILD @@ -14,6 +14,11 @@ envoy_cc_test( srcs = ["request_source_plugin_test.cc"], repository = "@envoy", deps = [ + "//test/test_common:environment_lib", "//source/common:request_source_plugin_impl", + "@envoy//source/common/config:utility_lib_with_external_headers", + ], + data = [ + "test_data/test-config.yaml", ], ) diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 9bd8f735d..0eb366027 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -4,6 +4,7 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +#include "test/test_common/environment.h" namespace Nighthawk { @@ -73,7 +74,7 @@ TEST(FileBasedPluginRequestSourceConfigFactory, CreateRequestSourcePluginCreates EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } TEST(FileBasedPluginRequestSourceConfigFactory, CreateRequestSourcePluginGetsWorkingRequestGenerator) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml("test-config.yaml"); + nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml(TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); FileBasedRequestSourcePlugin file_based_request_source(config); // auto generator = file_based_request_source.get(); // auto request = generator(); diff --git a/test/request_source/test_data/test-config.yaml b/test/request_source/test_data/test-config.yaml new file mode 100644 index 000000000..c8af0cab4 --- /dev/null +++ b/test/request_source/test_data/test-config.yaml @@ -0,0 +1,5 @@ +request_body_size: 10 +request_headers: + - { header: { key: "foo", value: "bar" } } + - { header: { key: "foo", value: "bar2" }, append: true } + - { header: { key: "x-nh", value: "1" } } From 6d87aead2715f515b9dba53b85c2cbc0728447e1 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 1 Sep 2020 18:50:15 +0000 Subject: [PATCH 043/114] Switching to using multiple requestOptions instead of one. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/client/options.proto | 4 ++ .../request_source_plugin_impl.proto | 1 + source/common/BUILD | 4 +- source/common/request_source_plugin_impl.cc | 64 ++++++++++++------- source/common/request_source_plugin_impl.h | 8 ++- .../request_source_plugin_test.cc | 7 +- .../request_source/test_data/test-config.yaml | 16 +++-- 7 files changed, 69 insertions(+), 35 deletions(-) diff --git a/api/client/options.proto b/api/client/options.proto index 0cfd8bf30..46a1d7259 100644 --- a/api/client/options.proto +++ b/api/client/options.proto @@ -18,6 +18,10 @@ message RequestOptions { google.protobuf.UInt32Value request_body_size = 3 [(validate.rules).uint32 = {lte: 4194304}]; } +message RequestOptionses { + repeated RequestOptions sub_options = 1; +} + // Configures a remote gRPC source that will deliver to-be-replayed request data to Nighthawks // workers. message RequestSource { diff --git a/api/request_source/request_source_plugin_impl.proto b/api/request_source/request_source_plugin_impl.proto index 76ad22ce3..e7d571cfd 100644 --- a/api/request_source/request_source_plugin_impl.proto +++ b/api/request_source/request_source_plugin_impl.proto @@ -16,4 +16,5 @@ message RPCPluginRequestSourceConfig { // Configuration for FileBasedPluginRequestSource (plugin name: "nighthawk.file-based-request-source-plugin") that uses rpc message FileBasedPluginRequestSourceConfig { string uri = 1; + string file_path = 2; } diff --git a/source/common/BUILD b/source/common/BUILD index 57e77b045..fee76a9f9 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -71,11 +71,13 @@ envoy_cc_library( repository = "@envoy", visibility = ["//visibility:public"], deps = [ - "//source/common:nighthawk_common_lib", + ":nighthawk_common_lib", "//include/nighthawk/common:request_source_plugin_lib", "@envoy//source/common/protobuf:message_validator_lib", ":request_impl_lib", ":request_source_impl_lib", + "@envoy//source/exe:platform_header_lib_with_external_headers", + "@envoy//source/exe:platform_impl_lib", "@envoy//source/common/protobuf:utility_lib_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", ], diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index bd7d7ccaf..6d945420c 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -1,11 +1,14 @@ #include "common/request_source_plugin_impl.h" #include "common/request_impl.h" #include "common/request_source_impl.h" -// #include "external/envoy/source/common/protobuf/protobuf.h" #include "external/envoy/source/common/protobuf/utility.h" #include "common/protobuf/message_validator_impl.h" +#include "external/envoy/source/exe/platform_impl.h" + + #include "api/client/options.pb.h" + #include "api/request_source/request_source_plugin_impl.pb.h" #include #include @@ -88,38 +91,53 @@ RequestSourcePluginPtr FileBasedRequestSourceConfigFactory::createRequestSourceP const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); - return std::make_unique(config); + Envoy::PlatformImpl platform_impl_; + return std::make_unique(config, platform_impl_.fileSystem()); } REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config) - : uri_(config.uri()) { + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, Envoy::Filesystem::Instance& file_system) + : uri_(config.uri()), file_path_(config.file_path()) { // Envoy::MessageUtil::loadFromJson() - std::ifstream options_file(uri_); - if (options_file.is_open()) - { - std::cerr << "Opened file: " + uri_; - } - // options_.ParseFromIstream(&options_file); - std::stringstream file_string_stream; - file_string_stream << options_file.rdbuf(); - std::string test_string = file_string_stream.str(); + // std::ifstream options_file(file_path_); + // if (options_file.is_open()) + // { + // std::cerr << "Opened file: " + file_path_; + // } + // // options_.ParseFromIstream(&options_file); + // std::stringstream file_string_stream; + // file_string_stream << options_file.rdbuf(); + // std::string test_string = file_string_stream.str(); + // Envoy::MessageUtil util; + // util.loadFromYaml(test_string, options_, Envoy::ProtobufMessage::getStrictValidationVisitor()); + // for (const auto& option_header : options_.request_headers()) { + // std::cerr << option_header.header().key() +":"+ option_header.header().value()+"\n"; + // } + // options_file.close(); Envoy::MessageUtil util; - util.loadFromYaml(test_string, options_, Envoy::ProtobufMessage::getStrictValidationVisitor()); - for (const auto& option_header : options_.request_headers()) { - std::cerr << option_header.header().key() +":"+ option_header.header().value()+"\n"; - } - options_file.close(); - std::cerr << "\ntest_string" +test_string; - std::cerr << "\nI was here"; - std::cerr << "header size:" + std::to_string(options_.request_headers_size()); + std::string file_string = file_system.fileReadToEnd(file_path_); + util.loadFromYaml(file_string, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor()); + std::cerr << "\n"+ file_string +"\n"; } + RequestGenerator FileBasedRequestSourcePlugin::get() { - RequestGenerator request_generator = []() { + auto iterator = optionses_.sub_options().begin(); + RequestGenerator request_generator = [this, &iterator]() { + auto temp = *iterator++; // auto returned_request_impl = std::make_unique(std::move(options_.request_headers())); - Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); + Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); + header->setPath(uri_.path()); + header->setHost(uri_.hostAndPort()); + header->setScheme(uri_.scheme() == "https" ? Envoy::Http::Headers::get().SchemeValues.Https + : Envoy::Http::Headers::get().SchemeValues.Http); + header->setMethod(envoy::config::core::v3::RequestMethod_Name(temp.request_method())); + // const uint32_t content_length = temp.request_body_size(); + // if (content_length > 0) { + // header->setContentLength(content_length); + // } + auto returned_request_impl = std::make_unique(std::move(header)); return returned_request_impl; }; diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index c7a440af7..dfc4abcd2 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -6,7 +6,7 @@ #include "api/request_source/request_source_plugin_impl.pb.h" #include "api/client/options.pb.h" -#include +#include "common/uri_impl.h" namespace Nighthawk { @@ -80,7 +80,7 @@ DECLARE_FACTORY(RPCRequestSourceConfigFactory); class FileBasedRequestSourcePlugin : public RequestSourcePlugin { public: explicit FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config); + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, Envoy::Filesystem::Instance& file_system); RequestGenerator get() override; /** * Will be called on an intialized and running worker thread, before commencing actual work. @@ -90,8 +90,10 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { void initOnThread() override; private: - const std::string uri_; + const Nighthawk::UriImpl uri_; + const std::string file_path_; nighthawk::client::RequestOptions options_; + nighthawk::client::RequestOptionses optionses_; }; /** diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 0eb366027..5a557dcb3 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -1,7 +1,7 @@ #include "envoy/common/exception.h" #include "common/request_source_plugin_impl.h" #include "external/envoy/source/common/config/utility.h" - +#include "external/envoy/test/test_common/file_system_for_test.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "test/test_common/environment.h" @@ -14,7 +14,8 @@ using nighthawk::request_source::FileBasedPluginRequestSourceConfig; nighthawk::request_source::FileBasedPluginRequestSourceConfig MakeFileBasedPluginConfigWithTestYaml(std::string request_file) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config; - config.mutable_uri()->assign(request_file); + config.mutable_uri()->assign("http://foo/"); + config.mutable_file_path()-> assign(request_file); return config; } TEST(DummyPluginRequestSourceConfigFactory, CreateEmptyConfigProtoCreatesCorrectType) { @@ -75,7 +76,7 @@ TEST(FileBasedPluginRequestSourceConfigFactory, CreateRequestSourcePluginCreates } TEST(FileBasedPluginRequestSourceConfigFactory, CreateRequestSourcePluginGetsWorkingRequestGenerator) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml(TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); - FileBasedRequestSourcePlugin file_based_request_source(config); + FileBasedRequestSourcePlugin file_based_request_source(config, Envoy::Filesystem::fileSystemForTest()); // auto generator = file_based_request_source.get(); // auto request = generator(); } diff --git a/test/request_source/test_data/test-config.yaml b/test/request_source/test_data/test-config.yaml index c8af0cab4..82fa98b4d 100644 --- a/test/request_source/test_data/test-config.yaml +++ b/test/request_source/test_data/test-config.yaml @@ -1,5 +1,11 @@ -request_body_size: 10 -request_headers: - - { header: { key: "foo", value: "bar" } } - - { header: { key: "foo", value: "bar2" }, append: true } - - { header: { key: "x-nh", value: "1" } } +sub_options: + - request_body_size: 10 + request_headers: + - { header: { key: "foo", value: "bar" } } + - { header: { key: "foo", value: "bar2" }, append: true } + - { header: { key: "x-nh", value: "1" } } + - request_body_size: 10 + request_headers: + - { header: { key: "bar", value: "foo" } } + - { header: { key: "bar", value: "foo2" }, append: true } + - { header: { key: "x-nh", value: "2" } } \ No newline at end of file From ca7a0c2e805850542031221711f69e133bac9df8 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 2 Sep 2020 14:46:47 +0000 Subject: [PATCH 044/114] Removing unused comments. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/client/factories_impl.cc | 4 ---- 1 file changed, 4 deletions(-) diff --git a/source/client/factories_impl.cc b/source/client/factories_impl.cc index 8309abd2b..1978172fe 100644 --- a/source/client/factories_impl.cc +++ b/source/client/factories_impl.cc @@ -180,15 +180,11 @@ RequestSourcePtr RequestSourceFactoryImpl::create( if (options_.requestSource() == "") { return request_source_constructor.createStaticRequestSource(std::move(header)); - // return std::make_unique(std::move(header)); } else { // We pass in options_.requestsPerSecond() as the header buffer length so the grpc client // will shoot for maintaining an amount of headers of at least one second. return request_source_constructor.createRemoteRequestSource(std::move(header), options_.requestsPerSecond()); - // return std::make_unique(cluster_manager, dispatcher, scope, - // service_cluster_name, std::move(header), - // options_.requestsPerSecond()); } } From 967e3f88218d7714c9187cb7f051a0cb4695b3dd Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 2 Sep 2020 20:20:05 +0000 Subject: [PATCH 045/114] Adding api dependency injection. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../nighthawk/common/request_source_plugin.h | 16 +- source/common/request_source_plugin_impl.cc | 57 +++--- source/common/request_source_plugin_impl.h | 30 ++-- .../request_source_plugin_test.cc | 162 ++++++++++-------- 4 files changed, 149 insertions(+), 116 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index eae0c9c62..03e70c4de 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -1,10 +1,11 @@ #pragma once +#include "envoy/api/api.h" #include "envoy/common/pure.h" + #include "envoy/config/typed_config.h" #include "nighthawk/common/request_source.h" - namespace Nighthawk { /** @@ -13,11 +14,14 @@ namespace Nighthawk { */ class RequestSourcePlugin : RequestSource { public: - virtual ~RequestSourcePlugin() = default; - virtual RequestGenerator get() PURE; - virtual void initOnThread() PURE; - + RequestSourcePlugin(Envoy::Api::Api& api) : api_(api) {} + virtual ~RequestSourcePlugin() = default; + // virtual RequestGenerator get() PURE; + // virtual void initOnThread() PURE; +protected: + Envoy::Api::Api& api_; }; + using RequestSourcePluginPtr = std::unique_ptr; /** @@ -39,7 +43,7 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the * plugin. */ - virtual RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) PURE; + virtual RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) PURE; }; } // namespace Nighthawk \ No newline at end of file diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 6d945420c..a9dd61ea5 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -1,12 +1,11 @@ #include "common/request_source_plugin_impl.h" +#include "common/protobuf/message_validator_impl.h" #include "common/request_impl.h" #include "common/request_source_impl.h" #include "external/envoy/source/common/protobuf/utility.h" -#include "common/protobuf/message_validator_impl.h" #include "external/envoy/source/exe/platform_impl.h" - #include "api/client/options.pb.h" #include "api/request_source/request_source_plugin_impl.pb.h" @@ -23,20 +22,22 @@ Envoy::ProtobufTypes::MessagePtr DummyRequestSourceConfigFactory::createEmptyCon return std::make_unique(); } -RequestSourcePluginPtr DummyRequestSourceConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message) { +RequestSourcePluginPtr +DummyRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + Envoy::Api::Api& api) { const auto& any = dynamic_cast(message); nighthawk::request_source::DummyPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); - return std::make_unique(config); + return std::make_unique(config, api); } REGISTER_FACTORY(DummyRequestSourceConfigFactory, RequestSourcePluginConfigFactory); DummyRequestSourcePlugin::DummyRequestSourcePlugin( - const nighthawk::request_source::DummyPluginRequestSourceConfig& config) - : dummy_value_{config.has_dummy_value() ? config.dummy_value().value() - : std::numeric_limits::infinity()} {} + const nighthawk::request_source::DummyPluginRequestSourceConfig& config, + Envoy::Api::Api& api) + : RequestSourcePlugin{api}, dummy_value_{config.has_dummy_value() ? config.dummy_value().value() + : std::numeric_limits::infinity()} {} RequestGenerator DummyRequestSourcePlugin::get() { RequestGenerator request_generator = []() { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); @@ -56,18 +57,20 @@ Envoy::ProtobufTypes::MessagePtr RPCRequestSourceConfigFactory::createEmptyConfi } RequestSourcePluginPtr -RPCRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message) { +RPCRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + Envoy::Api::Api& api) { const auto& any = dynamic_cast(message); nighthawk::request_source::RPCPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); - return std::make_unique(config); + return std::make_unique(config, api); } REGISTER_FACTORY(RPCRequestSourceConfigFactory, RequestSourcePluginConfigFactory); RPCRequestSourcePlugin::RPCRequestSourcePlugin( - const nighthawk::request_source::RPCPluginRequestSourceConfig& config) - : uri_(config.uri()) {} + const nighthawk::request_source::RPCPluginRequestSourceConfig& config, + Envoy::Api::Api& api) + : RequestSourcePlugin{api}, uri_(config.uri()) {} RequestGenerator RPCRequestSourcePlugin::get() { RequestGenerator request_generator = []() { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); @@ -87,19 +90,20 @@ Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourceConfigFactory::createEmpt } RequestSourcePluginPtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message) { + const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) { const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); - Envoy::PlatformImpl platform_impl_; - return std::make_unique(config, platform_impl_.fileSystem()); + // Envoy::PlatformImpl platform_impl_; + return std::make_unique(config, api); } REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, Envoy::Filesystem::Instance& file_system) - : uri_(config.uri()), file_path_(config.file_path()) { + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, + Envoy::Api::Api& api) + : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()) { // Envoy::MessageUtil::loadFromJson() // std::ifstream options_file(file_path_); // if (options_file.is_open()) @@ -117,26 +121,27 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( // } // options_file.close(); Envoy::MessageUtil util; - std::string file_string = file_system.fileReadToEnd(file_path_); + std::string file_string = RequestSourcePlugin::api_.fileSystem().fileReadToEnd(file_path_); util.loadFromYaml(file_string, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor()); - std::cerr << "\n"+ file_string +"\n"; + std::cerr << "\n" + file_string + "\n"; } RequestGenerator FileBasedRequestSourcePlugin::get() { auto iterator = optionses_.sub_options().begin(); RequestGenerator request_generator = [this, &iterator]() { auto temp = *iterator++; - // auto returned_request_impl = std::make_unique(std::move(options_.request_headers())); - Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); + // auto returned_request_impl = + // std::make_unique(std::move(options_.request_headers())); + Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); header->setPath(uri_.path()); header->setHost(uri_.hostAndPort()); header->setScheme(uri_.scheme() == "https" ? Envoy::Http::Headers::get().SchemeValues.Https - : Envoy::Http::Headers::get().SchemeValues.Http); + : Envoy::Http::Headers::get().SchemeValues.Http); header->setMethod(envoy::config::core::v3::RequestMethod_Name(temp.request_method())); - // const uint32_t content_length = temp.request_body_size(); - // if (content_length > 0) { - // header->setContentLength(content_length); - // } + const uint32_t content_length = temp.request_body_size().value(); + if (content_length > 0) { + header->setContentLength(content_length); + } auto returned_request_impl = std::make_unique(std::move(header)); return returned_request_impl; diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index dfc4abcd2..c0482d291 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -4,8 +4,8 @@ #include "nighthawk/common/request_source_plugin.h" -#include "api/request_source/request_source_plugin_impl.pb.h" #include "api/client/options.pb.h" +#include "api/request_source/request_source_plugin_impl.pb.h" #include "common/uri_impl.h" namespace Nighthawk { @@ -15,7 +15,8 @@ namespace Nighthawk { class DummyRequestSourcePlugin : public RequestSourcePlugin { public: explicit DummyRequestSourcePlugin( - const nighthawk::request_source::DummyPluginRequestSourceConfig& config); + const nighthawk::request_source::DummyPluginRequestSourceConfig& config, + Envoy::Api::Api& api); RequestGenerator get() override; /** * Will be called on an intialized and running worker thread, before commencing actual work. @@ -32,12 +33,12 @@ class DummyRequestSourcePlugin : public RequestSourcePlugin { * Factory that creates a DummyRequestSourcePlugin from a DummyRequestSourcePluginConfig proto. * Registered as an Envoy plugin. */ -class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory -{ +class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) override; + RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + Envoy::Api::Api& api) override; }; // This factory is activated through ???. @@ -48,7 +49,7 @@ DECLARE_FACTORY(DummyRequestSourceConfigFactory); class RPCRequestSourcePlugin : public RequestSourcePlugin { public: explicit RPCRequestSourcePlugin( - const nighthawk::request_source::RPCPluginRequestSourceConfig& config); + const nighthawk::request_source::RPCPluginRequestSourceConfig& config, Envoy::Api::Api& api); RequestGenerator get() override; /** * Will be called on an intialized and running worker thread, before commencing actual work. @@ -64,12 +65,12 @@ class RPCRequestSourcePlugin : public RequestSourcePlugin { /** * Registered as an Envoy plugin. */ -class RPCRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory -{ +class RPCRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) override; + RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + Envoy::Api::Api& api) override; }; // This factory is activated through ???. @@ -80,7 +81,8 @@ DECLARE_FACTORY(RPCRequestSourceConfigFactory); class FileBasedRequestSourcePlugin : public RequestSourcePlugin { public: explicit FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, Envoy::Filesystem::Instance& file_system); + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, + Envoy::Api::Api& api); RequestGenerator get() override; /** * Will be called on an intialized and running worker thread, before commencing actual work. @@ -99,15 +101,15 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { /** * Registered as an Envoy plugin. */ -class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory -{ +class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message) override; + RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + Envoy::Api::Api& api) override; }; // This factory is activated through ???. DECLARE_FACTORY(FileBasedRequestSourceConfigFactory); -} \ No newline at end of file +} // namespace Nighthawk \ No newline at end of file diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 5a557dcb3..8be9fb17d 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -1,84 +1,106 @@ -#include "envoy/common/exception.h" #include "common/request_source_plugin_impl.h" +#include "envoy/common/exception.h" #include "external/envoy/source/common/config/utility.h" +#include "external/envoy/test/mocks/stats/mocks.h" #include "external/envoy/test/test_common/file_system_for_test.h" +#include "external/envoy/test/test_common/utility.h" +#include "test/test_common/environment.h" #include "gmock/gmock.h" #include "gtest/gtest.h" -#include "test/test_common/environment.h" namespace Nighthawk { namespace { using nighthawk::request_source::DummyPluginRequestSourceConfig; using nighthawk::request_source::FileBasedPluginRequestSourceConfig; +using ::testing::Test; + +class DummyRequestSourcePluginTest : public Test { +public: + DummyRequestSourcePluginTest() : api_(Envoy::Api::createApiForTest(stats_store_)) {} + Envoy::Api::ApiPtr api_; + Envoy::Stats::MockIsolatedStatsStore stats_store_; +}; // RequestSourcePluginTest +class FileBasedRequestSourcePluginTest : public Test { +public: + FileBasedRequestSourcePluginTest() : api_(Envoy::Api::createApiForTest(stats_store_)) {} + Envoy::Api::ApiPtr api_; + Envoy::Stats::MockIsolatedStatsStore stats_store_; + nighthawk::request_source::FileBasedPluginRequestSourceConfig + MakeFileBasedPluginConfigWithTestYaml(std::string request_file) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + config.mutable_uri()->assign("http://foo/"); + config.mutable_file_path()->assign(request_file); + return config; + } +}; // RequestSourcePluginTest -nighthawk::request_source::FileBasedPluginRequestSourceConfig MakeFileBasedPluginConfigWithTestYaml(std::string request_file) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config; - config.mutable_uri()->assign("http://foo/"); - config.mutable_file_path()-> assign(request_file); - return config; -} -TEST(DummyPluginRequestSourceConfigFactory, CreateEmptyConfigProtoCreatesCorrectType) { - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.dummy-request-source-plugin"); - const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); - const nighthawk::request_source::DummyPluginRequestSourceConfig expected_config; - EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); - EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); -} -TEST(DummyPluginRequestSourceConfigFactory, FactoryRegistrationUsesCorrectPluginName) { - nighthawk::request_source::DummyPluginRequestSourceConfig config; - Envoy::ProtobufWkt::Any config_any; - config_any.PackFrom(config); - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.dummy-request-source-plugin"); - EXPECT_EQ(config_factory.name(), "nighthawk.dummy-request-source-plugin"); -} -TEST(DummyPluginRequestSourceConfigFactory, CreateRequestSourcePluginCreatesCorrectPluginType) { - nighthawk::request_source::DummyPluginRequestSourceConfig config; - Envoy::ProtobufWkt::Any config_any; - config_any.PackFrom(config); - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.dummy-request-source-plugin"); - RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any); - EXPECT_NE(dynamic_cast(plugin.get()), nullptr); -} -TEST(FileBasedPluginRequestSourceConfigFactory, CreateEmptyConfigProtoCreatesCorrectType) { - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.file-based-request-source-plugin"); - const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); - const nighthawk::request_source::FileBasedPluginRequestSourceConfig expected_config; - EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); - EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); -} -TEST(FileBasedPluginRequestSourceConfigFactory, FactoryRegistrationUsesCorrectPluginName) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config; - Envoy::ProtobufWkt::Any config_any; - config_any.PackFrom(config); - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.file-based-request-source-plugin"); - EXPECT_EQ(config_factory.name(), "nighthawk.file-based-request-source-plugin"); -} -TEST(FileBasedPluginRequestSourceConfigFactory, CreateRequestSourcePluginCreatesCorrectPluginType) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config; - Envoy::ProtobufWkt::Any config_any; - config_any.PackFrom(config); - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.file-based-request-source-plugin"); - RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any); - EXPECT_NE(dynamic_cast(plugin.get()), nullptr); -} -TEST(FileBasedPluginRequestSourceConfigFactory, CreateRequestSourcePluginGetsWorkingRequestGenerator) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml(TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); - FileBasedRequestSourcePlugin file_based_request_source(config, Envoy::Filesystem::fileSystemForTest()); - // auto generator = file_based_request_source.get(); - // auto request = generator(); -} + TEST_F(DummyRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.dummy-request-source-plugin"); + const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); + const nighthawk::request_source::DummyPluginRequestSourceConfig expected_config; + EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); + EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); + } + TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { + nighthawk::request_source::DummyPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.dummy-request-source-plugin"); + EXPECT_EQ(config_factory.name(), "nighthawk.dummy-request-source-plugin"); + } + TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { + nighthawk::request_source::DummyPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.dummy-request-source-plugin"); + RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); + EXPECT_NE(dynamic_cast(plugin.get()), nullptr); + } + TEST_F(FileBasedRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); + const nighthawk::request_source::FileBasedPluginRequestSourceConfig expected_config; + EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); + EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); + } + TEST_F(FileBasedRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + EXPECT_EQ(config_factory.name(), "nighthawk.file-based-request-source-plugin"); + } + TEST_F(FileBasedRequestSourcePluginTest, + CreateRequestSourcePluginCreatesCorrectPluginType) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); + EXPECT_NE(dynamic_cast(plugin.get()), nullptr); + } + TEST_F(FileBasedRequestSourcePluginTest, + CreateRequestSourcePluginGetsWorkingRequestGenerator) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config = + MakeFileBasedPluginConfigWithTestYaml( + TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); + FileBasedRequestSourcePlugin file_based_request_source(config, + *api_); + // auto generator = file_based_request_source.get(); + // auto request = generator(); + } } // namespace } // namespace Nighthawk From 14b7d79d7a02c7de906c2d4ad69069397f4a3985 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 3 Sep 2020 19:07:53 +0000 Subject: [PATCH 046/114] Getting the multiple paths parsing into the test. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 15 +++++++++++---- source/common/request_source_plugin_impl.h | 1 + test/request_source/request_source_plugin_test.cc | 11 ++++++++--- test/request_source/test_data/test-config.yaml | 2 ++ 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index a9dd61ea5..b0b1c668d 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -123,13 +123,14 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( Envoy::MessageUtil util; std::string file_string = RequestSourcePlugin::api_.fileSystem().fileReadToEnd(file_path_); util.loadFromYaml(file_string, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor()); + iterator_ = optionses_.sub_options().begin(); std::cerr << "\n" + file_string + "\n"; } RequestGenerator FileBasedRequestSourcePlugin::get() { - auto iterator = optionses_.sub_options().begin(); - RequestGenerator request_generator = [this, &iterator]() { - auto temp = *iterator++; + // const google::protobuf::internal::RepeatedPtrIterator option_iterator = optionses_.sub_options().begin(); + RequestGenerator request_generator = [this]() { + auto temp = *iterator_++; // auto returned_request_impl = // std::make_unique(std::move(options_.request_headers())); Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); @@ -142,12 +143,18 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { if (content_length > 0) { header->setContentLength(content_length); } - + for (const auto& option_header : temp.request_headers()) { + auto lower_case_key = Envoy::Http::LowerCaseString(std::string(option_header.header().key())); + header->remove(lower_case_key); + // TODO(oschaaf): we've performed zero validation on the header key/value. + header->addCopy(lower_case_key, std::string(option_header.header().value())); + } auto returned_request_impl = std::make_unique(std::move(header)); return returned_request_impl; }; return request_generator; } + void FileBasedRequestSourcePlugin::initOnThread() { // options_.set_request_method(::envoy::config::core::v3::RequestMethod::GET); // auto request_headers = options_.add_request_headers(); diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index c0482d291..15145b856 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -96,6 +96,7 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { const std::string file_path_; nighthawk::client::RequestOptions options_; nighthawk::client::RequestOptionses optionses_; + google::protobuf::internal::RepeatedPtrIterator iterator_; }; /** diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 8be9fb17d..650e0d37f 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -83,7 +83,7 @@ class FileBasedRequestSourcePluginTest : public Test { } TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml(TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); Envoy::ProtobufWkt::Any config_any; config_any.PackFrom(config); auto& config_factory = @@ -99,8 +99,13 @@ class FileBasedRequestSourcePluginTest : public Test { TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); FileBasedRequestSourcePlugin file_based_request_source(config, *api_); - // auto generator = file_based_request_source.get(); - // auto request = generator(); + auto generator = file_based_request_source.get(); + auto request = generator(); + auto request2 = generator(); + auto header = request -> header(); + auto header2 = request2 -> header(); + EXPECT_EQ ( header->getPathValue(), "/a"); + EXPECT_EQ ( header2->getPathValue(), "/b"); } } // namespace } // namespace Nighthawk diff --git a/test/request_source/test_data/test-config.yaml b/test/request_source/test_data/test-config.yaml index 82fa98b4d..07ed5ce11 100644 --- a/test/request_source/test_data/test-config.yaml +++ b/test/request_source/test_data/test-config.yaml @@ -1,11 +1,13 @@ sub_options: - request_body_size: 10 request_headers: + - { header: { key: ":path", value: "/a" } } - { header: { key: "foo", value: "bar" } } - { header: { key: "foo", value: "bar2" }, append: true } - { header: { key: "x-nh", value: "1" } } - request_body_size: 10 request_headers: + - { header: { key: ":path", value: "/b" } } - { header: { key: "bar", value: "foo" } } - { header: { key: "bar", value: "foo2" }, append: true } - { header: { key: "x-nh", value: "2" } } \ No newline at end of file From c4985bbcced7038e63d79fd28e737f98e393951d Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 3 Sep 2020 21:28:33 +0000 Subject: [PATCH 047/114] Comment clean up and using loadfromfile instead of reading the file and loading the yaml separately. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 39 ++++----------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index b0b1c668d..f9117fbf1 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -104,49 +104,29 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, Envoy::Api::Api& api) : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()) { - // Envoy::MessageUtil::loadFromJson() - // std::ifstream options_file(file_path_); - // if (options_file.is_open()) - // { - // std::cerr << "Opened file: " + file_path_; - // } - // // options_.ParseFromIstream(&options_file); - // std::stringstream file_string_stream; - // file_string_stream << options_file.rdbuf(); - // std::string test_string = file_string_stream.str(); - // Envoy::MessageUtil util; - // util.loadFromYaml(test_string, options_, Envoy::ProtobufMessage::getStrictValidationVisitor()); - // for (const auto& option_header : options_.request_headers()) { - // std::cerr << option_header.header().key() +":"+ option_header.header().value()+"\n"; - // } - // options_file.close(); Envoy::MessageUtil util; - std::string file_string = RequestSourcePlugin::api_.fileSystem().fileReadToEnd(file_path_); - util.loadFromYaml(file_string, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor()); + // std::string file_string = RequestSourcePlugin::api_.fileSystem().fileReadToEnd(file_path_); + util.loadFromFile(file_path_, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor(), api_, true); iterator_ = optionses_.sub_options().begin(); - std::cerr << "\n" + file_string + "\n"; + // std::cerr << "\n" + file_string + "\n"; } RequestGenerator FileBasedRequestSourcePlugin::get() { - // const google::protobuf::internal::RepeatedPtrIterator option_iterator = optionses_.sub_options().begin(); RequestGenerator request_generator = [this]() { - auto temp = *iterator_++; - // auto returned_request_impl = - // std::make_unique(std::move(options_.request_headers())); + nighthawk::client::RequestOptions request_option = *iterator_++; Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); header->setPath(uri_.path()); header->setHost(uri_.hostAndPort()); header->setScheme(uri_.scheme() == "https" ? Envoy::Http::Headers::get().SchemeValues.Https : Envoy::Http::Headers::get().SchemeValues.Http); - header->setMethod(envoy::config::core::v3::RequestMethod_Name(temp.request_method())); - const uint32_t content_length = temp.request_body_size().value(); + header->setMethod(envoy::config::core::v3::RequestMethod_Name(request_option.request_method())); + const uint32_t content_length = request_option.request_body_size().value(); if (content_length > 0) { header->setContentLength(content_length); } - for (const auto& option_header : temp.request_headers()) { + for (const auto& option_header : request_option.request_headers()) { auto lower_case_key = Envoy::Http::LowerCaseString(std::string(option_header.header().key())); header->remove(lower_case_key); - // TODO(oschaaf): we've performed zero validation on the header key/value. header->addCopy(lower_case_key, std::string(option_header.header().value())); } auto returned_request_impl = std::make_unique(std::move(header)); @@ -156,11 +136,6 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { } void FileBasedRequestSourcePlugin::initOnThread() { - // options_.set_request_method(::envoy::config::core::v3::RequestMethod::GET); - // auto request_headers = options_.add_request_headers(); - // request_headers->mutable_header()->set_key("foo"); - // request_headers->mutable_header()->set_value("bar"); - // options_.set_allocated_request_body_size(0); } } // namespace Nighthawk \ No newline at end of file From 922639acfdadced1b2f98f7542f2bc4ed000dfc8 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 9 Sep 2020 19:49:49 +0000 Subject: [PATCH 048/114] Switching to using iterators in a vector instead of a smart pointer. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 14 ++++++++------ source/common/request_source_plugin_impl.h | 7 +++++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index f9117fbf1..bcccccf88 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -94,7 +94,6 @@ RequestSourcePluginPtr FileBasedRequestSourceConfigFactory::createRequestSourceP const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); - // Envoy::PlatformImpl platform_impl_; return std::make_unique(config, api); } @@ -105,15 +104,18 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( Envoy::Api::Api& api) : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()) { Envoy::MessageUtil util; - // std::string file_string = RequestSourcePlugin::api_.fileSystem().fileReadToEnd(file_path_); util.loadFromFile(file_path_, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor(), api_, true); - iterator_ = optionses_.sub_options().begin(); - // std::cerr << "\n" + file_string + "\n"; + // iterator_ = std::make_shared(optionses_.sub_options().begin()); } RequestGenerator FileBasedRequestSourcePlugin::get() { - RequestGenerator request_generator = [this]() { - nighthawk::client::RequestOptions request_option = *iterator_++; + RequestOptionsIterator iterator = optionses_.sub_options().begin(); + request_iterators_.push_back(iterator); + RequestOptionsIterator* temp = &request_iterators_.back(); + RequestGenerator request_generator = [this, temp]() mutable { + auto tempValue = *temp; + nighthawk::client::RequestOptions request_option = *tempValue; + *temp = std::next(*temp); Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); header->setPath(uri_.path()); header->setHost(uri_.hostAndPort()); diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 15145b856..df0692741 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -76,6 +76,9 @@ class RPCRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFa // This factory is activated through ???. DECLARE_FACTORY(RPCRequestSourceConfigFactory); +using RequestOptionsIterator = google::protobuf::internal::RepeatedPtrIterator; +using RequestOptionsIteratorPtr = std::shared_ptr; + /** */ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { @@ -96,9 +99,9 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { const std::string file_path_; nighthawk::client::RequestOptions options_; nighthawk::client::RequestOptionses optionses_; - google::protobuf::internal::RepeatedPtrIterator iterator_; + // RequestOptionsIteratorPtr iterator_; + std::vector request_iterators_; }; - /** * Registered as an Envoy plugin. */ From 81dfecef3056b72a86b623a703015f40551112ee Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 9 Sep 2020 19:50:47 +0000 Subject: [PATCH 049/114] Removing unused comments. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 1 - source/common/request_source_plugin_impl.h | 2 -- 2 files changed, 3 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index bcccccf88..4ca15f5d1 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -105,7 +105,6 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()) { Envoy::MessageUtil util; util.loadFromFile(file_path_, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor(), api_, true); - // iterator_ = std::make_shared(optionses_.sub_options().begin()); } RequestGenerator FileBasedRequestSourcePlugin::get() { diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index df0692741..f483d42c5 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -77,7 +77,6 @@ class RPCRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFa DECLARE_FACTORY(RPCRequestSourceConfigFactory); using RequestOptionsIterator = google::protobuf::internal::RepeatedPtrIterator; -using RequestOptionsIteratorPtr = std::shared_ptr; /** */ @@ -99,7 +98,6 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { const std::string file_path_; nighthawk::client::RequestOptions options_; nighthawk::client::RequestOptionses optionses_; - // RequestOptionsIteratorPtr iterator_; std::vector request_iterators_; }; /** From bf086610c64c6df00e96deda38e765f4469aba40 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 10 Sep 2020 16:15:23 +0000 Subject: [PATCH 050/114] Small cleanup. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 4ca15f5d1..dca9fbd3c 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -111,9 +111,8 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { RequestOptionsIterator iterator = optionses_.sub_options().begin(); request_iterators_.push_back(iterator); RequestOptionsIterator* temp = &request_iterators_.back(); - RequestGenerator request_generator = [this, temp]() mutable { - auto tempValue = *temp; - nighthawk::client::RequestOptions request_option = *tempValue; + RequestGenerator request_generator = [this, temp]() mutable { + nighthawk::client::RequestOptions request_option = **temp; *temp = std::next(*temp); Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); header->setPath(uri_.path()); From e93bb58ed5e3e75ff948c7a761537a0dff060dcc Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 10 Sep 2020 16:59:12 +0000 Subject: [PATCH 051/114] Reverting changes to RequestSourceConstructor. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/factories.h | 17 +++------- source/client/client_worker_impl.cc | 10 +++--- source/client/factories_impl.cc | 32 ++++++------------- source/client/factories_impl.h | 22 +++---------- test/BUILD | 2 -- test/client_worker_test.cc | 2 +- test/factories_test.cc | 30 +++-------------- test/mocks/common/BUILD | 9 ------ .../common/mock_request_source_constructor.cc | 7 ---- .../common/mock_request_source_constructor.h | 17 ---------- .../common/mock_request_source_factory.h | 7 ++-- 11 files changed, 32 insertions(+), 123 deletions(-) delete mode 100644 test/mocks/common/mock_request_source_constructor.cc delete mode 100644 test/mocks/common/mock_request_source_constructor.h diff --git a/include/nighthawk/common/factories.h b/include/nighthawk/common/factories.h index 9e36fc2d2..d66cf5b8e 100644 --- a/include/nighthawk/common/factories.h +++ b/include/nighthawk/common/factories.h @@ -33,21 +33,12 @@ class StatisticFactory { virtual StatisticPtr create() const PURE; }; -class RequestSourceConstructorInterface { -public: - virtual ~RequestSourceConstructorInterface() = default; - virtual RequestSourcePtr - createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&&, - const uint64_t max_yields = UINT64_MAX) const PURE; - virtual RequestSourcePtr createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, - uint32_t header_buffer_length) const PURE; -}; - class RequestSourceFactory { public: virtual ~RequestSourceFactory() = default; - virtual RequestSourcePtr - create(const RequestSourceConstructorInterface& request_source_constructor) const PURE; + virtual RequestSourcePtr create(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, + Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, + absl::string_view service_cluster_name) const PURE; }; class TerminationPredicateFactory { @@ -81,4 +72,4 @@ class NighthawkStatsSinkFactory : public Envoy::Config::TypedFactory { std::string category() const override { return "nighthawk.stats_sinks"; } }; -} // namespace Nighthawk +} // namespace Nighthawk \ No newline at end of file diff --git a/source/client/client_worker_impl.cc b/source/client/client_worker_impl.cc index fea643c08..6ddac305f 100644 --- a/source/client/client_worker_impl.cc +++ b/source/client/client_worker_impl.cc @@ -7,8 +7,6 @@ #include "common/termination_predicate_impl.h" #include "common/utility.h" -#include "client/factories_impl.h" - namespace Nighthawk { namespace Client { @@ -30,9 +28,9 @@ ClientWorkerImpl::ClientWorkerImpl(Envoy::Api::Api& api, Envoy::ThreadLocal::Ins sequencer_factory_(sequencer_factory), worker_scope_(store_.createScope("cluster.")), worker_number_scope_(worker_scope_->createScope(fmt::format("{}.", worker_number))), worker_number_(worker_number), http_tracer_(http_tracer), - request_generator_(request_generator_factory.create( - RequestSourceConstructorImpl(cluster_manager, *dispatcher_, *worker_number_scope_, - fmt::format("{}.requestsource", worker_number)))), + request_generator_( + request_generator_factory.create(cluster_manager, *dispatcher_, *worker_number_scope_, + fmt::format("{}.requestsource", worker_number))), benchmark_client_(benchmark_client_factory.create( api, *dispatcher_, *worker_number_scope_, cluster_manager, http_tracer_, fmt::format("{}", worker_number), worker_number, *request_generator_)), @@ -108,4 +106,4 @@ StatisticPtrMap ClientWorkerImpl::statistics() const { } } // namespace Client -} // namespace Nighthawk +} // namespace Nighthawk \ No newline at end of file diff --git a/source/client/factories_impl.cc b/source/client/factories_impl.cc index 2888a4f0b..f0b9f3ab8 100644 --- a/source/client/factories_impl.cc +++ b/source/client/factories_impl.cc @@ -112,22 +112,6 @@ OutputFormatterPtr OutputFormatterFactoryImpl::create( NOT_REACHED_GCOVR_EXCL_LINE; } } -RequestSourceConstructorImpl::RequestSourceConstructorImpl( - const Envoy::Upstream::ClusterManagerPtr& cluster_manager, Envoy::Event::Dispatcher& dispatcher, - Envoy::Stats::Scope& scope, absl::string_view service_cluster_name) - : cluster_manager_(cluster_manager), dispatcher_(dispatcher), scope_(scope), - service_cluster_name_(service_cluster_name) {} -RequestSourcePtr RequestSourceConstructorImpl::createStaticRequestSource( - Envoy::Http::RequestHeaderMapPtr&& base_header, const uint64_t max_yields) const { - return std::make_unique(std::move(base_header), max_yields); -} -RequestSourcePtr RequestSourceConstructorImpl::createRemoteRequestSource( - Envoy::Http::RequestHeaderMapPtr&& base_header, uint32_t header_buffer_length) const { - RELEASE_ASSERT(!service_cluster_name_.empty(), "expected cluster name to be set"); - return std::make_unique(cluster_manager_, dispatcher_, scope_, - service_cluster_name_, std::move(base_header), - header_buffer_length); -} RequestSourceFactoryImpl::RequestSourceFactoryImpl(const Options& options) : OptionBasedFactoryImpl(options) {} @@ -141,8 +125,10 @@ void RequestSourceFactoryImpl::setRequestHeader(Envoy::Http::RequestHeaderMap& h header.addCopy(lower_case_key, std::string(value)); } -RequestSourcePtr RequestSourceFactoryImpl::create( - const RequestSourceConstructorInterface& request_source_constructor) const { +RequestSourcePtr +RequestSourceFactoryImpl::create(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, + Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, + absl::string_view service_cluster_name) const { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); if (options_.uri().has_value()) { // We set headers based on the URI, but we don't have all the prerequisites to call the @@ -180,12 +166,14 @@ RequestSourcePtr RequestSourceFactoryImpl::create( } if (options_.requestSource() == "") { - return request_source_constructor.createStaticRequestSource(std::move(header)); + return std::make_unique(std::move(header)); } else { + RELEASE_ASSERT(!service_cluster_name.empty(), "expected cluster name to be set"); // We pass in options_.requestsPerSecond() as the header buffer length so the grpc client // will shoot for maintaining an amount of headers of at least one second. - return request_source_constructor.createRemoteRequestSource(std::move(header), - options_.requestsPerSecond()); + return std::make_unique(cluster_manager, dispatcher, scope, + service_cluster_name, std::move(header), + options_.requestsPerSecond()); } } @@ -234,4 +222,4 @@ TerminationPredicate* TerminationPredicateFactoryImpl::linkConfiguredPredicates( } } // namespace Client -} // namespace Nighthawk +} // namespace Nighthawk \ No newline at end of file diff --git a/source/client/factories_impl.h b/source/client/factories_impl.h index 53ad1308d..7a542b6b0 100644 --- a/source/client/factories_impl.h +++ b/source/client/factories_impl.h @@ -55,27 +55,13 @@ class OutputFormatterFactoryImpl : public OutputFormatterFactory { OutputFormatterPtr create(const nighthawk::client::OutputFormat_OutputFormatOptions output_format) const override; }; -class RequestSourceConstructorImpl : public RequestSourceConstructorInterface { -public: - RequestSourceConstructorImpl(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, - Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, - absl::string_view service_cluster_name); - RequestSourcePtr createStaticRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, - const uint64_t max_yields = UINT64_MAX) const override; - RequestSourcePtr createRemoteRequestSource(Envoy::Http::RequestHeaderMapPtr&& base_header, - uint32_t header_buffer_length) const override; -protected: - const Envoy::Upstream::ClusterManagerPtr& cluster_manager_; - Envoy::Event::Dispatcher& dispatcher_; - Envoy::Stats::Scope& scope_; - absl::string_view service_cluster_name_; -}; class RequestSourceFactoryImpl : public OptionBasedFactoryImpl, public RequestSourceFactory { public: RequestSourceFactoryImpl(const Options& options); - RequestSourcePtr - create(const RequestSourceConstructorInterface& request_source_constructor) const override; + RequestSourcePtr create(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, + Envoy::Event::Dispatcher& dispatcher, Envoy::Stats::Scope& scope, + absl::string_view service_cluster_name) const override; private: void setRequestHeader(Envoy::Http::RequestHeaderMap& header, absl::string_view key, @@ -94,4 +80,4 @@ class TerminationPredicateFactoryImpl : public OptionBasedFactoryImpl, }; } // namespace Client -} // namespace Nighthawk +} // namespace Nighthawk \ No newline at end of file diff --git a/test/BUILD b/test/BUILD index 8a10ca59a..f88f59e3a 100644 --- a/test/BUILD +++ b/test/BUILD @@ -86,8 +86,6 @@ envoy_cc_test( "//source/client:nighthawk_client_lib", "//test/mocks/client:mock_benchmark_client", "//test/mocks/client:mock_options", - "//test/mocks/common:mock_request_source", - "//test/mocks/common:mock_request_source_constructor", "//test/mocks/common:mock_termination_predicate", "@envoy//test/mocks/event:event_mocks", "@envoy//test/mocks/tracing:tracing_mocks", diff --git a/test/client_worker_test.cc b/test/client_worker_test.cc index 5cf26d0e7..8ffdf6680 100644 --- a/test/client_worker_test.cc +++ b/test/client_worker_test.cc @@ -51,7 +51,7 @@ class ClientWorkerTest : public Test { .Times(1) .WillOnce(Return(ByMove(std::unique_ptr(sequencer_)))); - EXPECT_CALL(request_generator_factory_, create(_)) + EXPECT_CALL(request_generator_factory_, create(_, _, _, _)) .Times(1) .WillOnce(Return(ByMove(std::unique_ptr(request_generator_)))); EXPECT_CALL(*request_generator_, initOnThread()).Times(1); diff --git a/test/factories_test.cc b/test/factories_test.cc index 63cc7d2cb..c03442c83 100644 --- a/test/factories_test.cc +++ b/test/factories_test.cc @@ -10,8 +10,6 @@ #include "test/mocks/client/mock_benchmark_client.h" #include "test/mocks/client/mock_options.h" -#include "test/mocks/common/mock_request_source.h" -#include "test/mocks/common/mock_request_source_constructor.h" #include "test/mocks/common/mock_termination_predicate.h" #include "gtest/gtest.h" @@ -32,8 +30,6 @@ class FactoriesTest : public Test { Envoy::Event::MockDispatcher dispatcher_; MockOptions options_; Envoy::Tracing::HttpTracerSharedPtr http_tracer_; - MockRequestSourceConstructor mock_request_constructor_; - MockRequestSource mock_request_source_; }; TEST_F(FactoriesTest, CreateBenchmarkClient) { @@ -56,7 +52,7 @@ TEST_F(FactoriesTest, CreateBenchmarkClient) { EXPECT_NE(nullptr, benchmark_client.get()); } -TEST_F(FactoriesTest, CreateStaticRequestSource) { +TEST_F(FactoriesTest, CreateRequestSource) { EXPECT_CALL(options_, requestMethod()).Times(1); EXPECT_CALL(options_, requestBodySize()).Times(1); EXPECT_CALL(options_, uri()).Times(2).WillRepeatedly(Return("http://foo/")); @@ -68,29 +64,11 @@ TEST_F(FactoriesTest, CreateStaticRequestSource) { EXPECT_CALL(options_, toCommandLineOptions()).Times(1).WillOnce(Return(ByMove(std::move(cmd)))); RequestSourceFactoryImpl factory(options_); Envoy::Upstream::ClusterManagerPtr cluster_manager; - RequestSourceConstructorImpl constructor(cluster_manager, dispatcher_, - *stats_store_.createScope("foo."), "requestsource"); - auto request_generator = factory.create(constructor); + auto request_generator = factory.create(cluster_manager, dispatcher_, + *stats_store_.createScope("foo."), "requestsource"); EXPECT_NE(nullptr, request_generator.get()); } -TEST_F(FactoriesTest, CreateRequestSourceWithRequestSourceUriOptionReturnsRemoteRequestSource) { - EXPECT_CALL(options_, requestMethod()).Times(1); - EXPECT_CALL(options_, requestBodySize()).Times(1); - EXPECT_CALL(options_, requestsPerSecond()).Times(1).WillRepeatedly(Return(1)); - EXPECT_CALL(options_, uri()).Times(2).WillRepeatedly(Return("http://foo/")); - EXPECT_CALL(options_, requestSource()).Times(1).WillRepeatedly(Return("requestSourceUri")); - EXPECT_CALL(mock_request_constructor_, createRemoteRequestSource(_, _)).Times(1); - auto cmd = std::make_unique(); - auto request_headers = cmd->mutable_request_options()->add_request_headers(); - request_headers->mutable_header()->set_key("foo"); - request_headers->mutable_header()->set_value("bar"); - EXPECT_CALL(options_, toCommandLineOptions()).Times(1).WillOnce(Return(ByMove(std::move(cmd)))); - RequestSourceFactoryImpl factory(options_); - Envoy::Upstream::ClusterManagerPtr cluster_manager; - factory.create(mock_request_constructor_); -} - TEST_F(FactoriesTest, CreateSequencer) {} class SequencerFactoryTest : public FactoriesTest, @@ -152,4 +130,4 @@ INSTANTIATE_TEST_SUITE_P( nighthawk::client::OutputFormat::FORTIO})); } // namespace Client -} // namespace Nighthawk +} // namespace Nighthawk \ No newline at end of file diff --git a/test/mocks/common/BUILD b/test/mocks/common/BUILD index 0b78b7560..763ccb63a 100644 --- a/test/mocks/common/BUILD +++ b/test/mocks/common/BUILD @@ -88,12 +88,3 @@ envoy_cc_mock( ], ) -envoy_cc_mock( - name = "mock_request_source_constructor", - srcs = ["mock_request_source_constructor.cc"], - hdrs = ["mock_request_source_constructor.h"], - repository = "@envoy", - deps = [ - "//include/nighthawk/common:base_includes", - ], -) diff --git a/test/mocks/common/mock_request_source_constructor.cc b/test/mocks/common/mock_request_source_constructor.cc deleted file mode 100644 index da515d7f7..000000000 --- a/test/mocks/common/mock_request_source_constructor.cc +++ /dev/null @@ -1,7 +0,0 @@ -#include "test/mocks/common/mock_request_source_constructor.h" - -namespace Nighthawk { - -MockRequestSourceConstructor::MockRequestSourceConstructor() = default; - -} // namespace Nighthawk \ No newline at end of file diff --git a/test/mocks/common/mock_request_source_constructor.h b/test/mocks/common/mock_request_source_constructor.h deleted file mode 100644 index c29adc5e2..000000000 --- a/test/mocks/common/mock_request_source_constructor.h +++ /dev/null @@ -1,17 +0,0 @@ -#include "nighthawk/common/factories.h" - -#include "gmock/gmock.h" - -namespace Nighthawk { - -class MockRequestSourceConstructor : public RequestSourceConstructorInterface { -public: - MockRequestSourceConstructor(); - MOCK_METHOD(RequestSourcePtr, createStaticRequestSource, - (Envoy::Http::RequestHeaderMapPtr&&, const uint64_t max_yields), (const, override)); - MOCK_METHOD(RequestSourcePtr, createRemoteRequestSource, - (Envoy::Http::RequestHeaderMapPtr && base_header, uint32_t header_buffer_length), - (const, override)); -}; - -} // namespace Nighthawk \ No newline at end of file diff --git a/test/mocks/common/mock_request_source_factory.h b/test/mocks/common/mock_request_source_factory.h index 8defaa9bb..60f277e5b 100644 --- a/test/mocks/common/mock_request_source_factory.h +++ b/test/mocks/common/mock_request_source_factory.h @@ -9,8 +9,11 @@ namespace Nighthawk { class MockRequestSourceFactory : public RequestSourceFactory { public: MockRequestSourceFactory(); - MOCK_CONST_METHOD1(create, - RequestSourcePtr(const RequestSourceConstructorInterface& request_source_constructor)); + MOCK_CONST_METHOD4(create, + RequestSourcePtr(const Envoy::Upstream::ClusterManagerPtr& cluster_manager, + Envoy::Event::Dispatcher& dispatcher, + Envoy::Stats::Scope& scope, + absl::string_view service_cluster_name)); }; } // namespace Nighthawk \ No newline at end of file From f47cbd4d4eef21108489f76b70d56f3b3c1ed7cf Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 10 Sep 2020 18:39:09 +0000 Subject: [PATCH 052/114] Removing RPCRequestSourcePlugin Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 33 --------------------- source/common/request_source_plugin_impl.h | 31 ------------------- 2 files changed, 64 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index dca9fbd3c..fcf2ad218 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -48,39 +48,6 @@ RequestGenerator DummyRequestSourcePlugin::get() { } void DummyRequestSourcePlugin::initOnThread() {} -std::string RPCRequestSourceConfigFactory::name() const { - return "nighthawk.rpc-request-source-plugin"; -} - -Envoy::ProtobufTypes::MessagePtr RPCRequestSourceConfigFactory::createEmptyConfigProto() { - return std::make_unique(); -} - -RequestSourcePluginPtr -RPCRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api& api) { - const auto& any = dynamic_cast(message); - nighthawk::request_source::RPCPluginRequestSourceConfig config; - Envoy::MessageUtil::unpackTo(any, config); - return std::make_unique(config, api); -} - -REGISTER_FACTORY(RPCRequestSourceConfigFactory, RequestSourcePluginConfigFactory); - -RPCRequestSourcePlugin::RPCRequestSourcePlugin( - const nighthawk::request_source::RPCPluginRequestSourceConfig& config, - Envoy::Api::Api& api) - : RequestSourcePlugin{api}, uri_(config.uri()) {} -RequestGenerator RPCRequestSourcePlugin::get() { - RequestGenerator request_generator = []() { - Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); - auto returned_request_impl = std::make_unique(std::move(header)); - return returned_request_impl; - }; - return request_generator; -} -void RPCRequestSourcePlugin::initOnThread() {} - std::string FileBasedRequestSourceConfigFactory::name() const { return "nighthawk.file-based-request-source-plugin"; } diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index f483d42c5..b9473c50a 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -44,37 +44,6 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig // This factory is activated through ???. DECLARE_FACTORY(DummyRequestSourceConfigFactory); -/** - */ -class RPCRequestSourcePlugin : public RequestSourcePlugin { -public: - explicit RPCRequestSourcePlugin( - const nighthawk::request_source::RPCPluginRequestSourceConfig& config, Envoy::Api::Api& api); - RequestGenerator get() override; - /** - * Will be called on an intialized and running worker thread, before commencing actual work. - * Can be used to prepare the request source implementation (opening any connection or files - * needed, for example). - */ - void initOnThread() override; - -private: - const std::string uri_; -}; - -/** - * Registered as an Envoy plugin. - */ -class RPCRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory { -public: - std::string name() const override; - Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api& api) override; -}; - -// This factory is activated through ???. -DECLARE_FACTORY(RPCRequestSourceConfigFactory); using RequestOptionsIterator = google::protobuf::internal::RepeatedPtrIterator; From 7c5c6b211201d9c03f1b741ef74b92cf72c6260d Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 10 Sep 2020 18:53:38 +0000 Subject: [PATCH 053/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/request_source/BUILD | 2 + .../request_source_plugin_impl.proto | 23 +-- include/nighthawk/common/BUILD | 1 + .../nighthawk/common/request_source_plugin.h | 7 +- source/common/BUILD | 9 +- source/common/request_source_plugin_impl.cc | 36 ++--- source/common/request_source_plugin_impl.h | 5 +- test/mocks/common/BUILD | 1 - test/request_source/BUILD | 9 +- .../request_source_plugin_test.cc | 149 +++++++++--------- 10 files changed, 125 insertions(+), 117 deletions(-) diff --git a/api/request_source/BUILD b/api/request_source/BUILD index da25df27d..32c58eae8 100644 --- a/api/request_source/BUILD +++ b/api/request_source/BUILD @@ -15,6 +15,7 @@ api_cc_py_proto_library( "@envoy_api//envoy/api/v2/core:pkg", ], ) + api_cc_py_proto_library( name = "request_source_plugin", srcs = [ @@ -26,6 +27,7 @@ api_cc_py_proto_library( "@nighthawk//api/client:base", ], ) + cc_grpc_library( name = "grpc_request_source_service_lib", srcs = [ diff --git a/api/request_source/request_source_plugin_impl.proto b/api/request_source/request_source_plugin_impl.proto index e7d571cfd..4b5809d3c 100644 --- a/api/request_source/request_source_plugin_impl.proto +++ b/api/request_source/request_source_plugin_impl.proto @@ -4,17 +4,20 @@ package nighthawk.request_source; import "google/protobuf/wrappers.proto"; -// Configuration for DummyPluginRequestSource (plugin name: "nighthawk.dummy-request-source-plugin") that does nothing +// Configuration for DummyPluginRequestSource (plugin name: "nighthawk.dummy-request-source-plugin") +// that does nothing message DummyPluginRequestSourceConfig { - // Dummy input value. - google.protobuf.DoubleValue dummy_value = 1; - } -// Configuration for RPCPluginRequestSource (plugin name: "nighthawk.rpc-request-source-plugin") that uses rpc -message RPCPluginRequestSourceConfig { + // Dummy input value. + google.protobuf.DoubleValue dummy_value = 1; +} +// Configuration for RPCPluginRequestSource (plugin name: "nighthawk.rpc-request-source-plugin") +// that uses rpc +message RPCPluginRequestSourceConfig { string uri = 1; -} -// Configuration for FileBasedPluginRequestSource (plugin name: "nighthawk.file-based-request-source-plugin") that uses rpc -message FileBasedPluginRequestSourceConfig { +} +// Configuration for FileBasedPluginRequestSource (plugin name: +// "nighthawk.file-based-request-source-plugin") that uses rpc +message FileBasedPluginRequestSourceConfig { string uri = 1; string file_path = 2; -} +} diff --git a/include/nighthawk/common/BUILD b/include/nighthawk/common/BUILD index 71179effc..821c2948f 100644 --- a/include/nighthawk/common/BUILD +++ b/include/nighthawk/common/BUILD @@ -63,6 +63,7 @@ envoy_basic_cc_library( "@envoy//source/common/http:headers_lib", ], ) + envoy_basic_cc_library( name = "request_source_plugin_lib", hdrs = [ diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index 03e70c4de..e86e0807a 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -2,8 +2,8 @@ #include "envoy/api/api.h" #include "envoy/common/pure.h" - #include "envoy/config/typed_config.h" + #include "nighthawk/common/request_source.h" namespace Nighthawk { @@ -15,7 +15,7 @@ namespace Nighthawk { class RequestSourcePlugin : RequestSource { public: RequestSourcePlugin(Envoy::Api::Api& api) : api_(api) {} - virtual ~RequestSourcePlugin() = default; + virtual ~RequestSourcePlugin() = default; // virtual RequestGenerator get() PURE; // virtual void initOnThread() PURE; protected: @@ -43,7 +43,8 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the * plugin. */ - virtual RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) PURE; + virtual RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + Envoy::Api::Api& api) PURE; }; } // namespace Nighthawk \ No newline at end of file diff --git a/source/common/BUILD b/source/common/BUILD index dfb67a2f3..f14ce393b 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -80,6 +80,7 @@ envoy_cc_library( "//include/nighthawk/common:request_source_lib", ], ) + envoy_cc_library( name = "request_source_plugin_impl", srcs = [ @@ -92,14 +93,14 @@ envoy_cc_library( visibility = ["//visibility:public"], deps = [ ":nighthawk_common_lib", - "//include/nighthawk/common:request_source_plugin_lib", - "@envoy//source/common/protobuf:message_validator_lib", ":request_impl_lib", ":request_source_impl_lib", + "//include/nighthawk/common:request_source_plugin_lib", + "@envoy//source/common/protobuf:message_validator_lib", + "@envoy//source/common/protobuf:protobuf_with_external_headers", + "@envoy//source/common/protobuf:utility_lib_with_external_headers", "@envoy//source/exe:platform_header_lib_with_external_headers", "@envoy//source/exe:platform_impl_lib", - "@envoy//source/common/protobuf:utility_lib_with_external_headers", - "@envoy//source/common/protobuf:protobuf_with_external_headers", ], ) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index fcf2ad218..865fcc24e 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -1,17 +1,15 @@ #include "common/request_source_plugin_impl.h" -#include "common/protobuf/message_validator_impl.h" -#include "common/request_impl.h" -#include "common/request_source_impl.h" -#include "external/envoy/source/common/protobuf/utility.h" +#include "external/envoy/source/common/protobuf/utility.h" #include "external/envoy/source/exe/platform_impl.h" #include "api/client/options.pb.h" - #include "api/request_source/request_source_plugin_impl.pb.h" -#include -#include -#include + +#include "common/protobuf/message_validator_impl.h" +#include "common/request_impl.h" +#include "common/request_source_impl.h" + namespace Nighthawk { std::string DummyRequestSourceConfigFactory::name() const { @@ -34,10 +32,10 @@ DummyRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf REGISTER_FACTORY(DummyRequestSourceConfigFactory, RequestSourcePluginConfigFactory); DummyRequestSourcePlugin::DummyRequestSourcePlugin( - const nighthawk::request_source::DummyPluginRequestSourceConfig& config, - Envoy::Api::Api& api) - : RequestSourcePlugin{api}, dummy_value_{config.has_dummy_value() ? config.dummy_value().value() - : std::numeric_limits::infinity()} {} + const nighthawk::request_source::DummyPluginRequestSourceConfig& config, Envoy::Api::Api& api) + : RequestSourcePlugin{api}, dummy_value_{config.has_dummy_value() + ? config.dummy_value().value() + : std::numeric_limits::infinity()} {} RequestGenerator DummyRequestSourcePlugin::get() { RequestGenerator request_generator = []() { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); @@ -71,14 +69,15 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( Envoy::Api::Api& api) : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()) { Envoy::MessageUtil util; - util.loadFromFile(file_path_, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor(), api_, true); + util.loadFromFile(file_path_, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor(), + api_, true); } RequestGenerator FileBasedRequestSourcePlugin::get() { RequestOptionsIterator iterator = optionses_.sub_options().begin(); request_iterators_.push_back(iterator); RequestOptionsIterator* temp = &request_iterators_.back(); - RequestGenerator request_generator = [this, temp]() mutable { + RequestGenerator request_generator = [this, temp]() mutable { nighthawk::client::RequestOptions request_option = **temp; *temp = std::next(*temp); Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); @@ -92,9 +91,9 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { header->setContentLength(content_length); } for (const auto& option_header : request_option.request_headers()) { - auto lower_case_key = Envoy::Http::LowerCaseString(std::string(option_header.header().key())); - header->remove(lower_case_key); - header->addCopy(lower_case_key, std::string(option_header.header().value())); + auto lower_case_key = Envoy::Http::LowerCaseString(std::string(option_header.header().key())); + header->remove(lower_case_key); + header->addCopy(lower_case_key, std::string(option_header.header().value())); } auto returned_request_impl = std::make_unique(std::move(header)); return returned_request_impl; @@ -102,7 +101,6 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { return request_generator; } -void FileBasedRequestSourcePlugin::initOnThread() { -} +void FileBasedRequestSourcePlugin::initOnThread() {} } // namespace Nighthawk \ No newline at end of file diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index b9473c50a..7490420cf 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -6,6 +6,7 @@ #include "api/client/options.pb.h" #include "api/request_source/request_source_plugin_impl.pb.h" + #include "common/uri_impl.h" namespace Nighthawk { @@ -44,8 +45,8 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig // This factory is activated through ???. DECLARE_FACTORY(DummyRequestSourceConfigFactory); - -using RequestOptionsIterator = google::protobuf::internal::RepeatedPtrIterator; +using RequestOptionsIterator = + google::protobuf::internal::RepeatedPtrIterator; /** */ diff --git a/test/mocks/common/BUILD b/test/mocks/common/BUILD index 763ccb63a..e74f25e1c 100644 --- a/test/mocks/common/BUILD +++ b/test/mocks/common/BUILD @@ -87,4 +87,3 @@ envoy_cc_mock( "//include/nighthawk/common:base_includes", ], ) - diff --git a/test/request_source/BUILD b/test/request_source/BUILD index d70bc01f7..c4975875c 100644 --- a/test/request_source/BUILD +++ b/test/request_source/BUILD @@ -1,7 +1,6 @@ load( "@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", - "envoy_cc_test_library", "envoy_package", ) @@ -12,13 +11,13 @@ envoy_package() envoy_cc_test( name = "request_source_plugin_test", srcs = ["request_source_plugin_test.cc"], + data = [ + "test_data/test-config.yaml", + ], repository = "@envoy", deps = [ - "//test/test_common:environment_lib", "//source/common:request_source_plugin_impl", + "//test/test_common:environment_lib", "@envoy//source/common/config:utility_lib_with_external_headers", ], - data = [ - "test_data/test-config.yaml", - ], ) diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 650e0d37f..3f3436e0b 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -1,10 +1,14 @@ -#include "common/request_source_plugin_impl.h" #include "envoy/common/exception.h" + #include "external/envoy/source/common/config/utility.h" #include "external/envoy/test/mocks/stats/mocks.h" #include "external/envoy/test/test_common/file_system_for_test.h" #include "external/envoy/test/test_common/utility.h" + +#include "common/request_source_plugin_impl.h" + #include "test/test_common/environment.h" + #include "gmock/gmock.h" #include "gtest/gtest.h" @@ -35,77 +39,76 @@ class FileBasedRequestSourcePluginTest : public Test { } }; // RequestSourcePluginTest - TEST_F(DummyRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.dummy-request-source-plugin"); - const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); - const nighthawk::request_source::DummyPluginRequestSourceConfig expected_config; - EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); - EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); - } - TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { - nighthawk::request_source::DummyPluginRequestSourceConfig config; - Envoy::ProtobufWkt::Any config_any; - config_any.PackFrom(config); - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.dummy-request-source-plugin"); - EXPECT_EQ(config_factory.name(), "nighthawk.dummy-request-source-plugin"); - } - TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { - nighthawk::request_source::DummyPluginRequestSourceConfig config; - Envoy::ProtobufWkt::Any config_any; - config_any.PackFrom(config); - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.dummy-request-source-plugin"); - RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); - EXPECT_NE(dynamic_cast(plugin.get()), nullptr); - } - TEST_F(FileBasedRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.file-based-request-source-plugin"); - const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); - const nighthawk::request_source::FileBasedPluginRequestSourceConfig expected_config; - EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); - EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); - } - TEST_F(FileBasedRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config; - Envoy::ProtobufWkt::Any config_any; - config_any.PackFrom(config); - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.file-based-request-source-plugin"); - EXPECT_EQ(config_factory.name(), "nighthawk.file-based-request-source-plugin"); - } - TEST_F(FileBasedRequestSourcePluginTest, - CreateRequestSourcePluginCreatesCorrectPluginType) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml(TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); - Envoy::ProtobufWkt::Any config_any; - config_any.PackFrom(config); - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.file-based-request-source-plugin"); - RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); - EXPECT_NE(dynamic_cast(plugin.get()), nullptr); - } - TEST_F(FileBasedRequestSourcePluginTest, - CreateRequestSourcePluginGetsWorkingRequestGenerator) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config = - MakeFileBasedPluginConfigWithTestYaml( - TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); - FileBasedRequestSourcePlugin file_based_request_source(config, - *api_); - auto generator = file_based_request_source.get(); - auto request = generator(); - auto request2 = generator(); - auto header = request -> header(); - auto header2 = request2 -> header(); - EXPECT_EQ ( header->getPathValue(), "/a"); - EXPECT_EQ ( header2->getPathValue(), "/b"); - } +TEST_F(DummyRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.dummy-request-source-plugin"); + const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); + const nighthawk::request_source::DummyPluginRequestSourceConfig expected_config; + EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); + EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); +} +TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { + nighthawk::request_source::DummyPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.dummy-request-source-plugin"); + EXPECT_EQ(config_factory.name(), "nighthawk.dummy-request-source-plugin"); +} +TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { + nighthawk::request_source::DummyPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.dummy-request-source-plugin"); + RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); + EXPECT_NE(dynamic_cast(plugin.get()), nullptr); +} +TEST_F(FileBasedRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); + const nighthawk::request_source::FileBasedPluginRequestSourceConfig expected_config; + EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); + EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); +} +TEST_F(FileBasedRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + EXPECT_EQ(config_factory.name(), "nighthawk.file-based-request-source-plugin"); +} +TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config = + MakeFileBasedPluginConfigWithTestYaml( + TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); + EXPECT_NE(dynamic_cast(plugin.get()), nullptr); +} +TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingRequestGenerator) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config = + MakeFileBasedPluginConfigWithTestYaml( + TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); + FileBasedRequestSourcePlugin file_based_request_source(config, *api_); + auto generator = file_based_request_source.get(); + auto request = generator(); + auto request2 = generator(); + auto header = request->header(); + auto header2 = request2->header(); + EXPECT_EQ(header->getPathValue(), "/a"); + EXPECT_EQ(header2->getPathValue(), "/b"); +} } // namespace } // namespace Nighthawk From 1b02cecfc07bcd6c09726b4719fd617e5aec0d32 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 10 Sep 2020 19:59:13 +0000 Subject: [PATCH 054/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/BUILD | 2 +- source/common/request_source_plugin_impl.cc | 2 +- source/common/request_source_plugin_impl.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/common/BUILD b/source/common/BUILD index f14ce393b..5f2e4eed4 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -96,7 +96,7 @@ envoy_cc_library( ":request_impl_lib", ":request_source_impl_lib", "//include/nighthawk/common:request_source_plugin_lib", - "@envoy//source/common/protobuf:message_validator_lib", + "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", "@envoy//source/common/protobuf:utility_lib_with_external_headers", "@envoy//source/exe:platform_header_lib_with_external_headers", diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 865fcc24e..2c5394b23 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -1,12 +1,12 @@ #include "common/request_source_plugin_impl.h" +#include "external/envoy/source/common/protobuf/message_validator_impl.h" #include "external/envoy/source/common/protobuf/utility.h" #include "external/envoy/source/exe/platform_impl.h" #include "api/client/options.pb.h" #include "api/request_source/request_source_plugin_impl.pb.h" -#include "common/protobuf/message_validator_impl.h" #include "common/request_impl.h" #include "common/request_source_impl.h" diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 7490420cf..f7953de00 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -46,7 +46,7 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig DECLARE_FACTORY(DummyRequestSourceConfigFactory); using RequestOptionsIterator = - google::protobuf::internal::RepeatedPtrIterator; + Envoy::ProtobufWkt::internal::RepeatedPtrIterator; /** */ From 4d75602b8548dadcbc40192fe4fa1cedf6c382ae Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 11 Sep 2020 15:10:48 +0000 Subject: [PATCH 055/114] Fixing clang problems. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/request_source_plugin.h | 2 +- test/request_source/request_source_plugin_test.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index e86e0807a..2e3d5aab1 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -15,7 +15,7 @@ namespace Nighthawk { class RequestSourcePlugin : RequestSource { public: RequestSourcePlugin(Envoy::Api::Api& api) : api_(api) {} - virtual ~RequestSourcePlugin() = default; + override ~RequestSourcePlugin() = default; // virtual RequestGenerator get() PURE; // virtual void initOnThread() PURE; protected: diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 3f3436e0b..5297510aa 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -31,7 +31,7 @@ class FileBasedRequestSourcePluginTest : public Test { Envoy::Api::ApiPtr api_; Envoy::Stats::MockIsolatedStatsStore stats_store_; nighthawk::request_source::FileBasedPluginRequestSourceConfig - MakeFileBasedPluginConfigWithTestYaml(std::string request_file) { + MakeFileBasedPluginConfigWithTestYaml(const std::string& request_file) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config; config.mutable_uri()->assign("http://foo/"); config.mutable_file_path()->assign(request_file); From c74f535eb70364ca0f0c15176c99e9710607c085 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 11 Sep 2020 15:33:03 +0000 Subject: [PATCH 056/114] Fixing clang. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/request_source_plugin.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index 2e3d5aab1..9a763470b 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -15,9 +15,6 @@ namespace Nighthawk { class RequestSourcePlugin : RequestSource { public: RequestSourcePlugin(Envoy::Api::Api& api) : api_(api) {} - override ~RequestSourcePlugin() = default; - // virtual RequestGenerator get() PURE; - // virtual void initOnThread() PURE; protected: Envoy::Api::Api& api_; }; From 9949fb8c42a95db1c62198fdca36deec530bf0dd Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 11 Sep 2020 15:49:47 +0000 Subject: [PATCH 057/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/request_source_plugin.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index 9a763470b..835847947 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -15,6 +15,7 @@ namespace Nighthawk { class RequestSourcePlugin : RequestSource { public: RequestSourcePlugin(Envoy::Api::Api& api) : api_(api) {} + protected: Envoy::Api::Api& api_; }; From fcf10d3c4f62ed71912f8726e3bf9ffb2a8ac78c Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 11 Sep 2020 17:31:37 +0000 Subject: [PATCH 058/114] Fixing clang tidy. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/BUILD | 1 + 1 file changed, 1 insertion(+) diff --git a/include/nighthawk/common/BUILD b/include/nighthawk/common/BUILD index 821c2948f..501edff26 100644 --- a/include/nighthawk/common/BUILD +++ b/include/nighthawk/common/BUILD @@ -72,6 +72,7 @@ envoy_basic_cc_library( include_prefix = "nighthawk/common", deps = [ ":request_source_lib", + "@envoy//source/common/api:api_lib_with_external_headers", "//api/request_source:request_source_plugin_cc_proto", "@envoy//include/envoy/common:base_includes", "@envoy//include/envoy/config:typed_config_interface", From fd9744d0287acd927519d03bf6671162a4e108fa Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 11 Sep 2020 17:47:13 +0000 Subject: [PATCH 059/114] Fix Format Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/nighthawk/common/BUILD b/include/nighthawk/common/BUILD index 501edff26..7a0921dc2 100644 --- a/include/nighthawk/common/BUILD +++ b/include/nighthawk/common/BUILD @@ -72,10 +72,10 @@ envoy_basic_cc_library( include_prefix = "nighthawk/common", deps = [ ":request_source_lib", - "@envoy//source/common/api:api_lib_with_external_headers", "//api/request_source:request_source_plugin_cc_proto", "@envoy//include/envoy/common:base_includes", "@envoy//include/envoy/config:typed_config_interface", + "@envoy//source/common/api:api_lib_with_external_headers", ], ) From 68c103751155e40c383e3e32b917db099fba4190 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 14 Sep 2020 16:23:32 +0000 Subject: [PATCH 060/114] Rename requestOptionses to requestOptionsList. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/client/options.proto | 4 ++-- include/nighthawk/common/factories.h | 2 +- include/nighthawk/common/request_source_plugin.h | 4 +++- source/client/client_worker_impl.cc | 2 +- source/client/factories_impl.cc | 2 +- source/common/request_source_plugin_impl.cc | 6 +++--- source/common/request_source_plugin_impl.h | 4 ++-- test/factories_test.cc | 2 +- test/request_source/test_data/test-config.yaml | 2 +- 9 files changed, 15 insertions(+), 13 deletions(-) diff --git a/api/client/options.proto b/api/client/options.proto index 6fe2f9773..9e3d29e5b 100644 --- a/api/client/options.proto +++ b/api/client/options.proto @@ -18,8 +18,8 @@ message RequestOptions { google.protobuf.UInt32Value request_body_size = 3 [(validate.rules).uint32 = {lte: 4194304}]; } -message RequestOptionses { - repeated RequestOptions sub_options = 1; +message RequestOptionsList { + repeated RequestOptions options = 1; } // Configures a remote gRPC source that will deliver to-be-replayed request data to Nighthawks diff --git a/include/nighthawk/common/factories.h b/include/nighthawk/common/factories.h index d66cf5b8e..c93097b79 100644 --- a/include/nighthawk/common/factories.h +++ b/include/nighthawk/common/factories.h @@ -72,4 +72,4 @@ class NighthawkStatsSinkFactory : public Envoy::Config::TypedFactory { std::string category() const override { return "nighthawk.stats_sinks"; } }; -} // namespace Nighthawk \ No newline at end of file +} // namespace Nighthawk diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index 835847947..7a6d7a82b 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -36,6 +36,8 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * * @param message Any typed_config proto taken from the TypedExtensionConfig. * + * @param api Api parameter that contains timesystem, filesystem, and threadfactory. + * * @return RequestSourcePluginPtr Pointer to the new plugin instance. * * @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the @@ -45,4 +47,4 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { Envoy::Api::Api& api) PURE; }; -} // namespace Nighthawk \ No newline at end of file +} // namespace Nighthawk diff --git a/source/client/client_worker_impl.cc b/source/client/client_worker_impl.cc index 6ddac305f..a5d456763 100644 --- a/source/client/client_worker_impl.cc +++ b/source/client/client_worker_impl.cc @@ -106,4 +106,4 @@ StatisticPtrMap ClientWorkerImpl::statistics() const { } } // namespace Client -} // namespace Nighthawk \ No newline at end of file +} // namespace Nighthawk diff --git a/source/client/factories_impl.cc b/source/client/factories_impl.cc index f0b9f3ab8..ba1cb9e56 100644 --- a/source/client/factories_impl.cc +++ b/source/client/factories_impl.cc @@ -222,4 +222,4 @@ TerminationPredicate* TerminationPredicateFactoryImpl::linkConfiguredPredicates( } } // namespace Client -} // namespace Nighthawk \ No newline at end of file +} // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 2c5394b23..c8aee6e0a 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -69,12 +69,12 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( Envoy::Api::Api& api) : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()) { Envoy::MessageUtil util; - util.loadFromFile(file_path_, optionses_, Envoy::ProtobufMessage::getStrictValidationVisitor(), + util.loadFromFile(file_path_, options_list_, Envoy::ProtobufMessage::getStrictValidationVisitor(), api_, true); } RequestGenerator FileBasedRequestSourcePlugin::get() { - RequestOptionsIterator iterator = optionses_.sub_options().begin(); + RequestOptionsIterator iterator = options_list_.options().begin(); request_iterators_.push_back(iterator); RequestOptionsIterator* temp = &request_iterators_.back(); RequestGenerator request_generator = [this, temp]() mutable { @@ -103,4 +103,4 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { void FileBasedRequestSourcePlugin::initOnThread() {} -} // namespace Nighthawk \ No newline at end of file +} // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index f7953de00..54525c4e4 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -67,7 +67,7 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { const Nighthawk::UriImpl uri_; const std::string file_path_; nighthawk::client::RequestOptions options_; - nighthawk::client::RequestOptionses optionses_; + nighthawk::client::RequestOptionsList options_list_; std::vector request_iterators_; }; /** @@ -84,4 +84,4 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo // This factory is activated through ???. DECLARE_FACTORY(FileBasedRequestSourceConfigFactory); -} // namespace Nighthawk \ No newline at end of file +} // namespace Nighthawk diff --git a/test/factories_test.cc b/test/factories_test.cc index c03442c83..fa4d6dbc7 100644 --- a/test/factories_test.cc +++ b/test/factories_test.cc @@ -130,4 +130,4 @@ INSTANTIATE_TEST_SUITE_P( nighthawk::client::OutputFormat::FORTIO})); } // namespace Client -} // namespace Nighthawk \ No newline at end of file +} // namespace Nighthawk diff --git a/test/request_source/test_data/test-config.yaml b/test/request_source/test_data/test-config.yaml index 07ed5ce11..4facb2195 100644 --- a/test/request_source/test_data/test-config.yaml +++ b/test/request_source/test_data/test-config.yaml @@ -1,4 +1,4 @@ -sub_options: +options: - request_body_size: 10 request_headers: - { header: { key: ":path", value: "/a" } } From 883ee30eb28edc43fbeeb6b4452a98a3c4f9222a Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 15 Sep 2020 15:39:14 +0000 Subject: [PATCH 061/114] Renaming proto. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/request_source/BUILD | 2 +- ...est_source_plugin_impl.proto => request_source_plugin.proto} | 0 source/common/request_source_plugin_impl.cc | 1 - source/common/request_source_plugin_impl.h | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) rename api/request_source/{request_source_plugin_impl.proto => request_source_plugin.proto} (100%) diff --git a/api/request_source/BUILD b/api/request_source/BUILD index 32c58eae8..9cf50e7ff 100644 --- a/api/request_source/BUILD +++ b/api/request_source/BUILD @@ -19,7 +19,7 @@ api_cc_py_proto_library( api_cc_py_proto_library( name = "request_source_plugin", srcs = [ - "request_source_plugin_impl.proto", + "request_source_plugin.proto", ], visibility = ["//visibility:public"], deps = [ diff --git a/api/request_source/request_source_plugin_impl.proto b/api/request_source/request_source_plugin.proto similarity index 100% rename from api/request_source/request_source_plugin_impl.proto rename to api/request_source/request_source_plugin.proto diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index c8aee6e0a..3343544a8 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -5,7 +5,6 @@ #include "external/envoy/source/exe/platform_impl.h" #include "api/client/options.pb.h" -#include "api/request_source/request_source_plugin_impl.pb.h" #include "common/request_impl.h" #include "common/request_source_impl.h" diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 54525c4e4..7a8c81e41 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -5,7 +5,7 @@ #include "nighthawk/common/request_source_plugin.h" #include "api/client/options.pb.h" -#include "api/request_source/request_source_plugin_impl.pb.h" +#include "api/request_source/request_source_plugin.pb.h" #include "common/uri_impl.h" From 8c34b25afe7fde29c80a48b419f587c06610ea60 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 16 Sep 2020 15:09:01 +0000 Subject: [PATCH 062/114] Updating to take a number of requests. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin.proto | 3 ++ source/common/request_source_plugin_impl.cc | 28 +++++++++++++------ source/common/request_source_plugin_impl.h | 3 ++ .../request_source_plugin_test.cc | 23 +++++++++++++++ 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index 4b5809d3c..e48a5f6b0 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -3,6 +3,8 @@ syntax = "proto3"; package nighthawk.request_source; import "google/protobuf/wrappers.proto"; +import "validate/validate.proto"; + // Configuration for DummyPluginRequestSource (plugin name: "nighthawk.dummy-request-source-plugin") // that does nothing @@ -20,4 +22,5 @@ message RPCPluginRequestSourceConfig { message FileBasedPluginRequestSourceConfig { string uri = 1; string file_path = 2; + google.protobuf.UInt32Value num_requests = 3 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; } diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 3343544a8..d0c496682 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -66,19 +66,30 @@ REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigF FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, Envoy::Api::Api& api) - : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()) { + : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()), request_max_(config.num_requests().value()) { Envoy::MessageUtil util; util.loadFromFile(file_path_, options_list_, Envoy::ProtobufMessage::getStrictValidationVisitor(), api_, true); } RequestGenerator FileBasedRequestSourcePlugin::get() { - RequestOptionsIterator iterator = options_list_.options().begin(); - request_iterators_.push_back(iterator); - RequestOptionsIterator* temp = &request_iterators_.back(); - RequestGenerator request_generator = [this, temp]() mutable { - nighthawk::client::RequestOptions request_option = **temp; - *temp = std::next(*temp); + // RequestOptionsIterator iterator = options_list_.options().begin(); + // options_list_.options().at(); + // request_iterators_.push_back(iterator); + // RequestOptionsIterator* temp = &request_iterators_.back(); + uint32_t counter = 0; + request_count_.push_back(counter); + uint32_t* lambda_counter = &request_count_.back(); + RequestGenerator request_generator = [this, lambda_counter]() mutable -> RequestPtr { + // nighthawk::client::RequestOptions request_option = **temp; + // *temp = std::next(*temp); + if (*lambda_counter > request_max_ && request_max_ != 0) + { + return nullptr; + } + auto index = *lambda_counter % options_list_.options_size(); + nighthawk::client::RequestOptions request_option = options_list_.options().at(index); + (*lambda_counter)++; Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); header->setPath(uri_.path()); header->setHost(uri_.hostAndPort()); @@ -94,8 +105,7 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { header->remove(lower_case_key); header->addCopy(lower_case_key, std::string(option_header.header().value())); } - auto returned_request_impl = std::make_unique(std::move(header)); - return returned_request_impl; + return std::make_unique(std::move(header)); }; return request_generator; } diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 7a8c81e41..2c19f0f2f 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -69,6 +69,9 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { nighthawk::client::RequestOptions options_; nighthawk::client::RequestOptionsList options_list_; std::vector request_iterators_; + std::vector request_count_; + const uint32_t request_max_; + }; /** * Registered as an Envoy plugin. diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 5297510aa..868392081 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -101,6 +101,7 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingReq nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml( TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); + config.mutable_num_requests()->set_value(2); FileBasedRequestSourcePlugin file_based_request_source(config, *api_); auto generator = file_based_request_source.get(); auto request = generator(); @@ -110,5 +111,27 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingReq EXPECT_EQ(header->getPathValue(), "/a"); EXPECT_EQ(header2->getPathValue(), "/b"); } +TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginWithMoreNumRequestsThanInFileGetsWorkingRequestGeneratorThatLoops) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config = + MakeFileBasedPluginConfigWithTestYaml( + TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); + config.mutable_num_requests()->set_value(4); + FileBasedRequestSourcePlugin file_based_request_source(config, *api_); + auto generator = file_based_request_source.get(); + auto request = generator(); + auto request2 = generator(); + auto request3 = generator(); + auto header = request->header(); + auto header2 = request2->header(); + auto header3 = request3 -> header(); + std::cerr << header ->getPathValue() +"\n"; + std::cerr << header2 ->getPathValue() +"\n"; + std::cerr << header3 ->getPathValue() +"\n"; + + EXPECT_EQ(header->getPathValue(), "/a"); + EXPECT_EQ(header2->getPathValue(), "/b"); + EXPECT_EQ(header3->getPathValue(), "/a"); + +} } // namespace } // namespace Nighthawk From 6ce7e741be6f2a427fea90390f77c796bfe15b90 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 16 Sep 2020 16:45:05 +0000 Subject: [PATCH 063/114] Clean up tests. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 8 +------- test/request_source/request_source_plugin_test.cc | 9 ++++----- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index d0c496682..f0020e192 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -73,17 +73,11 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( } RequestGenerator FileBasedRequestSourcePlugin::get() { - // RequestOptionsIterator iterator = options_list_.options().begin(); - // options_list_.options().at(); - // request_iterators_.push_back(iterator); - // RequestOptionsIterator* temp = &request_iterators_.back(); uint32_t counter = 0; request_count_.push_back(counter); uint32_t* lambda_counter = &request_count_.back(); RequestGenerator request_generator = [this, lambda_counter]() mutable -> RequestPtr { - // nighthawk::client::RequestOptions request_option = **temp; - // *temp = std::next(*temp); - if (*lambda_counter > request_max_ && request_max_ != 0) + if (*lambda_counter >= request_max_ && request_max_ != 0) { return nullptr; } diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 868392081..5aaf144c8 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -106,10 +106,13 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingReq auto generator = file_based_request_source.get(); auto request = generator(); auto request2 = generator(); + auto request3 = generator(); auto header = request->header(); auto header2 = request2->header(); EXPECT_EQ(header->getPathValue(), "/a"); EXPECT_EQ(header2->getPathValue(), "/b"); + EXPECT_EQ(request3, nullptr); + } TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginWithMoreNumRequestsThanInFileGetsWorkingRequestGeneratorThatLoops) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config = @@ -123,11 +126,7 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginWithMoreNumReq auto request3 = generator(); auto header = request->header(); auto header2 = request2->header(); - auto header3 = request3 -> header(); - std::cerr << header ->getPathValue() +"\n"; - std::cerr << header2 ->getPathValue() +"\n"; - std::cerr << header3 ->getPathValue() +"\n"; - + auto header3 = request3 -> header(); EXPECT_EQ(header->getPathValue(), "/a"); EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(header3->getPathValue(), "/a"); From 92927e51c20bc6cefc387f789845286821c2cfcb Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 16 Sep 2020 17:21:06 +0000 Subject: [PATCH 064/114] Changing visibility of RequestSourcePlugin's inheritance. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../nighthawk/common/request_source_plugin.h | 2 +- .../request_source_plugin_test.cc | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index 7a6d7a82b..b2c707aaa 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -12,7 +12,7 @@ namespace Nighthawk { * An interface for different RequestSource plugins. * Uses a plugin-specific config proto. */ -class RequestSourcePlugin : RequestSource { +class RequestSourcePlugin : public RequestSource { public: RequestSourcePlugin(Envoy::Api::Api& api) : api_(api) {} diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 5aaf144c8..4b1767560 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -102,8 +102,13 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingReq MakeFileBasedPluginConfigWithTestYaml( TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); config.mutable_num_requests()->set_value(2); - FileBasedRequestSourcePlugin file_based_request_source(config, *api_); - auto generator = file_based_request_source.get(); + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + RequestSourcePluginPtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, *api_); + auto generator = file_based_request_source->get(); auto request = generator(); auto request2 = generator(); auto request3 = generator(); @@ -119,8 +124,13 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginWithMoreNumReq MakeFileBasedPluginConfigWithTestYaml( TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); config.mutable_num_requests()->set_value(4); - FileBasedRequestSourcePlugin file_based_request_source(config, *api_); - auto generator = file_based_request_source.get(); + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + RequestSourcePluginPtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, *api_); + auto generator = file_based_request_source->get(); auto request = generator(); auto request2 = generator(); auto request3 = generator(); From a62f2d567daaf9bc48dbd8fc769d127496ec5661 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 16 Sep 2020 21:02:58 +0000 Subject: [PATCH 065/114] Switching to using lock_guard. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin.proto | 2 ++ source/common/BUILD | 2 ++ source/common/request_source_plugin_impl.cc | 27 ++++++++++++------- source/common/request_source_plugin_impl.h | 12 ++++++--- .../request_source_plugin_test.cc | 1 + 5 files changed, 32 insertions(+), 12 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index e48a5f6b0..c71db824d 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -23,4 +23,6 @@ message FileBasedPluginRequestSourceConfig { string uri = 1; string file_path = 2; google.protobuf.UInt32Value num_requests = 3 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; + google.protobuf.UInt32Value max_file_size = 4; + } diff --git a/source/common/BUILD b/source/common/BUILD index 5f2e4eed4..4df378b85 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -95,10 +95,12 @@ envoy_cc_library( ":nighthawk_common_lib", ":request_impl_lib", ":request_source_impl_lib", + "@envoy//source/common/common:thread_lib_with_external_headers", "//include/nighthawk/common:request_source_plugin_lib", "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", "@envoy//source/common/protobuf:utility_lib_with_external_headers", + "@envoy//source/common/event:real_time_system_lib_with_external_headers", "@envoy//source/exe:platform_header_lib_with_external_headers", "@envoy//source/exe:platform_impl_lib", ], diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index f0020e192..7b6d1576a 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -57,19 +57,28 @@ RequestSourcePluginPtr FileBasedRequestSourceConfigFactory::createRequestSourceP const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) { const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginRequestSourceConfig config; - Envoy::MessageUtil::unpackTo(any, config); - return std::make_unique(config, api); + Envoy::MessageUtil util; + util.unpackTo(any, config); + RELEASE_ASSERT(api.fileSystem().fileSize(config.file_path()) < config.max_file_size().value(), "file size must be less than max_file_size"); + auto temp_list = std::make_unique(); + { + Envoy::Thread::LockGuard lock_guard(file_lock_); + if (options_list_.options_size() == 0) + { + util.loadFromFile(config.file_path(), options_list_, Envoy::ProtobufMessage::getStrictValidationVisitor(), + api, true); + } + temp_list->CopyFrom(options_list_); + } + return std::make_unique(config, api, std::move(temp_list)); } REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, - Envoy::Api::Api& api) - : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()), request_max_(config.num_requests().value()) { - Envoy::MessageUtil util; - util.loadFromFile(file_path_, options_list_, Envoy::ProtobufMessage::getStrictValidationVisitor(), - api_, true); + Envoy::Api::Api& api, std::unique_ptr options_list) + : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()), options_list_(std::move(options_list)), request_max_(config.num_requests().value()) { } RequestGenerator FileBasedRequestSourcePlugin::get() { @@ -81,8 +90,8 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { { return nullptr; } - auto index = *lambda_counter % options_list_.options_size(); - nighthawk::client::RequestOptions request_option = options_list_.options().at(index); + auto index = *lambda_counter % options_list_->options_size(); + nighthawk::client::RequestOptions request_option = options_list_->options().at(index); (*lambda_counter)++; Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); header->setPath(uri_.path()); diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 2c19f0f2f..e40742ca8 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -8,6 +8,9 @@ #include "api/request_source/request_source_plugin.pb.h" #include "common/uri_impl.h" +#include "external/envoy/source/common/common/thread.h" +#include "external/envoy/source/common/common/lock_guard.h" +#include "external/envoy/source/common/event/real_time_system.h" namespace Nighthawk { @@ -54,7 +57,7 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { public: explicit FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, - Envoy::Api::Api& api); + Envoy::Api::Api& api, std::unique_ptr options_list); RequestGenerator get() override; /** * Will be called on an intialized and running worker thread, before commencing actual work. @@ -66,8 +69,7 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { private: const Nighthawk::UriImpl uri_; const std::string file_path_; - nighthawk::client::RequestOptions options_; - nighthawk::client::RequestOptionsList options_list_; + const std::unique_ptr options_list_; std::vector request_iterators_; std::vector request_count_; const uint32_t request_max_; @@ -82,8 +84,12 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) override; +private: + Envoy::Thread::MutexBasicLockable file_lock_; + nighthawk::client::RequestOptionsList options_list_ ABSL_GUARDED_BY(file_lock_);; }; + // This factory is activated through ???. DECLARE_FACTORY(FileBasedRequestSourceConfigFactory); diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 4b1767560..4e6fca6aa 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -35,6 +35,7 @@ class FileBasedRequestSourcePluginTest : public Test { nighthawk::request_source::FileBasedPluginRequestSourceConfig config; config.mutable_uri()->assign("http://foo/"); config.mutable_file_path()->assign(request_file); + config.mutable_max_file_size()->set_value(4000); return config; } }; // RequestSourcePluginTest From 16f89c66250bd0bab5175934417ca50ba9519a83 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 16 Sep 2020 21:43:28 +0000 Subject: [PATCH 066/114] Clean up. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/BUILD | 1 - source/common/request_source_plugin_impl.h | 1 - 2 files changed, 2 deletions(-) diff --git a/source/common/BUILD b/source/common/BUILD index 4df378b85..9ed9fee60 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -100,7 +100,6 @@ envoy_cc_library( "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", "@envoy//source/common/protobuf:utility_lib_with_external_headers", - "@envoy//source/common/event:real_time_system_lib_with_external_headers", "@envoy//source/exe:platform_header_lib_with_external_headers", "@envoy//source/exe:platform_impl_lib", ], diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index e40742ca8..12b1332e1 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -10,7 +10,6 @@ #include "common/uri_impl.h" #include "external/envoy/source/common/common/thread.h" #include "external/envoy/source/common/common/lock_guard.h" -#include "external/envoy/source/common/event/real_time_system.h" namespace Nighthawk { From f4257e3ed5cd8d2c9df2fa0dce966dc85370fb4a Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 16 Sep 2020 21:56:04 +0000 Subject: [PATCH 067/114] Fix Format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin.proto | 2 -- source/common/BUILD | 2 +- source/common/request_source_plugin_impl.cc | 21 +++++++++---------- source/common/request_source_plugin_impl.h | 11 +++++----- .../request_source_plugin_test.cc | 13 ++++++------ 5 files changed, 24 insertions(+), 25 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index c71db824d..78000fe4e 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -5,7 +5,6 @@ package nighthawk.request_source; import "google/protobuf/wrappers.proto"; import "validate/validate.proto"; - // Configuration for DummyPluginRequestSource (plugin name: "nighthawk.dummy-request-source-plugin") // that does nothing message DummyPluginRequestSourceConfig { @@ -24,5 +23,4 @@ message FileBasedPluginRequestSourceConfig { string file_path = 2; google.protobuf.UInt32Value num_requests = 3 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; google.protobuf.UInt32Value max_file_size = 4; - } diff --git a/source/common/BUILD b/source/common/BUILD index 9ed9fee60..1dac362f3 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -95,8 +95,8 @@ envoy_cc_library( ":nighthawk_common_lib", ":request_impl_lib", ":request_source_impl_lib", - "@envoy//source/common/common:thread_lib_with_external_headers", "//include/nighthawk/common:request_source_plugin_lib", + "@envoy//source/common/common:thread_lib_with_external_headers", "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", "@envoy//source/common/protobuf:utility_lib_with_external_headers", diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 7b6d1576a..ee89189da 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -58,15 +58,15 @@ RequestSourcePluginPtr FileBasedRequestSourceConfigFactory::createRequestSourceP const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::MessageUtil util; - util.unpackTo(any, config); - RELEASE_ASSERT(api.fileSystem().fileSize(config.file_path()) < config.max_file_size().value(), "file size must be less than max_file_size"); + util.unpackTo(any, config); + RELEASE_ASSERT(api.fileSystem().fileSize(config.file_path()) < config.max_file_size().value(), + "file size must be less than max_file_size"); auto temp_list = std::make_unique(); { - Envoy::Thread::LockGuard lock_guard(file_lock_); - if (options_list_.options_size() == 0) - { - util.loadFromFile(config.file_path(), options_list_, Envoy::ProtobufMessage::getStrictValidationVisitor(), - api, true); + Envoy::Thread::LockGuard lock_guard(file_lock_); + if (options_list_.options_size() == 0) { + util.loadFromFile(config.file_path(), options_list_, + Envoy::ProtobufMessage::getStrictValidationVisitor(), api, true); } temp_list->CopyFrom(options_list_); } @@ -78,16 +78,15 @@ REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigF FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, Envoy::Api::Api& api, std::unique_ptr options_list) - : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()), options_list_(std::move(options_list)), request_max_(config.num_requests().value()) { -} + : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()), + options_list_(std::move(options_list)), request_max_(config.num_requests().value()) {} RequestGenerator FileBasedRequestSourcePlugin::get() { uint32_t counter = 0; request_count_.push_back(counter); uint32_t* lambda_counter = &request_count_.back(); RequestGenerator request_generator = [this, lambda_counter]() mutable -> RequestPtr { - if (*lambda_counter >= request_max_ && request_max_ != 0) - { + if (*lambda_counter >= request_max_ && request_max_ != 0) { return nullptr; } auto index = *lambda_counter % options_list_->options_size(); diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 12b1332e1..b165ab373 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -4,12 +4,13 @@ #include "nighthawk/common/request_source_plugin.h" +#include "external/envoy/source/common/common/lock_guard.h" +#include "external/envoy/source/common/common/thread.h" + #include "api/client/options.pb.h" #include "api/request_source/request_source_plugin.pb.h" #include "common/uri_impl.h" -#include "external/envoy/source/common/common/thread.h" -#include "external/envoy/source/common/common/lock_guard.h" namespace Nighthawk { @@ -72,7 +73,6 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { std::vector request_iterators_; std::vector request_count_; const uint32_t request_max_; - }; /** * Registered as an Envoy plugin. @@ -83,12 +83,13 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) override; + private: Envoy::Thread::MutexBasicLockable file_lock_; - nighthawk::client::RequestOptionsList options_list_ ABSL_GUARDED_BY(file_lock_);; + nighthawk::client::RequestOptionsList options_list_ ABSL_GUARDED_BY(file_lock_); + ; }; - // This factory is activated through ???. DECLARE_FACTORY(FileBasedRequestSourceConfigFactory); diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 4e6fca6aa..83246fa64 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -108,7 +108,8 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingReq auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - RequestSourcePluginPtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, *api_); + RequestSourcePluginPtr file_based_request_source = + config_factory.createRequestSourcePlugin(config_any, *api_); auto generator = file_based_request_source->get(); auto request = generator(); auto request2 = generator(); @@ -118,9 +119,9 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingReq EXPECT_EQ(header->getPathValue(), "/a"); EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(request3, nullptr); - } -TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginWithMoreNumRequestsThanInFileGetsWorkingRequestGeneratorThatLoops) { +TEST_F(FileBasedRequestSourcePluginTest, + CreateRequestSourcePluginWithMoreNumRequestsThanInFileGetsWorkingRequestGeneratorThatLoops) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml( TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); @@ -130,18 +131,18 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginWithMoreNumReq auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - RequestSourcePluginPtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, *api_); + RequestSourcePluginPtr file_based_request_source = + config_factory.createRequestSourcePlugin(config_any, *api_); auto generator = file_based_request_source->get(); auto request = generator(); auto request2 = generator(); auto request3 = generator(); auto header = request->header(); auto header2 = request2->header(); - auto header3 = request3 -> header(); + auto header3 = request3->header(); EXPECT_EQ(header->getPathValue(), "/a"); EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(header3->getPathValue(), "/a"); - } } // namespace } // namespace Nighthawk From d075588acd67066a395048819d7ef823fcdbb95a Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 17 Sep 2020 16:19:59 +0000 Subject: [PATCH 068/114] Addressing comments on PR. Cleaning up formatting. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/client/options.proto | 2 ++ api/request_source/request_source_plugin.proto | 2 ++ source/common/request_source_plugin_impl.cc | 3 +-- source/common/request_source_plugin_impl.h | 2 ++ .../request_source/request_source_plugin_test.cc | 16 ++++++++++++---- test/request_source/test_data/test-config.yaml | 4 ++-- 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/api/client/options.proto b/api/client/options.proto index 9e3d29e5b..9b93ca0ce 100644 --- a/api/client/options.proto +++ b/api/client/options.proto @@ -18,7 +18,9 @@ message RequestOptions { google.protobuf.UInt32Value request_body_size = 3 [(validate.rules).uint32 = {lte: 4194304}]; } +// Used for providing multiple request options, especially for RequestSourcePlugins. message RequestOptionsList { + // Each option is used for a separate request to be sent by the requestSource. repeated RequestOptions options = 1; } diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index 78000fe4e..351ce36a4 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -11,11 +11,13 @@ message DummyPluginRequestSourceConfig { // Dummy input value. google.protobuf.DoubleValue dummy_value = 1; } + // Configuration for RPCPluginRequestSource (plugin name: "nighthawk.rpc-request-source-plugin") // that uses rpc message RPCPluginRequestSourceConfig { string uri = 1; } + // Configuration for FileBasedPluginRequestSource (plugin name: // "nighthawk.file-based-request-source-plugin") that uses rpc message FileBasedPluginRequestSourceConfig { diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index ee89189da..3249c90e2 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -104,8 +104,7 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { } for (const auto& option_header : request_option.request_headers()) { auto lower_case_key = Envoy::Http::LowerCaseString(std::string(option_header.header().key())); - header->remove(lower_case_key); - header->addCopy(lower_case_key, std::string(option_header.header().value())); + header->setCopy(lower_case_key, std::string(option_header.header().value())); } return std::make_unique(std::move(header)); }; diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index b165ab373..e4d5d7648 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -52,6 +52,8 @@ using RequestOptionsIterator = Envoy::ProtobufWkt::internal::RepeatedPtrIterator; /** + * Sample Request Source for small files. Loads the file in and replays the request specifications from the file. Each worker will keep the file contents in memory. + * It will provide num_requests number of requests, looping as required. 0 requests means infinite requests. */ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { public: diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 83246fa64..206b3266f 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -24,21 +24,22 @@ class DummyRequestSourcePluginTest : public Test { DummyRequestSourcePluginTest() : api_(Envoy::Api::createApiForTest(stats_store_)) {} Envoy::Api::ApiPtr api_; Envoy::Stats::MockIsolatedStatsStore stats_store_; -}; // RequestSourcePluginTest +}; + class FileBasedRequestSourcePluginTest : public Test { public: FileBasedRequestSourcePluginTest() : api_(Envoy::Api::createApiForTest(stats_store_)) {} Envoy::Api::ApiPtr api_; Envoy::Stats::MockIsolatedStatsStore stats_store_; nighthawk::request_source::FileBasedPluginRequestSourceConfig - MakeFileBasedPluginConfigWithTestYaml(const std::string& request_file) { + MakeFileBasedPluginConfigWithTestYaml(absl::string_view request_file) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config; config.mutable_uri()->assign("http://foo/"); config.mutable_file_path()->assign(request_file); config.mutable_max_file_size()->set_value(4000); return config; } -}; // RequestSourcePluginTest +}; TEST_F(DummyRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { auto& config_factory = @@ -49,6 +50,7 @@ TEST_F(DummyRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); } + TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { nighthawk::request_source::DummyPluginRequestSourceConfig config; Envoy::ProtobufWkt::Any config_any; @@ -58,6 +60,7 @@ TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { "nighthawk.dummy-request-source-plugin"); EXPECT_EQ(config_factory.name(), "nighthawk.dummy-request-source-plugin"); } + TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { nighthawk::request_source::DummyPluginRequestSourceConfig config; Envoy::ProtobufWkt::Any config_any; @@ -68,6 +71,7 @@ TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlug RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } + TEST_F(FileBasedRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( @@ -77,6 +81,7 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectTyp EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); } + TEST_F(FileBasedRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::ProtobufWkt::Any config_any; @@ -86,6 +91,7 @@ TEST_F(FileBasedRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginNam "nighthawk.file-based-request-source-plugin"); EXPECT_EQ(config_factory.name(), "nighthawk.file-based-request-source-plugin"); } + TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml( @@ -98,7 +104,8 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } -TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingRequestGenerator) { + +TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingRequestGeneratorThatEndsAtNumRequest) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml( TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); @@ -120,6 +127,7 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingReq EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(request3, nullptr); } + TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginWithMoreNumRequestsThanInFileGetsWorkingRequestGeneratorThatLoops) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config = diff --git a/test/request_source/test_data/test-config.yaml b/test/request_source/test_data/test-config.yaml index 4facb2195..e8b4cdaac 100644 --- a/test/request_source/test_data/test-config.yaml +++ b/test/request_source/test_data/test-config.yaml @@ -3,11 +3,11 @@ options: request_headers: - { header: { key: ":path", value: "/a" } } - { header: { key: "foo", value: "bar" } } - - { header: { key: "foo", value: "bar2" }, append: true } + - { header: { key: "foo", value: "bar2" } } - { header: { key: "x-nh", value: "1" } } - request_body_size: 10 request_headers: - { header: { key: ":path", value: "/b" } } - { header: { key: "bar", value: "foo" } } - - { header: { key: "bar", value: "foo2" }, append: true } + - { header: { key: "bar", value: "foo2" } } - { header: { key: "x-nh", value: "2" } } \ No newline at end of file From eb10a3bd90e10066242c08c87ddb9b0ccfd5590f Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 17 Sep 2020 17:38:35 +0000 Subject: [PATCH 069/114] Getting rid of RequestSourcePluginPtr, and adding comments. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/request_source_plugin.h | 6 ++---- source/common/request_source_plugin_impl.cc | 4 ++-- source/common/request_source_plugin_impl.h | 9 +++++---- test/request_source/request_source_plugin_test.cc | 8 ++++---- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index b2c707aaa..288f594a0 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -20,8 +20,6 @@ class RequestSourcePlugin : public RequestSource { Envoy::Api::Api& api_; }; -using RequestSourcePluginPtr = std::unique_ptr; - /** * A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific * RequestSourcePlugin class after unpacking the plugin-specific config proto. @@ -38,12 +36,12 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * * @param api Api parameter that contains timesystem, filesystem, and threadfactory. * - * @return RequestSourcePluginPtr Pointer to the new plugin instance. + * @return RequestSourcePtr Pointer to the new plugin instance. * * @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the * plugin. */ - virtual RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) PURE; }; diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 3249c90e2..2891df506 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -19,7 +19,7 @@ Envoy::ProtobufTypes::MessagePtr DummyRequestSourceConfigFactory::createEmptyCon return std::make_unique(); } -RequestSourcePluginPtr +RequestSourcePtr DummyRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) { const auto& any = dynamic_cast(message); @@ -53,7 +53,7 @@ Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourceConfigFactory::createEmpt return std::make_unique(); } -RequestSourcePluginPtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( +RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) { const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginRequestSourceConfig config; diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index e4d5d7648..c6e1cdc6b 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -15,6 +15,7 @@ namespace Nighthawk { /** + * Sample Request Source implementation for comparison. */ class DummyRequestSourcePlugin : public RequestSourcePlugin { public: @@ -41,11 +42,11 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig public: std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) override; }; -// This factory is activated through ???. +// This factory will be activated through RequestSourceFactory in factories.h DECLARE_FACTORY(DummyRequestSourceConfigFactory); using RequestOptionsIterator = @@ -83,7 +84,7 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo public: std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - RequestSourcePluginPtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) override; private: @@ -92,7 +93,7 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo ; }; -// This factory is activated through ???. +// This factory will be activated through RequestSourceFactory in factories.h DECLARE_FACTORY(FileBasedRequestSourceConfigFactory); } // namespace Nighthawk diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 206b3266f..9f1e7267c 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -68,7 +68,7 @@ TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlug auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.dummy-request-source-plugin"); - RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); + RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } @@ -101,7 +101,7 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - RequestSourcePluginPtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); + RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } @@ -115,7 +115,7 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingReq auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - RequestSourcePluginPtr file_based_request_source = + RequestSourcePtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, *api_); auto generator = file_based_request_source->get(); auto request = generator(); @@ -139,7 +139,7 @@ TEST_F(FileBasedRequestSourcePluginTest, auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - RequestSourcePluginPtr file_based_request_source = + RequestSourcePtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, *api_); auto generator = file_based_request_source->get(); auto request = generator(); From cdbd6bfbb99cd1a623e6a6fb8930d4097eb12f14 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 17 Sep 2020 19:14:40 +0000 Subject: [PATCH 070/114] Removing unnecessary RequestSourcePlugin interface for improved testability and cleanliness. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/request_source_plugin.h | 10 ---------- source/common/request_source_plugin_impl.cc | 16 +++++++++------- source/common/request_source_plugin_impl.h | 12 ++++-------- 3 files changed, 13 insertions(+), 25 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index 288f594a0..7f3d3c46d 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -8,17 +8,7 @@ namespace Nighthawk { -/** - * An interface for different RequestSource plugins. - * Uses a plugin-specific config proto. - */ -class RequestSourcePlugin : public RequestSource { -public: - RequestSourcePlugin(Envoy::Api::Api& api) : api_(api) {} -protected: - Envoy::Api::Api& api_; -}; /** * A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 2891df506..82b324569 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -11,6 +11,7 @@ namespace Nighthawk { + std::string DummyRequestSourceConfigFactory::name() const { return "nighthawk.dummy-request-source-plugin"; } @@ -21,18 +22,18 @@ Envoy::ProtobufTypes::MessagePtr DummyRequestSourceConfigFactory::createEmptyCon RequestSourcePtr DummyRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api& api) { + Envoy::Api::Api&) { const auto& any = dynamic_cast(message); nighthawk::request_source::DummyPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); - return std::make_unique(config, api); + return std::make_unique(config); } REGISTER_FACTORY(DummyRequestSourceConfigFactory, RequestSourcePluginConfigFactory); DummyRequestSourcePlugin::DummyRequestSourcePlugin( - const nighthawk::request_source::DummyPluginRequestSourceConfig& config, Envoy::Api::Api& api) - : RequestSourcePlugin{api}, dummy_value_{config.has_dummy_value() + const nighthawk::request_source::DummyPluginRequestSourceConfig& config) + : dummy_value_{config.has_dummy_value() ? config.dummy_value().value() : std::numeric_limits::infinity()} {} RequestGenerator DummyRequestSourcePlugin::get() { @@ -43,6 +44,7 @@ RequestGenerator DummyRequestSourcePlugin::get() { }; return request_generator; } + void DummyRequestSourcePlugin::initOnThread() {} std::string FileBasedRequestSourceConfigFactory::name() const { @@ -70,15 +72,15 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( } temp_list->CopyFrom(options_list_); } - return std::make_unique(config, api, std::move(temp_list)); + return std::make_unique(config, std::move(temp_list)); } REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, - Envoy::Api::Api& api, std::unique_ptr options_list) - : RequestSourcePlugin{api}, uri_(config.uri()), file_path_(config.file_path()), + std::unique_ptr options_list) + : uri_(config.uri()), file_path_(config.file_path()), options_list_(std::move(options_list)), request_max_(config.num_requests().value()) {} RequestGenerator FileBasedRequestSourcePlugin::get() { diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index c6e1cdc6b..413d793a9 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -17,11 +17,10 @@ namespace Nighthawk { /** * Sample Request Source implementation for comparison. */ -class DummyRequestSourcePlugin : public RequestSourcePlugin { +class DummyRequestSourcePlugin : public RequestSource { public: explicit DummyRequestSourcePlugin( - const nighthawk::request_source::DummyPluginRequestSourceConfig& config, - Envoy::Api::Api& api); + const nighthawk::request_source::DummyPluginRequestSourceConfig& config); RequestGenerator get() override; /** * Will be called on an intialized and running worker thread, before commencing actual work. @@ -29,7 +28,6 @@ class DummyRequestSourcePlugin : public RequestSourcePlugin { * needed, for example). */ void initOnThread() override; - private: const double dummy_value_; }; @@ -56,11 +54,10 @@ using RequestOptionsIterator = * Sample Request Source for small files. Loads the file in and replays the request specifications from the file. Each worker will keep the file contents in memory. * It will provide num_requests number of requests, looping as required. 0 requests means infinite requests. */ -class FileBasedRequestSourcePlugin : public RequestSourcePlugin { +class FileBasedRequestSourcePlugin : public RequestSource { public: explicit FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, - Envoy::Api::Api& api, std::unique_ptr options_list); + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, std::unique_ptr options_list); RequestGenerator get() override; /** * Will be called on an intialized and running worker thread, before commencing actual work. @@ -68,7 +65,6 @@ class FileBasedRequestSourcePlugin : public RequestSourcePlugin { * needed, for example). */ void initOnThread() override; - private: const Nighthawk::UriImpl uri_; const std::string file_path_; From 17acc5fb41946b44746e5b63b9de6f75b517226e Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 17 Sep 2020 20:59:42 +0000 Subject: [PATCH 071/114] Fix format Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/request_source_plugin.h | 4 +--- source/common/request_source_plugin_impl.cc | 10 ++++------ source/common/request_source_plugin_impl.h | 14 +++++++++----- test/request_source/request_source_plugin_test.cc | 3 ++- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin.h index 7f3d3c46d..b3548c75c 100644 --- a/include/nighthawk/common/request_source_plugin.h +++ b/include/nighthawk/common/request_source_plugin.h @@ -8,8 +8,6 @@ namespace Nighthawk { - - /** * A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific * RequestSourcePlugin class after unpacking the plugin-specific config proto. @@ -32,7 +30,7 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * plugin. */ virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api& api) PURE; + Envoy::Api::Api& api) PURE; }; } // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 82b324569..50bf0fc13 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -11,7 +11,6 @@ namespace Nighthawk { - std::string DummyRequestSourceConfigFactory::name() const { return "nighthawk.dummy-request-source-plugin"; } @@ -33,9 +32,8 @@ REGISTER_FACTORY(DummyRequestSourceConfigFactory, RequestSourcePluginConfigFacto DummyRequestSourcePlugin::DummyRequestSourcePlugin( const nighthawk::request_source::DummyPluginRequestSourceConfig& config) - : dummy_value_{config.has_dummy_value() - ? config.dummy_value().value() - : std::numeric_limits::infinity()} {} + : dummy_value_{config.has_dummy_value() ? config.dummy_value().value() + : std::numeric_limits::infinity()} {} RequestGenerator DummyRequestSourcePlugin::get() { RequestGenerator request_generator = []() { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); @@ -80,8 +78,8 @@ REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigF FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, std::unique_ptr options_list) - : uri_(config.uri()), file_path_(config.file_path()), - options_list_(std::move(options_list)), request_max_(config.num_requests().value()) {} + : uri_(config.uri()), file_path_(config.file_path()), options_list_(std::move(options_list)), + request_max_(config.num_requests().value()) {} RequestGenerator FileBasedRequestSourcePlugin::get() { uint32_t counter = 0; diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 413d793a9..f88b50089 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -28,6 +28,7 @@ class DummyRequestSourcePlugin : public RequestSource { * needed, for example). */ void initOnThread() override; + private: const double dummy_value_; }; @@ -41,7 +42,7 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api& api) override; + Envoy::Api::Api& api) override; }; // This factory will be activated through RequestSourceFactory in factories.h @@ -51,13 +52,15 @@ using RequestOptionsIterator = Envoy::ProtobufWkt::internal::RepeatedPtrIterator; /** - * Sample Request Source for small files. Loads the file in and replays the request specifications from the file. Each worker will keep the file contents in memory. - * It will provide num_requests number of requests, looping as required. 0 requests means infinite requests. + * Sample Request Source for small files. Loads the file in and replays the request specifications + * from the file. Each worker will keep the file contents in memory. It will provide num_requests + * number of requests, looping as required. 0 requests means infinite requests. */ class FileBasedRequestSourcePlugin : public RequestSource { public: explicit FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, std::unique_ptr options_list); + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, + std::unique_ptr options_list); RequestGenerator get() override; /** * Will be called on an intialized and running worker thread, before commencing actual work. @@ -65,6 +68,7 @@ class FileBasedRequestSourcePlugin : public RequestSource { * needed, for example). */ void initOnThread() override; + private: const Nighthawk::UriImpl uri_; const std::string file_path_; @@ -81,7 +85,7 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api& api) override; + Envoy::Api::Api& api) override; private: Envoy::Thread::MutexBasicLockable file_lock_; diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 9f1e7267c..0dbe74aa6 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -105,7 +105,8 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } -TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingRequestGeneratorThatEndsAtNumRequest) { +TEST_F(FileBasedRequestSourcePluginTest, + CreateRequestSourcePluginGetsWorkingRequestGeneratorThatEndsAtNumRequest) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config = MakeFileBasedPluginConfigWithTestYaml( TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); From 55a0e62c7463c5a2d2aa8de9af15093670e7b183 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 18 Sep 2020 14:49:13 +0000 Subject: [PATCH 072/114] Cleanup unintentional whitespace. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/client/factories_impl.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/client/factories_impl.h b/source/client/factories_impl.h index 7a542b6b0..5e508b65a 100644 --- a/source/client/factories_impl.h +++ b/source/client/factories_impl.h @@ -80,4 +80,4 @@ class TerminationPredicateFactoryImpl : public OptionBasedFactoryImpl, }; } // namespace Client -} // namespace Nighthawk \ No newline at end of file +} // namespace Nighthawk From fa23aad722092b3880ee22025cf9142d576f2069 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 18 Sep 2020 14:49:37 +0000 Subject: [PATCH 073/114] Swapping to exception instead of Release_assert. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 50bf0fc13..4604aca67 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -59,8 +59,10 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::MessageUtil util; util.unpackTo(any, config); - RELEASE_ASSERT(api.fileSystem().fileSize(config.file_path()) < config.max_file_size().value(), - "file size must be less than max_file_size"); + if(api.fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) + { + throw NighthawkException("file size must be less than max_file_size"); + } auto temp_list = std::make_unique(); { Envoy::Thread::LockGuard lock_guard(file_lock_); From b8e24473a00902241e24b5661df663abad8ba80c Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 18 Sep 2020 15:04:05 +0000 Subject: [PATCH 074/114] Renaming the request_source_plugin to request_source_plugin_config_factory. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/BUILD | 4 ++-- ...source_plugin.h => request_source_plugin_config_factory.h} | 0 source/common/BUILD | 2 +- source/common/request_source_plugin_impl.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename include/nighthawk/common/{request_source_plugin.h => request_source_plugin_config_factory.h} (100%) diff --git a/include/nighthawk/common/BUILD b/include/nighthawk/common/BUILD index 7a0921dc2..71aefd7f7 100644 --- a/include/nighthawk/common/BUILD +++ b/include/nighthawk/common/BUILD @@ -65,9 +65,9 @@ envoy_basic_cc_library( ) envoy_basic_cc_library( - name = "request_source_plugin_lib", + name = "request_source_plugin_config_factory_lib", hdrs = [ - "request_source_plugin.h", + "request_source_plugin_config_factory.h", ], include_prefix = "nighthawk/common", deps = [ diff --git a/include/nighthawk/common/request_source_plugin.h b/include/nighthawk/common/request_source_plugin_config_factory.h similarity index 100% rename from include/nighthawk/common/request_source_plugin.h rename to include/nighthawk/common/request_source_plugin_config_factory.h diff --git a/source/common/BUILD b/source/common/BUILD index 1dac362f3..191077805 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -95,7 +95,7 @@ envoy_cc_library( ":nighthawk_common_lib", ":request_impl_lib", ":request_source_impl_lib", - "//include/nighthawk/common:request_source_plugin_lib", + "//include/nighthawk/common:request_source_plugin_config_factory_lib", "@envoy//source/common/common:thread_lib_with_external_headers", "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index f88b50089..d7ded2f2a 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -2,7 +2,7 @@ #include "envoy/registry/registry.h" -#include "nighthawk/common/request_source_plugin.h" +#include "nighthawk/common/request_source_plugin_config_factory.h" #include "external/envoy/source/common/common/lock_guard.h" #include "external/envoy/source/common/common/thread.h" From 248f439e1e91d0d8a8281c690597ca0524aaadc4 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 22 Sep 2020 07:16:15 +0000 Subject: [PATCH 075/114] Using a context struct for extensability. Taking in a header to enable pluggability. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin.proto | 7 +++--- .../request_source_plugin_config_factory.h | 11 +++++++++- source/common/request_source_plugin_impl.cc | 18 +++++++-------- source/common/request_source_plugin_impl.h | 9 ++++---- .../request_source_plugin_test.cc | 22 +++++++++++-------- 5 files changed, 38 insertions(+), 29 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index 351ce36a4..b2317dd83 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -21,8 +21,7 @@ message RPCPluginRequestSourceConfig { // Configuration for FileBasedPluginRequestSource (plugin name: // "nighthawk.file-based-request-source-plugin") that uses rpc message FileBasedPluginRequestSourceConfig { - string uri = 1; - string file_path = 2; - google.protobuf.UInt32Value num_requests = 3 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; - google.protobuf.UInt32Value max_file_size = 4; + string file_path = 1; + google.protobuf.UInt32Value num_requests = 2 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; + google.protobuf.UInt32Value max_file_size = 3; } diff --git a/include/nighthawk/common/request_source_plugin_config_factory.h b/include/nighthawk/common/request_source_plugin_config_factory.h index b3548c75c..398570dd3 100644 --- a/include/nighthawk/common/request_source_plugin_config_factory.h +++ b/include/nighthawk/common/request_source_plugin_config_factory.h @@ -8,6 +8,15 @@ namespace Nighthawk { + struct RequestSourceContext { + RequestSourceContext(RequestSourceContext& context) : api(std::move(context.api)), header(std::move(context.header)) {} + RequestSourceContext(Envoy::Api::ApiPtr api_input, Envoy::Http::RequestHeaderMapPtr header_input) : + api(std::move(api_input)), header(std::move(header_input)){} + Envoy::Api::ApiPtr api; + Envoy::Http::RequestHeaderMapPtr header; + }; +using RequestSourceContextPtr = std::unique_ptr; + /** * A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific * RequestSourcePlugin class after unpacking the plugin-specific config proto. @@ -30,7 +39,7 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * plugin. */ virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api& api) PURE; + RequestSourceContextPtr context) PURE; }; } // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 4604aca67..78ca03440 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -21,7 +21,7 @@ Envoy::ProtobufTypes::MessagePtr DummyRequestSourceConfigFactory::createEmptyCon RequestSourcePtr DummyRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api&) { + RequestSourceContextPtr) { const auto& any = dynamic_cast(message); nighthawk::request_source::DummyPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); @@ -54,12 +54,12 @@ Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourceConfigFactory::createEmpt } RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message, Envoy::Api::Api& api) { + const Envoy::Protobuf::Message& message, RequestSourceContextPtr context) { const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::MessageUtil util; util.unpackTo(any, config); - if(api.fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) + if(context->api->fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) { throw NighthawkException("file size must be less than max_file_size"); } @@ -68,19 +68,20 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( Envoy::Thread::LockGuard lock_guard(file_lock_); if (options_list_.options_size() == 0) { util.loadFromFile(config.file_path(), options_list_, - Envoy::ProtobufMessage::getStrictValidationVisitor(), api, true); + Envoy::ProtobufMessage::getStrictValidationVisitor(), *(context->api), true); } temp_list->CopyFrom(options_list_); } - return std::make_unique(config, std::move(temp_list)); + return std::make_unique(config, std::move(context), std::move(temp_list)); } REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, + RequestSourceContextPtr context, std::unique_ptr options_list) - : uri_(config.uri()), file_path_(config.file_path()), options_list_(std::move(options_list)), + : context_(std::move(context)), options_list_(std::move(options_list)), request_max_(config.num_requests().value()) {} RequestGenerator FileBasedRequestSourcePlugin::get() { @@ -95,10 +96,7 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { nighthawk::client::RequestOptions request_option = options_list_->options().at(index); (*lambda_counter)++; Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); - header->setPath(uri_.path()); - header->setHost(uri_.hostAndPort()); - header->setScheme(uri_.scheme() == "https" ? Envoy::Http::Headers::get().SchemeValues.Https - : Envoy::Http::Headers::get().SchemeValues.Http); + Envoy::Http::HeaderMapImpl::copyFrom(*header, *(context_->header)); header->setMethod(envoy::config::core::v3::RequestMethod_Name(request_option.request_method())); const uint32_t content_length = request_option.request_body_size().value(); if (content_length > 0) { diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index d7ded2f2a..93bb4cfe3 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -42,7 +42,7 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api& api) override; + RequestSourceContextPtr context) override; }; // This factory will be activated through RequestSourceFactory in factories.h @@ -59,7 +59,7 @@ using RequestOptionsIterator = class FileBasedRequestSourcePlugin : public RequestSource { public: explicit FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, RequestSourceContextPtr context, std::unique_ptr options_list); RequestGenerator get() override; /** @@ -70,8 +70,7 @@ class FileBasedRequestSourcePlugin : public RequestSource { void initOnThread() override; private: - const Nighthawk::UriImpl uri_; - const std::string file_path_; + RequestSourceContextPtr context_; const std::unique_ptr options_list_; std::vector request_iterators_; std::vector request_count_; @@ -85,7 +84,7 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::Api& api) override; + RequestSourceContextPtr context) override; private: Envoy::Thread::MutexBasicLockable file_lock_; diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 0dbe74aa6..4a8dca915 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -21,20 +21,19 @@ using ::testing::Test; class DummyRequestSourcePluginTest : public Test { public: - DummyRequestSourcePluginTest() : api_(Envoy::Api::createApiForTest(stats_store_)) {} - Envoy::Api::ApiPtr api_; + DummyRequestSourcePluginTest() : context_(Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()) {} + Nighthawk::RequestSourceContext context_; Envoy::Stats::MockIsolatedStatsStore stats_store_; }; class FileBasedRequestSourcePluginTest : public Test { public: - FileBasedRequestSourcePluginTest() : api_(Envoy::Api::createApiForTest(stats_store_)) {} - Envoy::Api::ApiPtr api_; + FileBasedRequestSourcePluginTest() : context_(Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()) {} + Nighthawk::RequestSourceContext context_; Envoy::Stats::MockIsolatedStatsStore stats_store_; nighthawk::request_source::FileBasedPluginRequestSourceConfig MakeFileBasedPluginConfigWithTestYaml(absl::string_view request_file) { nighthawk::request_source::FileBasedPluginRequestSourceConfig config; - config.mutable_uri()->assign("http://foo/"); config.mutable_file_path()->assign(request_file); config.mutable_max_file_size()->set_value(4000); return config; @@ -68,7 +67,8 @@ TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlug auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.dummy-request-source-plugin"); - RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); + auto context = std::make_unique(context_); + RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, std::move(context)); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } @@ -101,7 +101,8 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, *api_); + auto context = std::make_unique(context_); + RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, std::move(context)); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } @@ -116,8 +117,10 @@ TEST_F(FileBasedRequestSourcePluginTest, auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); + auto context = std::make_unique(context_); + RequestSourcePtr file_based_request_source = - config_factory.createRequestSourcePlugin(config_any, *api_); + config_factory.createRequestSourcePlugin(config_any, std::move(context)); auto generator = file_based_request_source->get(); auto request = generator(); auto request2 = generator(); @@ -140,8 +143,9 @@ TEST_F(FileBasedRequestSourcePluginTest, auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); + auto context = std::make_unique(context_); RequestSourcePtr file_based_request_source = - config_factory.createRequestSourcePlugin(config_any, *api_); + config_factory.createRequestSourcePlugin(config_any, std::move(context)); auto generator = file_based_request_source->get(); auto request = generator(); auto request2 = generator(); From 91703b53b50c053f55908068a245cc112555456e Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 22 Sep 2020 07:38:42 +0000 Subject: [PATCH 076/114] Spacing and comments. Using a reference for lambda counter instead of pointer. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 19 +++++++++++++++---- source/common/request_source_plugin_impl.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 78ca03440..d3af3536c 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -35,6 +35,7 @@ DummyRequestSourcePlugin::DummyRequestSourcePlugin( : dummy_value_{config.has_dummy_value() ? config.dummy_value().value() : std::numeric_limits::infinity()} {} RequestGenerator DummyRequestSourcePlugin::get() { + RequestGenerator request_generator = []() { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); auto returned_request_impl = std::make_unique(std::move(header)); @@ -64,6 +65,8 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( throw NighthawkException("file size must be less than max_file_size"); } auto temp_list = std::make_unique(); + + //Locking to avoid issues with multiple threads reading the same file. { Envoy::Thread::LockGuard lock_guard(file_lock_); if (options_list_.options_size() == 0) { @@ -87,16 +90,24 @@ FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( RequestGenerator FileBasedRequestSourcePlugin::get() { uint32_t counter = 0; request_count_.push_back(counter); - uint32_t* lambda_counter = &request_count_.back(); + uint32_t& lambda_counter = request_count_.back(); RequestGenerator request_generator = [this, lambda_counter]() mutable -> RequestPtr { - if (*lambda_counter >= request_max_ && request_max_ != 0) { + + //if request_max is 0, then we never stop generating requests. + if (lambda_counter >= request_max_ && request_max_ != 0) { return nullptr; } - auto index = *lambda_counter % options_list_->options_size(); + + //Increment the counter and get the request_option from the list for the current iteration. + auto index = lambda_counter % options_list_->options_size(); nighthawk::client::RequestOptions request_option = options_list_->options().at(index); - (*lambda_counter)++; + lambda_counter++; + + //Initialize the header with the values from the context header. Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); Envoy::Http::HeaderMapImpl::copyFrom(*header, *(context_->header)); + + //Override the default values with the values from the request_option header->setMethod(envoy::config::core::v3::RequestMethod_Name(request_option.request_method())); const uint32_t content_length = request_option.request_body_size().value(); if (content_length > 0) { diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 93bb4cfe3..b664604ee 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -76,6 +76,7 @@ class FileBasedRequestSourcePlugin : public RequestSource { std::vector request_count_; const uint32_t request_max_; }; + /** * Registered as an Envoy plugin. */ From bbc0c2a1e92933dca661e17a583e96600d81e9e1 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 22 Sep 2020 07:44:01 +0000 Subject: [PATCH 077/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin_config_factory.h | 15 ++++++------ source/common/request_source_plugin_impl.cc | 24 +++++++++---------- source/common/request_source_plugin_impl.h | 3 ++- .../request_source_plugin_test.cc | 22 ++++++++++------- 4 files changed, 36 insertions(+), 28 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin_config_factory.h b/include/nighthawk/common/request_source_plugin_config_factory.h index 398570dd3..f271047e2 100644 --- a/include/nighthawk/common/request_source_plugin_config_factory.h +++ b/include/nighthawk/common/request_source_plugin_config_factory.h @@ -8,13 +8,14 @@ namespace Nighthawk { - struct RequestSourceContext { - RequestSourceContext(RequestSourceContext& context) : api(std::move(context.api)), header(std::move(context.header)) {} - RequestSourceContext(Envoy::Api::ApiPtr api_input, Envoy::Http::RequestHeaderMapPtr header_input) : - api(std::move(api_input)), header(std::move(header_input)){} - Envoy::Api::ApiPtr api; - Envoy::Http::RequestHeaderMapPtr header; - }; +struct RequestSourceContext { + RequestSourceContext(RequestSourceContext& context) + : api(std::move(context.api)), header(std::move(context.header)) {} + RequestSourceContext(Envoy::Api::ApiPtr api_input, Envoy::Http::RequestHeaderMapPtr header_input) + : api(std::move(api_input)), header(std::move(header_input)) {} + Envoy::Api::ApiPtr api; + Envoy::Http::RequestHeaderMapPtr header; +}; using RequestSourceContextPtr = std::unique_ptr; /** diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index d3af3536c..a1801d89a 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -60,22 +60,23 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::MessageUtil util; util.unpackTo(any, config); - if(context->api->fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) - { + if (context->api->fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) { throw NighthawkException("file size must be less than max_file_size"); } auto temp_list = std::make_unique(); - //Locking to avoid issues with multiple threads reading the same file. + // Locking to avoid issues with multiple threads reading the same file. { Envoy::Thread::LockGuard lock_guard(file_lock_); if (options_list_.options_size() == 0) { util.loadFromFile(config.file_path(), options_list_, - Envoy::ProtobufMessage::getStrictValidationVisitor(), *(context->api), true); + Envoy::ProtobufMessage::getStrictValidationVisitor(), *(context->api), + true); } temp_list->CopyFrom(options_list_); } - return std::make_unique(config, std::move(context), std::move(temp_list)); + return std::make_unique(config, std::move(context), + std::move(temp_list)); } REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); @@ -92,22 +93,21 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { request_count_.push_back(counter); uint32_t& lambda_counter = request_count_.back(); RequestGenerator request_generator = [this, lambda_counter]() mutable -> RequestPtr { - - //if request_max is 0, then we never stop generating requests. + // if request_max is 0, then we never stop generating requests. if (lambda_counter >= request_max_ && request_max_ != 0) { return nullptr; } - - //Increment the counter and get the request_option from the list for the current iteration. + + // Increment the counter and get the request_option from the list for the current iteration. auto index = lambda_counter % options_list_->options_size(); nighthawk::client::RequestOptions request_option = options_list_->options().at(index); lambda_counter++; - - //Initialize the header with the values from the context header. + + // Initialize the header with the values from the context header. Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); Envoy::Http::HeaderMapImpl::copyFrom(*header, *(context_->header)); - //Override the default values with the values from the request_option + // Override the default values with the values from the request_option header->setMethod(envoy::config::core::v3::RequestMethod_Name(request_option.request_method())); const uint32_t content_length = request_option.request_body_size().value(); if (content_length > 0) { diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index b664604ee..a12454270 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -59,7 +59,8 @@ using RequestOptionsIterator = class FileBasedRequestSourcePlugin : public RequestSource { public: explicit FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, RequestSourceContextPtr context, + const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, + RequestSourceContextPtr context, std::unique_ptr options_list); RequestGenerator get() override; /** diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 4a8dca915..473d1b299 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -21,14 +21,18 @@ using ::testing::Test; class DummyRequestSourcePluginTest : public Test { public: - DummyRequestSourcePluginTest() : context_(Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()) {} + DummyRequestSourcePluginTest() + : context_(Envoy::Api::createApiForTest(stats_store_), + Envoy::Http::RequestHeaderMapImpl::create()) {} Nighthawk::RequestSourceContext context_; Envoy::Stats::MockIsolatedStatsStore stats_store_; }; class FileBasedRequestSourcePluginTest : public Test { public: - FileBasedRequestSourcePluginTest() : context_(Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()) {} + FileBasedRequestSourcePluginTest() + : context_(Envoy::Api::createApiForTest(stats_store_), + Envoy::Http::RequestHeaderMapImpl::create()) {} Nighthawk::RequestSourceContext context_; Envoy::Stats::MockIsolatedStatsStore stats_store_; nighthawk::request_source::FileBasedPluginRequestSourceConfig @@ -67,8 +71,9 @@ TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlug auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.dummy-request-source-plugin"); - auto context = std::make_unique(context_); - RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, std::move(context)); + auto context = std::make_unique(context_); + RequestSourcePtr plugin = + config_factory.createRequestSourcePlugin(config_any, std::move(context)); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } @@ -101,8 +106,9 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - auto context = std::make_unique(context_); - RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, std::move(context)); + auto context = std::make_unique(context_); + RequestSourcePtr plugin = + config_factory.createRequestSourcePlugin(config_any, std::move(context)); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } @@ -117,7 +123,7 @@ TEST_F(FileBasedRequestSourcePluginTest, auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - auto context = std::make_unique(context_); + auto context = std::make_unique(context_); RequestSourcePtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, std::move(context)); @@ -143,7 +149,7 @@ TEST_F(FileBasedRequestSourcePluginTest, auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - auto context = std::make_unique(context_); + auto context = std::make_unique(context_); RequestSourcePtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, std::move(context)); auto generator = file_based_request_source->get(); From 517c83dc70aa8277bf77d633bc112bef19eb2d3a Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 22 Sep 2020 08:22:55 +0000 Subject: [PATCH 078/114] Adding test for multiple request sources thread lock. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/request_source/BUILD | 1 + .../request_source_plugin_test.cc | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/test/request_source/BUILD b/test/request_source/BUILD index c4975875c..1dc858b26 100644 --- a/test/request_source/BUILD +++ b/test/request_source/BUILD @@ -19,5 +19,6 @@ envoy_cc_test( "//source/common:request_source_plugin_impl", "//test/test_common:environment_lib", "@envoy//source/common/config:utility_lib_with_external_headers", + "@envoy//test/mocks/api:api_mocks", ], ) diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 473d1b299..1298bbf87 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -1,6 +1,7 @@ #include "envoy/common/exception.h" #include "external/envoy/source/common/config/utility.h" +#include "external/envoy/test/mocks/api/mocks.h" #include "external/envoy/test/mocks/stats/mocks.h" #include "external/envoy/test/test_common/file_system_for_test.h" #include "external/envoy/test/test_common/utility.h" @@ -17,6 +18,7 @@ namespace Nighthawk { namespace { using nighthawk::request_source::DummyPluginRequestSourceConfig; using nighthawk::request_source::FileBasedPluginRequestSourceConfig; +using ::testing::NiceMock; using ::testing::Test; class DummyRequestSourcePluginTest : public Test { @@ -163,5 +165,24 @@ TEST_F(FileBasedRequestSourcePluginTest, EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(header3->getPathValue(), "/a"); } +TEST_F(FileBasedRequestSourcePluginTest, CreateMultipleRequestSourcePluginReadsFileOnce) { + nighthawk::request_source::FileBasedPluginRequestSourceConfig config = + MakeFileBasedPluginConfigWithTestYaml( + TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); + config.mutable_num_requests()->set_value(4); + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.file-based-request-source-plugin"); + auto context = std::make_unique( + Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()); + auto context2 = std::make_unique( + Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()); + RequestSourcePtr file_based_request_source = + config_factory.createRequestSourcePlugin(config_any, std::move(context)); + RequestSourcePtr file_based_request_source2 = + config_factory.createRequestSourcePlugin(config_any, std::move(context2)); +} } // namespace } // namespace Nighthawk From c1d0428d76153332d4c6b2cc0f5990d96e10c1ed Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 22 Sep 2020 08:30:15 +0000 Subject: [PATCH 079/114] Additional comment Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index a1801d89a..b5ae28437 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -68,6 +68,7 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( // Locking to avoid issues with multiple threads reading the same file. { Envoy::Thread::LockGuard lock_guard(file_lock_); + // Reading the file only the first time. if (options_list_.options_size() == 0) { util.loadFromFile(config.file_path(), options_list_, Envoy::ProtobufMessage::getStrictValidationVisitor(), *(context->api), From bc86c09b89809f1217522556f7f2e3e8d316f3b9 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 22 Sep 2020 20:56:34 +0000 Subject: [PATCH 080/114] Getting rid of context object because the Register Factory mechanism wouldn't make sense to extend the parameters passed in. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin_config_factory.h | 14 +--- source/common/request_source_plugin_impl.cc | 19 ++--- source/common/request_source_plugin_impl.h | 8 +- .../request_source_plugin_test.cc | 77 +++++++++---------- 4 files changed, 53 insertions(+), 65 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin_config_factory.h b/include/nighthawk/common/request_source_plugin_config_factory.h index f271047e2..786258dd8 100644 --- a/include/nighthawk/common/request_source_plugin_config_factory.h +++ b/include/nighthawk/common/request_source_plugin_config_factory.h @@ -8,16 +8,6 @@ namespace Nighthawk { -struct RequestSourceContext { - RequestSourceContext(RequestSourceContext& context) - : api(std::move(context.api)), header(std::move(context.header)) {} - RequestSourceContext(Envoy::Api::ApiPtr api_input, Envoy::Http::RequestHeaderMapPtr header_input) - : api(std::move(api_input)), header(std::move(header_input)) {} - Envoy::Api::ApiPtr api; - Envoy::Http::RequestHeaderMapPtr header; -}; -using RequestSourceContextPtr = std::unique_ptr; - /** * A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific * RequestSourcePlugin class after unpacking the plugin-specific config proto. @@ -39,8 +29,8 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the * plugin. */ - virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - RequestSourceContextPtr context) PURE; + virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& typed_config, + Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) PURE; }; } // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index b5ae28437..78ca833a1 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -21,7 +21,7 @@ Envoy::ProtobufTypes::MessagePtr DummyRequestSourceConfigFactory::createEmptyCon RequestSourcePtr DummyRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - RequestSourceContextPtr) { + Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr) { const auto& any = dynamic_cast(message); nighthawk::request_source::DummyPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); @@ -55,12 +55,13 @@ Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourceConfigFactory::createEmpt } RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message, RequestSourceContextPtr context) { + const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) { const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::MessageUtil util; + util.unpackTo(any, config); - if (context->api->fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) { + if (api->fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) { throw NighthawkException("file size must be less than max_file_size"); } auto temp_list = std::make_unique(); @@ -71,12 +72,12 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( // Reading the file only the first time. if (options_list_.options_size() == 0) { util.loadFromFile(config.file_path(), options_list_, - Envoy::ProtobufMessage::getStrictValidationVisitor(), *(context->api), + Envoy::ProtobufMessage::getStrictValidationVisitor(), *api, true); } temp_list->CopyFrom(options_list_); } - return std::make_unique(config, std::move(context), + return std::make_unique(config, std::move(header), std::move(temp_list)); } @@ -84,9 +85,9 @@ REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigF FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, - RequestSourceContextPtr context, + Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list) - : context_(std::move(context)), options_list_(std::move(options_list)), + : header_(std::move(header)), options_list_(std::move(options_list)), request_max_(config.num_requests().value()) {} RequestGenerator FileBasedRequestSourcePlugin::get() { @@ -104,9 +105,9 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { nighthawk::client::RequestOptions request_option = options_list_->options().at(index); lambda_counter++; - // Initialize the header with the values from the context header. + // Initialize the header with the values from the default header. Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); - Envoy::Http::HeaderMapImpl::copyFrom(*header, *(context_->header)); + Envoy::Http::HeaderMapImpl::copyFrom(*header, *header_); // Override the default values with the values from the request_option header->setMethod(envoy::config::core::v3::RequestMethod_Name(request_option.request_method())); diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index a12454270..fc1a98cab 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -42,7 +42,7 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - RequestSourceContextPtr context) override; + Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) override; }; // This factory will be activated through RequestSourceFactory in factories.h @@ -60,7 +60,7 @@ class FileBasedRequestSourcePlugin : public RequestSource { public: explicit FileBasedRequestSourcePlugin( const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, - RequestSourceContextPtr context, + Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list); RequestGenerator get() override; /** @@ -71,7 +71,7 @@ class FileBasedRequestSourcePlugin : public RequestSource { void initOnThread() override; private: - RequestSourceContextPtr context_; + Envoy::Http::RequestHeaderMapPtr header_; const std::unique_ptr options_list_; std::vector request_iterators_; std::vector request_count_; @@ -86,7 +86,7 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - RequestSourceContextPtr context) override; + Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) override; private: Envoy::Thread::MutexBasicLockable file_lock_; diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 1298bbf87..cbea4426b 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -23,19 +23,13 @@ using ::testing::Test; class DummyRequestSourcePluginTest : public Test { public: - DummyRequestSourcePluginTest() - : context_(Envoy::Api::createApiForTest(stats_store_), - Envoy::Http::RequestHeaderMapImpl::create()) {} - Nighthawk::RequestSourceContext context_; + DummyRequestSourcePluginTest(){} Envoy::Stats::MockIsolatedStatsStore stats_store_; }; class FileBasedRequestSourcePluginTest : public Test { public: - FileBasedRequestSourcePluginTest() - : context_(Envoy::Api::createApiForTest(stats_store_), - Envoy::Http::RequestHeaderMapImpl::create()) {} - Nighthawk::RequestSourceContext context_; + FileBasedRequestSourcePluginTest() {} Envoy::Stats::MockIsolatedStatsStore stats_store_; nighthawk::request_source::FileBasedPluginRequestSourceConfig MakeFileBasedPluginConfigWithTestYaml(absl::string_view request_file) { @@ -73,9 +67,10 @@ TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlug auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.dummy-request-source-plugin"); - auto context = std::make_unique(context_); + auto api = Envoy::Api::createApiForTest(stats_store_); + auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr plugin = - config_factory.createRequestSourcePlugin(config_any, std::move(context)); + config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } @@ -108,9 +103,10 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - auto context = std::make_unique(context_); + auto api = Envoy::Api::createApiForTest(stats_store_); + auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr plugin = - config_factory.createRequestSourcePlugin(config_any, std::move(context)); + config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } @@ -125,17 +121,17 @@ TEST_F(FileBasedRequestSourcePluginTest, auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - auto context = std::make_unique(context_); - + auto api = Envoy::Api::createApiForTest(stats_store_); + auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr file_based_request_source = - config_factory.createRequestSourcePlugin(config_any, std::move(context)); + config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); auto generator = file_based_request_source->get(); auto request = generator(); auto request2 = generator(); auto request3 = generator(); - auto header = request->header(); + auto header1 = request->header(); auto header2 = request2->header(); - EXPECT_EQ(header->getPathValue(), "/a"); + EXPECT_EQ(header1->getPathValue(), "/a"); EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(request3, nullptr); } @@ -151,38 +147,39 @@ TEST_F(FileBasedRequestSourcePluginTest, auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - auto context = std::make_unique(context_); + auto api = Envoy::Api::createApiForTest(stats_store_); + auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr file_based_request_source = - config_factory.createRequestSourcePlugin(config_any, std::move(context)); + config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); auto generator = file_based_request_source->get(); auto request = generator(); auto request2 = generator(); auto request3 = generator(); - auto header = request->header(); + auto header1 = request->header(); auto header2 = request2->header(); auto header3 = request3->header(); - EXPECT_EQ(header->getPathValue(), "/a"); + EXPECT_EQ(header1->getPathValue(), "/a"); EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(header3->getPathValue(), "/a"); } -TEST_F(FileBasedRequestSourcePluginTest, CreateMultipleRequestSourcePluginReadsFileOnce) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config = - MakeFileBasedPluginConfigWithTestYaml( - TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); - config.mutable_num_requests()->set_value(4); - Envoy::ProtobufWkt::Any config_any; - config_any.PackFrom(config); - auto& config_factory = - Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.file-based-request-source-plugin"); - auto context = std::make_unique( - Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()); - auto context2 = std::make_unique( - Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()); - RequestSourcePtr file_based_request_source = - config_factory.createRequestSourcePlugin(config_any, std::move(context)); - RequestSourcePtr file_based_request_source2 = - config_factory.createRequestSourcePlugin(config_any, std::move(context2)); -} +// TEST_F(FileBasedRequestSourcePluginTest, CreateMultipleRequestSourcePluginReadsFileOnce) { +// nighthawk::request_source::FileBasedPluginRequestSourceConfig config = +// MakeFileBasedPluginConfigWithTestYaml( +// TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); +// config.mutable_num_requests()->set_value(4); +// Envoy::ProtobufWkt::Any config_any; +// config_any.PackFrom(config); +// auto& config_factory = +// Envoy::Config::Utility::getAndCheckFactoryByName( +// "nighthawk.file-based-request-source-plugin"); +// auto context = std::make_unique( +// Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()); +// auto context2 = std::make_unique( +// Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()); +// RequestSourcePtr file_based_request_source = +// config_factory.createRequestSourcePlugin(config_any, std::move(context)); +// RequestSourcePtr file_based_request_source2 = +// config_factory.createRequestSourcePlugin(config_any, std::move(context2)); +// } } // namespace } // namespace Nighthawk From 33e35648fcfe68c35860fa98adb5325c47d9b732 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 23 Sep 2020 16:14:41 +0000 Subject: [PATCH 081/114] Adding option to circumvent file reading. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin.proto | 8 ++++++ source/common/request_source_plugin_impl.cc | 27 ++++++++++++++++--- source/common/request_source_plugin_impl.h | 20 +++++++++++--- .../request_source_plugin_test.cc | 19 ------------- 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index b2317dd83..7e553b7f4 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -4,6 +4,7 @@ package nighthawk.request_source; import "google/protobuf/wrappers.proto"; import "validate/validate.proto"; +import "api/client/options.proto"; // Configuration for DummyPluginRequestSource (plugin name: "nighthawk.dummy-request-source-plugin") // that does nothing @@ -25,3 +26,10 @@ message FileBasedPluginRequestSourceConfig { google.protobuf.UInt32Value num_requests = 2 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; google.protobuf.UInt32Value max_file_size = 3; } + +// Configuration for RequestOptionsListPluginRequestSource (plugin name: +// "nighthawk.request-options-list-request-source-plugin") that uses rpc +message RequestOptionsListPluginRequestSourceConfig { + nighthawk.client.RequestOptionsList options_list = 1; + google.protobuf.UInt32Value num_requests = 2 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; +} diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 78ca833a1..1ba60d53d 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -77,18 +77,18 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( } temp_list->CopyFrom(options_list_); } - return std::make_unique(config, std::move(header), + return std::make_unique(config.num_requests().value(), std::move(header), std::move(temp_list)); } REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, + const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list) : header_(std::move(header)), options_list_(std::move(options_list)), - request_max_(config.num_requests().value()) {} + request_max_(request_max) {} RequestGenerator FileBasedRequestSourcePlugin::get() { uint32_t counter = 0; @@ -126,4 +126,25 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { void FileBasedRequestSourcePlugin::initOnThread() {} +std::string RequestOptionsListRequestSourceConfigFactory::name() const { + return "nighthawk.request-options-list-request-source-plugin"; +} + +Envoy::ProtobufTypes::MessagePtr RequestOptionsListRequestSourceConfigFactory::createEmptyConfigProto() { + return std::make_unique(); +} + +RequestSourcePtr +RequestOptionsListRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr header) { + const auto& any = dynamic_cast(message); + nighthawk::request_source::RequestOptionsListPluginRequestSourceConfig config; + Envoy::MessageUtil::unpackTo(any, config); + auto temp_list = std::make_unique(config.options_list()); + return std::make_unique(config.num_requests().value(), std::move(header), std::move(temp_list)); +} + +REGISTER_FACTORY(RequestOptionsListRequestSourceConfigFactory, RequestSourcePluginConfigFactory); + + } // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index fc1a98cab..8d7a3c441 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -59,7 +59,7 @@ using RequestOptionsIterator = class FileBasedRequestSourcePlugin : public RequestSource { public: explicit FileBasedRequestSourcePlugin( - const nighthawk::request_source::FileBasedPluginRequestSourceConfig& config, + const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list); RequestGenerator get() override; @@ -90,11 +90,25 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo private: Envoy::Thread::MutexBasicLockable file_lock_; - nighthawk::client::RequestOptionsList options_list_ ABSL_GUARDED_BY(file_lock_); - ; + nighthawk::client::RequestOptionsList options_list_ ABSL_GUARDED_BY(file_lock_); }; // This factory will be activated through RequestSourceFactory in factories.h DECLARE_FACTORY(FileBasedRequestSourceConfigFactory); + +/** + * Registered as an Envoy plugin. + */ +class RequestOptionsListRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory { +public: + std::string name() const override; + Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; + RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) override; +}; + +// This factory will be activated through RequestSourceFactory in factories.h +DECLARE_FACTORY(RequestOptionsListRequestSourceConfigFactory); + } // namespace Nighthawk diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index cbea4426b..727c24cf2 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -162,24 +162,5 @@ TEST_F(FileBasedRequestSourcePluginTest, EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(header3->getPathValue(), "/a"); } -// TEST_F(FileBasedRequestSourcePluginTest, CreateMultipleRequestSourcePluginReadsFileOnce) { -// nighthawk::request_source::FileBasedPluginRequestSourceConfig config = -// MakeFileBasedPluginConfigWithTestYaml( -// TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); -// config.mutable_num_requests()->set_value(4); -// Envoy::ProtobufWkt::Any config_any; -// config_any.PackFrom(config); -// auto& config_factory = -// Envoy::Config::Utility::getAndCheckFactoryByName( -// "nighthawk.file-based-request-source-plugin"); -// auto context = std::make_unique( -// Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()); -// auto context2 = std::make_unique( -// Envoy::Api::createApiForTest(stats_store_), Envoy::Http::RequestHeaderMapImpl::create()); -// RequestSourcePtr file_based_request_source = -// config_factory.createRequestSourcePlugin(config_any, std::move(context)); -// RequestSourcePtr file_based_request_source2 = -// config_factory.createRequestSourcePlugin(config_any, std::move(context2)); -// } } // namespace } // namespace Nighthawk From 402ada237955c64a2aa3fc549aa01b0bd53300f7 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 23 Sep 2020 17:21:36 +0000 Subject: [PATCH 082/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin_config_factory.h | 3 +- source/common/request_source_plugin_impl.cc | 31 +++++++++---------- source/common/request_source_plugin_impl.h | 18 ++++++----- .../request_source_plugin_test.cc | 2 +- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/include/nighthawk/common/request_source_plugin_config_factory.h b/include/nighthawk/common/request_source_plugin_config_factory.h index 786258dd8..dee2106ba 100644 --- a/include/nighthawk/common/request_source_plugin_config_factory.h +++ b/include/nighthawk/common/request_source_plugin_config_factory.h @@ -30,7 +30,8 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * plugin. */ virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& typed_config, - Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) PURE; + Envoy::Api::ApiPtr api, + Envoy::Http::RequestHeaderMapPtr header) PURE; }; } // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 1ba60d53d..3913fc7b0 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -19,9 +19,8 @@ Envoy::ProtobufTypes::MessagePtr DummyRequestSourceConfigFactory::createEmptyCon return std::make_unique(); } -RequestSourcePtr -DummyRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr) { +RequestSourcePtr DummyRequestSourceConfigFactory::createRequestSourcePlugin( + const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr) { const auto& any = dynamic_cast(message); nighthawk::request_source::DummyPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); @@ -55,7 +54,8 @@ Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourceConfigFactory::createEmpt } RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) { + const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr api, + Envoy::Http::RequestHeaderMapPtr header) { const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginRequestSourceConfig config; Envoy::MessageUtil util; @@ -72,20 +72,18 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( // Reading the file only the first time. if (options_list_.options_size() == 0) { util.loadFromFile(config.file_path(), options_list_, - Envoy::ProtobufMessage::getStrictValidationVisitor(), *api, - true); + Envoy::ProtobufMessage::getStrictValidationVisitor(), *api, true); } temp_list->CopyFrom(options_list_); } - return std::make_unique(config.num_requests().value(), std::move(header), - std::move(temp_list)); + return std::make_unique(config.num_requests().value(), + std::move(header), std::move(temp_list)); } REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( - const uint32_t request_max, - Envoy::Http::RequestHeaderMapPtr header, + const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list) : header_(std::move(header)), options_list_(std::move(options_list)), request_max_(request_max) {} @@ -130,21 +128,22 @@ std::string RequestOptionsListRequestSourceConfigFactory::name() const { return "nighthawk.request-options-list-request-source-plugin"; } -Envoy::ProtobufTypes::MessagePtr RequestOptionsListRequestSourceConfigFactory::createEmptyConfigProto() { +Envoy::ProtobufTypes::MessagePtr +RequestOptionsListRequestSourceConfigFactory::createEmptyConfigProto() { return std::make_unique(); } -RequestSourcePtr -RequestOptionsListRequestSourceConfigFactory::createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr header) { +RequestSourcePtr RequestOptionsListRequestSourceConfigFactory::createRequestSourcePlugin( + const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, + Envoy::Http::RequestHeaderMapPtr header) { const auto& any = dynamic_cast(message); nighthawk::request_source::RequestOptionsListPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); auto temp_list = std::make_unique(config.options_list()); - return std::make_unique(config.num_requests().value(), std::move(header), std::move(temp_list)); + return std::make_unique(config.num_requests().value(), + std::move(header), std::move(temp_list)); } REGISTER_FACTORY(RequestOptionsListRequestSourceConfigFactory, RequestSourcePluginConfigFactory); - } // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 8d7a3c441..aa2d1effd 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -42,7 +42,8 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) override; + Envoy::Api::ApiPtr api, + Envoy::Http::RequestHeaderMapPtr header) override; }; // This factory will be activated through RequestSourceFactory in factories.h @@ -59,8 +60,7 @@ using RequestOptionsIterator = class FileBasedRequestSourcePlugin : public RequestSource { public: explicit FileBasedRequestSourcePlugin( - const uint32_t request_max, - Envoy::Http::RequestHeaderMapPtr header, + const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list); RequestGenerator get() override; /** @@ -86,26 +86,28 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) override; + Envoy::Api::ApiPtr api, + Envoy::Http::RequestHeaderMapPtr header) override; private: Envoy::Thread::MutexBasicLockable file_lock_; - nighthawk::client::RequestOptionsList options_list_ ABSL_GUARDED_BY(file_lock_); + nighthawk::client::RequestOptionsList options_list_ ABSL_GUARDED_BY(file_lock_); }; // This factory will be activated through RequestSourceFactory in factories.h DECLARE_FACTORY(FileBasedRequestSourceConfigFactory); - /** * Registered as an Envoy plugin. */ -class RequestOptionsListRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory { +class RequestOptionsListRequestSourceConfigFactory + : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) override; + Envoy::Api::ApiPtr api, + Envoy::Http::RequestHeaderMapPtr header) override; }; // This factory will be activated through RequestSourceFactory in factories.h diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 727c24cf2..e931704ae 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -23,7 +23,7 @@ using ::testing::Test; class DummyRequestSourcePluginTest : public Test { public: - DummyRequestSourcePluginTest(){} + DummyRequestSourcePluginTest() {} Envoy::Stats::MockIsolatedStatsStore stats_store_; }; From 017481fcf5195b4b8a162a8bf469d5aa83e25d34 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 23 Sep 2020 17:26:14 +0000 Subject: [PATCH 083/114] Getting rid of default constructors. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/request_source/request_source_plugin_test.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index e931704ae..ec2be4253 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -23,13 +23,11 @@ using ::testing::Test; class DummyRequestSourcePluginTest : public Test { public: - DummyRequestSourcePluginTest() {} Envoy::Stats::MockIsolatedStatsStore stats_store_; }; class FileBasedRequestSourcePluginTest : public Test { public: - FileBasedRequestSourcePluginTest() {} Envoy::Stats::MockIsolatedStatsStore stats_store_; nighthawk::request_source::FileBasedPluginRequestSourceConfig MakeFileBasedPluginConfigWithTestYaml(absl::string_view request_file) { From 3ed43fcf2ec37f46c2b25a0679a3d4eb154367d9 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 23 Sep 2020 18:22:49 +0000 Subject: [PATCH 084/114] Renames for clarity. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 42 +++++++++---------- source/common/request_source_plugin_impl.h | 22 +++++----- .../request_source_plugin_test.cc | 4 +- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 3913fc7b0..1517c66e0 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -11,29 +11,29 @@ namespace Nighthawk { -std::string DummyRequestSourceConfigFactory::name() const { +std::string DummyRequestSourcePluginConfigFactory::name() const { return "nighthawk.dummy-request-source-plugin"; } -Envoy::ProtobufTypes::MessagePtr DummyRequestSourceConfigFactory::createEmptyConfigProto() { +Envoy::ProtobufTypes::MessagePtr DummyRequestSourcePluginConfigFactory::createEmptyConfigProto() { return std::make_unique(); } -RequestSourcePtr DummyRequestSourceConfigFactory::createRequestSourcePlugin( +RequestSourcePtr DummyRequestSourcePluginConfigFactory::createRequestSourcePlugin( const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr) { const auto& any = dynamic_cast(message); nighthawk::request_source::DummyPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); - return std::make_unique(config); + return std::make_unique(config); } -REGISTER_FACTORY(DummyRequestSourceConfigFactory, RequestSourcePluginConfigFactory); +REGISTER_FACTORY(DummyRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); -DummyRequestSourcePlugin::DummyRequestSourcePlugin( +DummyRequestSource::DummyRequestSource( const nighthawk::request_source::DummyPluginRequestSourceConfig& config) : dummy_value_{config.has_dummy_value() ? config.dummy_value().value() : std::numeric_limits::infinity()} {} -RequestGenerator DummyRequestSourcePlugin::get() { +RequestGenerator DummyRequestSource::get() { RequestGenerator request_generator = []() { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); @@ -43,17 +43,17 @@ RequestGenerator DummyRequestSourcePlugin::get() { return request_generator; } -void DummyRequestSourcePlugin::initOnThread() {} +void DummyRequestSource::initOnThread() {} -std::string FileBasedRequestSourceConfigFactory::name() const { +std::string FileBasedRequestSourcePluginConfigFactory::name() const { return "nighthawk.file-based-request-source-plugin"; } -Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourceConfigFactory::createEmptyConfigProto() { +Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourcePluginConfigFactory::createEmptyConfigProto() { return std::make_unique(); } -RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( +RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourcePlugin( const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) { const auto& any = dynamic_cast(message); @@ -76,19 +76,19 @@ RequestSourcePtr FileBasedRequestSourceConfigFactory::createRequestSourcePlugin( } temp_list->CopyFrom(options_list_); } - return std::make_unique(config.num_requests().value(), + return std::make_unique(config.num_requests().value(), std::move(header), std::move(temp_list)); } -REGISTER_FACTORY(FileBasedRequestSourceConfigFactory, RequestSourcePluginConfigFactory); +REGISTER_FACTORY(FileBasedRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); -FileBasedRequestSourcePlugin::FileBasedRequestSourcePlugin( +RequestOptionsListRequestSource::RequestOptionsListRequestSource( const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list) : header_(std::move(header)), options_list_(std::move(options_list)), request_max_(request_max) {} -RequestGenerator FileBasedRequestSourcePlugin::get() { +RequestGenerator RequestOptionsListRequestSource::get() { uint32_t counter = 0; request_count_.push_back(counter); uint32_t& lambda_counter = request_count_.back(); @@ -122,28 +122,28 @@ RequestGenerator FileBasedRequestSourcePlugin::get() { return request_generator; } -void FileBasedRequestSourcePlugin::initOnThread() {} +void RequestOptionsListRequestSource::initOnThread() {} -std::string RequestOptionsListRequestSourceConfigFactory::name() const { +std::string RequestOptionsListRequestSourcePluginConfigFactory::name() const { return "nighthawk.request-options-list-request-source-plugin"; } Envoy::ProtobufTypes::MessagePtr -RequestOptionsListRequestSourceConfigFactory::createEmptyConfigProto() { +RequestOptionsListRequestSourcePluginConfigFactory::createEmptyConfigProto() { return std::make_unique(); } -RequestSourcePtr RequestOptionsListRequestSourceConfigFactory::createRequestSourcePlugin( +RequestSourcePtr RequestOptionsListRequestSourcePluginConfigFactory::createRequestSourcePlugin( const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr header) { const auto& any = dynamic_cast(message); nighthawk::request_source::RequestOptionsListPluginRequestSourceConfig config; Envoy::MessageUtil::unpackTo(any, config); auto temp_list = std::make_unique(config.options_list()); - return std::make_unique(config.num_requests().value(), + return std::make_unique(config.num_requests().value(), std::move(header), std::move(temp_list)); } -REGISTER_FACTORY(RequestOptionsListRequestSourceConfigFactory, RequestSourcePluginConfigFactory); +REGISTER_FACTORY(RequestOptionsListRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); } // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index aa2d1effd..c06aa3249 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -17,9 +17,9 @@ namespace Nighthawk { /** * Sample Request Source implementation for comparison. */ -class DummyRequestSourcePlugin : public RequestSource { +class DummyRequestSource : public RequestSource { public: - explicit DummyRequestSourcePlugin( + explicit DummyRequestSource( const nighthawk::request_source::DummyPluginRequestSourceConfig& config); RequestGenerator get() override; /** @@ -34,10 +34,10 @@ class DummyRequestSourcePlugin : public RequestSource { }; /** - * Factory that creates a DummyRequestSourcePlugin from a DummyRequestSourcePluginConfig proto. + * Factory that creates a DummyRequestSource from a DummyRequestSourcePluginConfig proto. * Registered as an Envoy plugin. */ -class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory { +class DummyRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; @@ -47,7 +47,7 @@ class DummyRequestSourceConfigFactory : public virtual RequestSourcePluginConfig }; // This factory will be activated through RequestSourceFactory in factories.h -DECLARE_FACTORY(DummyRequestSourceConfigFactory); +DECLARE_FACTORY(DummyRequestSourcePluginConfigFactory); using RequestOptionsIterator = Envoy::ProtobufWkt::internal::RepeatedPtrIterator; @@ -57,9 +57,9 @@ using RequestOptionsIterator = * from the file. Each worker will keep the file contents in memory. It will provide num_requests * number of requests, looping as required. 0 requests means infinite requests. */ -class FileBasedRequestSourcePlugin : public RequestSource { +class RequestOptionsListRequestSource : public RequestSource { public: - explicit FileBasedRequestSourcePlugin( + explicit RequestOptionsListRequestSource( const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list); RequestGenerator get() override; @@ -81,7 +81,7 @@ class FileBasedRequestSourcePlugin : public RequestSource { /** * Registered as an Envoy plugin. */ -class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginConfigFactory { +class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; @@ -95,12 +95,12 @@ class FileBasedRequestSourceConfigFactory : public virtual RequestSourcePluginCo }; // This factory will be activated through RequestSourceFactory in factories.h -DECLARE_FACTORY(FileBasedRequestSourceConfigFactory); +DECLARE_FACTORY(FileBasedRequestSourcePluginConfigFactory); /** * Registered as an Envoy plugin. */ -class RequestOptionsListRequestSourceConfigFactory +class RequestOptionsListRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; @@ -111,6 +111,6 @@ class RequestOptionsListRequestSourceConfigFactory }; // This factory will be activated through RequestSourceFactory in factories.h -DECLARE_FACTORY(RequestOptionsListRequestSourceConfigFactory); +DECLARE_FACTORY(RequestOptionsListRequestSourcePluginConfigFactory); } // namespace Nighthawk diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index ec2be4253..ffb98d404 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -69,7 +69,7 @@ TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlug auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); - EXPECT_NE(dynamic_cast(plugin.get()), nullptr); + EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } TEST_F(FileBasedRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { @@ -105,7 +105,7 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); - EXPECT_NE(dynamic_cast(plugin.get()), nullptr); + EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } TEST_F(FileBasedRequestSourcePluginTest, From 247b71bdcdeaf50f0d44424d93d915015af06acb Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 23 Sep 2020 18:32:14 +0000 Subject: [PATCH 085/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/request_source_plugin_impl.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 1517c66e0..81b3ff153 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -49,7 +49,8 @@ std::string FileBasedRequestSourcePluginConfigFactory::name() const { return "nighthawk.file-based-request-source-plugin"; } -Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourcePluginConfigFactory::createEmptyConfigProto() { +Envoy::ProtobufTypes::MessagePtr +FileBasedRequestSourcePluginConfigFactory::createEmptyConfigProto() { return std::make_unique(); } @@ -77,7 +78,7 @@ RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourceP temp_list->CopyFrom(options_list_); } return std::make_unique(config.num_requests().value(), - std::move(header), std::move(temp_list)); + std::move(header), std::move(temp_list)); } REGISTER_FACTORY(FileBasedRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); @@ -141,9 +142,10 @@ RequestSourcePtr RequestOptionsListRequestSourcePluginConfigFactory::createReque Envoy::MessageUtil::unpackTo(any, config); auto temp_list = std::make_unique(config.options_list()); return std::make_unique(config.num_requests().value(), - std::move(header), std::move(temp_list)); + std::move(header), std::move(temp_list)); } -REGISTER_FACTORY(RequestOptionsListRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); +REGISTER_FACTORY(RequestOptionsListRequestSourcePluginConfigFactory, + RequestSourcePluginConfigFactory); } // namespace Nighthawk From 171fb2e8ffb4716f801efc6b521f9b2bb86b9ac1 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 24 Sep 2020 18:12:29 +0000 Subject: [PATCH 086/114] Splitting factory off into a separate pr. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin.proto | 6 ----- source/common/request_source_plugin_impl.cc | 23 ------------------- source/common/request_source_plugin_impl.h | 16 ------------- 3 files changed, 45 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index 7e553b7f4..9d0e157c5 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -27,9 +27,3 @@ message FileBasedPluginRequestSourceConfig { google.protobuf.UInt32Value max_file_size = 3; } -// Configuration for RequestOptionsListPluginRequestSource (plugin name: -// "nighthawk.request-options-list-request-source-plugin") that uses rpc -message RequestOptionsListPluginRequestSourceConfig { - nighthawk.client.RequestOptionsList options_list = 1; - google.protobuf.UInt32Value num_requests = 2 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; -} diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 81b3ff153..595d5f4ce 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -125,27 +125,4 @@ RequestGenerator RequestOptionsListRequestSource::get() { void RequestOptionsListRequestSource::initOnThread() {} -std::string RequestOptionsListRequestSourcePluginConfigFactory::name() const { - return "nighthawk.request-options-list-request-source-plugin"; -} - -Envoy::ProtobufTypes::MessagePtr -RequestOptionsListRequestSourcePluginConfigFactory::createEmptyConfigProto() { - return std::make_unique(); -} - -RequestSourcePtr RequestOptionsListRequestSourcePluginConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, - Envoy::Http::RequestHeaderMapPtr header) { - const auto& any = dynamic_cast(message); - nighthawk::request_source::RequestOptionsListPluginRequestSourceConfig config; - Envoy::MessageUtil::unpackTo(any, config); - auto temp_list = std::make_unique(config.options_list()); - return std::make_unique(config.num_requests().value(), - std::move(header), std::move(temp_list)); -} - -REGISTER_FACTORY(RequestOptionsListRequestSourcePluginConfigFactory, - RequestSourcePluginConfigFactory); - } // namespace Nighthawk diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index c06aa3249..3b1da2a91 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -97,20 +97,4 @@ class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePl // This factory will be activated through RequestSourceFactory in factories.h DECLARE_FACTORY(FileBasedRequestSourcePluginConfigFactory); -/** - * Registered as an Envoy plugin. - */ -class RequestOptionsListRequestSourcePluginConfigFactory - : public virtual RequestSourcePluginConfigFactory { -public: - std::string name() const override; - Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::ApiPtr api, - Envoy::Http::RequestHeaderMapPtr header) override; -}; - -// This factory will be activated through RequestSourceFactory in factories.h -DECLARE_FACTORY(RequestOptionsListRequestSourcePluginConfigFactory); - } // namespace Nighthawk From 5df83edb92a399657058f10bf3b0a24b13974d33 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 24 Sep 2020 18:44:55 +0000 Subject: [PATCH 087/114] Proto cleanup/rename Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin.proto | 21 ++++++---------- source/common/request_source_plugin_impl.cc | 12 ++++------ source/common/request_source_plugin_impl.h | 5 +--- .../request_source_plugin_test.cc | 24 +++++++++---------- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index 9d0e157c5..8680703ef 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -6,24 +6,17 @@ import "google/protobuf/wrappers.proto"; import "validate/validate.proto"; import "api/client/options.proto"; -// Configuration for DummyPluginRequestSource (plugin name: "nighthawk.dummy-request-source-plugin") -// that does nothing -message DummyPluginRequestSourceConfig { - // Dummy input value. - google.protobuf.DoubleValue dummy_value = 1; -} - -// Configuration for RPCPluginRequestSource (plugin name: "nighthawk.rpc-request-source-plugin") -// that uses rpc -message RPCPluginRequestSourceConfig { - string uri = 1; -} - // Configuration for FileBasedPluginRequestSource (plugin name: // "nighthawk.file-based-request-source-plugin") that uses rpc -message FileBasedPluginRequestSourceConfig { +message FileBasedPluginConfig { string file_path = 1; google.protobuf.UInt32Value num_requests = 2 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; google.protobuf.UInt32Value max_file_size = 3; } +// Configuration for StubPluginRequestSource (plugin name: "nighthawk.stub-request-source-plugin") +// The plugin does nothing. +message StubPluginConfig { + // test input value. + google.protobuf.DoubleValue test_value = 1; +} diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 595d5f4ce..e68e56fae 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -16,13 +16,13 @@ std::string DummyRequestSourcePluginConfigFactory::name() const { } Envoy::ProtobufTypes::MessagePtr DummyRequestSourcePluginConfigFactory::createEmptyConfigProto() { - return std::make_unique(); + return std::make_unique(); } RequestSourcePtr DummyRequestSourcePluginConfigFactory::createRequestSourcePlugin( const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr) { const auto& any = dynamic_cast(message); - nighthawk::request_source::DummyPluginRequestSourceConfig config; + nighthawk::request_source::StubPluginConfig config; Envoy::MessageUtil::unpackTo(any, config); return std::make_unique(config); } @@ -30,9 +30,7 @@ RequestSourcePtr DummyRequestSourcePluginConfigFactory::createRequestSourcePlugi REGISTER_FACTORY(DummyRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); DummyRequestSource::DummyRequestSource( - const nighthawk::request_source::DummyPluginRequestSourceConfig& config) - : dummy_value_{config.has_dummy_value() ? config.dummy_value().value() - : std::numeric_limits::infinity()} {} + const nighthawk::request_source::StubPluginConfig&) {} RequestGenerator DummyRequestSource::get() { RequestGenerator request_generator = []() { @@ -51,14 +49,14 @@ std::string FileBasedRequestSourcePluginConfigFactory::name() const { Envoy::ProtobufTypes::MessagePtr FileBasedRequestSourcePluginConfigFactory::createEmptyConfigProto() { - return std::make_unique(); + return std::make_unique(); } RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourcePlugin( const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) { const auto& any = dynamic_cast(message); - nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + nighthawk::request_source::FileBasedPluginConfig config; Envoy::MessageUtil util; util.unpackTo(any, config); diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 3b1da2a91..ce14e7b4f 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -20,7 +20,7 @@ namespace Nighthawk { class DummyRequestSource : public RequestSource { public: explicit DummyRequestSource( - const nighthawk::request_source::DummyPluginRequestSourceConfig& config); + const nighthawk::request_source::StubPluginConfig& config); RequestGenerator get() override; /** * Will be called on an intialized and running worker thread, before commencing actual work. @@ -28,9 +28,6 @@ class DummyRequestSource : public RequestSource { * needed, for example). */ void initOnThread() override; - -private: - const double dummy_value_; }; /** diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index ffb98d404..08dea3a11 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -16,8 +16,8 @@ namespace Nighthawk { namespace { -using nighthawk::request_source::DummyPluginRequestSourceConfig; -using nighthawk::request_source::FileBasedPluginRequestSourceConfig; +using nighthawk::request_source::StubPluginConfig; +using nighthawk::request_source::FileBasedPluginConfig; using ::testing::NiceMock; using ::testing::Test; @@ -29,9 +29,9 @@ class DummyRequestSourcePluginTest : public Test { class FileBasedRequestSourcePluginTest : public Test { public: Envoy::Stats::MockIsolatedStatsStore stats_store_; - nighthawk::request_source::FileBasedPluginRequestSourceConfig + nighthawk::request_source::FileBasedPluginConfig MakeFileBasedPluginConfigWithTestYaml(absl::string_view request_file) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + nighthawk::request_source::FileBasedPluginConfig config; config.mutable_file_path()->assign(request_file); config.mutable_max_file_size()->set_value(4000); return config; @@ -43,13 +43,13 @@ TEST_F(DummyRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.dummy-request-source-plugin"); const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); - const nighthawk::request_source::DummyPluginRequestSourceConfig expected_config; + const nighthawk::request_source::StubPluginConfig expected_config; EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); } TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { - nighthawk::request_source::DummyPluginRequestSourceConfig config; + nighthawk::request_source::StubPluginConfig config; Envoy::ProtobufWkt::Any config_any; config_any.PackFrom(config); auto& config_factory = @@ -59,7 +59,7 @@ TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { } TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { - nighthawk::request_source::DummyPluginRequestSourceConfig config; + nighthawk::request_source::StubPluginConfig config; Envoy::ProtobufWkt::Any config_any; config_any.PackFrom(config); auto& config_factory = @@ -77,13 +77,13 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectTyp Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); - const nighthawk::request_source::FileBasedPluginRequestSourceConfig expected_config; + const nighthawk::request_source::FileBasedPluginConfig expected_config; EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); } TEST_F(FileBasedRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config; + nighthawk::request_source::FileBasedPluginConfig config; Envoy::ProtobufWkt::Any config_any; config_any.PackFrom(config); auto& config_factory = @@ -93,7 +93,7 @@ TEST_F(FileBasedRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginNam } TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config = + nighthawk::request_source::FileBasedPluginConfig config = MakeFileBasedPluginConfigWithTestYaml( TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); Envoy::ProtobufWkt::Any config_any; @@ -110,7 +110,7 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingRequestGeneratorThatEndsAtNumRequest) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config = + nighthawk::request_source::FileBasedPluginConfig config = MakeFileBasedPluginConfigWithTestYaml( TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); config.mutable_num_requests()->set_value(2); @@ -136,7 +136,7 @@ TEST_F(FileBasedRequestSourcePluginTest, TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginWithMoreNumRequestsThanInFileGetsWorkingRequestGeneratorThatLoops) { - nighthawk::request_source::FileBasedPluginRequestSourceConfig config = + nighthawk::request_source::FileBasedPluginConfig config = MakeFileBasedPluginConfigWithTestYaml( TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); config.mutable_num_requests()->set_value(4); From 0af3ffdbd92608ebba21c3ee1dfc72c5203ed516 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 24 Sep 2020 18:53:46 +0000 Subject: [PATCH 088/114] Comment cleanup. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../nighthawk/common/request_source_plugin_config_factory.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/nighthawk/common/request_source_plugin_config_factory.h b/include/nighthawk/common/request_source_plugin_config_factory.h index dee2106ba..8b6ab96a1 100644 --- a/include/nighthawk/common/request_source_plugin_config_factory.h +++ b/include/nighthawk/common/request_source_plugin_config_factory.h @@ -24,7 +24,9 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { * * @param api Api parameter that contains timesystem, filesystem, and threadfactory. * - * @return RequestSourcePtr Pointer to the new plugin instance. + * @param header RequestHeaderMapPtr parameter that acts as a template header for the requestSource to modify when generating requests. + * + * @return RequestSourcePtr Pointer to the new instance of RequestSource. * * @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the * plugin. From ff90e597defe456f87d51765545808563696a20f Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 24 Sep 2020 21:59:01 +0000 Subject: [PATCH 089/114] Proto comments and dummy -> stub clean up. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/request_source/request_source_plugin.proto | 13 +++++++++++-- source/common/request_source_plugin_impl.cc | 2 +- test/request_source/request_source_plugin_test.cc | 8 ++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index 8680703ef..81a9042ba 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -1,3 +1,4 @@ +// Config protos for the Request Source Plugin Config Factories. syntax = "proto3"; package nighthawk.request_source; @@ -7,15 +8,23 @@ import "validate/validate.proto"; import "api/client/options.proto"; // Configuration for FileBasedPluginRequestSource (plugin name: -// "nighthawk.file-based-request-source-plugin") that uses rpc +// "nighthawk.file-based-request-source-plugin") +// The factory will load the RequestOptionsList from the file, and then passes it to the requestSource it generates. +// The resulting request source will loop over the RequestOptionsList it is passed. message FileBasedPluginConfig { + // The file_path is the path to a file that contains a RequestOptionList in json or yaml format. string file_path = 1; + // The pluginfactory makes requestSources that will generate requests from the RequestOptionList up to num_requests number of times. + // If num_requests exceeds the number of RequestOptions in the RequestOptionList located in the file at file_path, it will loop. + // num_requests = 0 means no limit on the number of requests to be produced. google.protobuf.UInt32Value num_requests = 2 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; + // The pluginfactory will load the file located in file_path as long as it is below max_file_size, if it's too large it will throw an error. google.protobuf.UInt32Value max_file_size = 3; } // Configuration for StubPluginRequestSource (plugin name: "nighthawk.stub-request-source-plugin") -// The plugin does nothing. +// The plugin does nothing. This is for testing and comparison of the Request Source Plugin Factory mechanism +// using a minimal version of plugin that does not require a more complicated proto or file reading. message StubPluginConfig { // test input value. google.protobuf.DoubleValue test_value = 1; diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index e68e56fae..60f19f250 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -12,7 +12,7 @@ namespace Nighthawk { std::string DummyRequestSourcePluginConfigFactory::name() const { - return "nighthawk.dummy-request-source-plugin"; + return "nighthawk.stub-request-source-plugin"; } Envoy::ProtobufTypes::MessagePtr DummyRequestSourcePluginConfigFactory::createEmptyConfigProto() { diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 08dea3a11..a72e80ab3 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -41,7 +41,7 @@ class FileBasedRequestSourcePluginTest : public Test { TEST_F(DummyRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.dummy-request-source-plugin"); + "nighthawk.stub-request-source-plugin"); const Envoy::ProtobufTypes::MessagePtr empty_config = config_factory.createEmptyConfigProto(); const nighthawk::request_source::StubPluginConfig expected_config; EXPECT_EQ(empty_config->DebugString(), expected_config.DebugString()); @@ -54,8 +54,8 @@ TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { config_any.PackFrom(config); auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.dummy-request-source-plugin"); - EXPECT_EQ(config_factory.name(), "nighthawk.dummy-request-source-plugin"); + "nighthawk.stub-request-source-plugin"); + EXPECT_EQ(config_factory.name(), "nighthawk.stub-request-source-plugin"); } TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { @@ -64,7 +64,7 @@ TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlug config_any.PackFrom(config); auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( - "nighthawk.dummy-request-source-plugin"); + "nighthawk.stub-request-source-plugin"); auto api = Envoy::Api::createApiForTest(stats_store_); auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr plugin = From e57c05f59ba2941019c6325f5390b1c0e89f1dca Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 28 Sep 2020 03:58:45 +0000 Subject: [PATCH 090/114] Cleaning up comments Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin.proto | 2 +- .../request_source_plugin_config_factory.h | 37 +++++++++---------- source/common/request_source_plugin_impl.h | 20 ++++------ 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index 81a9042ba..9394303df 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -19,7 +19,7 @@ message FileBasedPluginConfig { // num_requests = 0 means no limit on the number of requests to be produced. google.protobuf.UInt32Value num_requests = 2 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; // The pluginfactory will load the file located in file_path as long as it is below max_file_size, if it's too large it will throw an error. - google.protobuf.UInt32Value max_file_size = 3; + google.protobuf.UInt32Value max_file_size = 3 [(validate.rules).uint32 = {lte: 1000000}]; } // Configuration for StubPluginRequestSource (plugin name: "nighthawk.stub-request-source-plugin") diff --git a/include/nighthawk/common/request_source_plugin_config_factory.h b/include/nighthawk/common/request_source_plugin_config_factory.h index 8b6ab96a1..2c328e416 100644 --- a/include/nighthawk/common/request_source_plugin_config_factory.h +++ b/include/nighthawk/common/request_source_plugin_config_factory.h @@ -8,29 +8,28 @@ namespace Nighthawk { -/** - * A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific - * RequestSourcePlugin class after unpacking the plugin-specific config proto. - */ + + // A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific + // RequestSourcePlugin class after unpacking the plugin-specific config proto. class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { public: ~RequestSourcePluginConfigFactory() override = default; + //All request source plugins will be in this category. std::string category() const override { return "nighthawk.request_source_plugin"; } - /** - * Instantiates the specific RequestSourcePlugin class. Casts |message| to Any, unpacks it to the - * plugin-specific proto, and passes the strongly typed proto to the plugin constructor. - * - * @param message Any typed_config proto taken from the TypedExtensionConfig. - * - * @param api Api parameter that contains timesystem, filesystem, and threadfactory. - * - * @param header RequestHeaderMapPtr parameter that acts as a template header for the requestSource to modify when generating requests. - * - * @return RequestSourcePtr Pointer to the new instance of RequestSource. - * - * @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the - * plugin. - */ + + // Instantiates the specific RequestSourcePlugin class. Casts |message| to Any, unpacks it to the + // plugin-specific proto, and passes the strongly typed proto to the plugin constructor. + // + // @param typed_config Any typed_config proto taken from the TypedExtensionConfig. This should be a type listed in request_source_plugin_config.proto + // + // @param api Api parameter that contains timesystem, filesystem, and threadfactory. + // + // @param header RequestHeaderMapPtr parameter that acts as a template header for the requestSource to modify when generating requests. + // + // @return RequestSourcePtr Pointer to the new instance of RequestSource. + // + // @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the + // plugin. virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& typed_config, Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) PURE; diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index ce14e7b4f..7f39df911 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -1,3 +1,4 @@ +// Implementations of RequestSourceConfigFactory and the RequestSources that those factories make. #pragma once #include "envoy/registry/registry.h" @@ -14,19 +15,14 @@ namespace Nighthawk { -/** - * Sample Request Source implementation for comparison. - */ +// Sample Request Source implementation for comparison. class DummyRequestSource : public RequestSource { public: explicit DummyRequestSource( const nighthawk::request_source::StubPluginConfig& config); RequestGenerator get() override; - /** - * Will be called on an intialized and running worker thread, before commencing actual work. - * Can be used to prepare the request source implementation (opening any connection or files - * needed, for example). - */ + + //default implementation void initOnThread() override; }; @@ -36,6 +32,7 @@ class DummyRequestSource : public RequestSource { */ class DummyRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { public: + std::string name() const override; Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, @@ -60,11 +57,8 @@ class RequestOptionsListRequestSource : public RequestSource { const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list); RequestGenerator get() override; - /** - * Will be called on an intialized and running worker thread, before commencing actual work. - * Can be used to prepare the request source implementation (opening any connection or files - * needed, for example). - */ + + //default implementation void initOnThread() override; private: From 55244b01f9f0c546b93a0f6c1066f9c502086790 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 28 Sep 2020 04:37:01 +0000 Subject: [PATCH 091/114] Updating class comments. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin.proto | 20 +++-- .../request_source_plugin_config_factory.h | 37 ++++----- source/common/request_source_plugin_impl.cc | 3 +- source/common/request_source_plugin_impl.h | 77 +++++++++++++------ .../request_source_plugin_test.cc | 17 ++-- 5 files changed, 94 insertions(+), 60 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index 9394303df..ff717ffbd 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -9,22 +9,26 @@ import "api/client/options.proto"; // Configuration for FileBasedPluginRequestSource (plugin name: // "nighthawk.file-based-request-source-plugin") -// The factory will load the RequestOptionsList from the file, and then passes it to the requestSource it generates. -// The resulting request source will loop over the RequestOptionsList it is passed. +// The factory will load the RequestOptionsList from the file, and then passes it to the +// requestSource it generates. The resulting request source will loop over the RequestOptionsList it +// is passed. message FileBasedPluginConfig { // The file_path is the path to a file that contains a RequestOptionList in json or yaml format. string file_path = 1; - // The pluginfactory makes requestSources that will generate requests from the RequestOptionList up to num_requests number of times. - // If num_requests exceeds the number of RequestOptions in the RequestOptionList located in the file at file_path, it will loop. - // num_requests = 0 means no limit on the number of requests to be produced. + // The pluginfactory makes requestSources that will generate requests from the RequestOptionList + // up to num_requests number of times. If num_requests exceeds the number of RequestOptions in the + // RequestOptionList located in the file at file_path, it will loop. num_requests = 0 means no + // limit on the number of requests to be produced. google.protobuf.UInt32Value num_requests = 2 [(validate.rules).uint32 = {gte: 0, lte: 1000000}]; - // The pluginfactory will load the file located in file_path as long as it is below max_file_size, if it's too large it will throw an error. + // The pluginfactory will load the file located in file_path as long as it is below max_file_size, + // if it's too large it will throw an error. google.protobuf.UInt32Value max_file_size = 3 [(validate.rules).uint32 = {lte: 1000000}]; } // Configuration for StubPluginRequestSource (plugin name: "nighthawk.stub-request-source-plugin") -// The plugin does nothing. This is for testing and comparison of the Request Source Plugin Factory mechanism -// using a minimal version of plugin that does not require a more complicated proto or file reading. +// The plugin does nothing. This is for testing and comparison of the Request Source Plugin Factory +// mechanism using a minimal version of plugin that does not require a more complicated proto or +// file reading. message StubPluginConfig { // test input value. google.protobuf.DoubleValue test_value = 1; diff --git a/include/nighthawk/common/request_source_plugin_config_factory.h b/include/nighthawk/common/request_source_plugin_config_factory.h index 2c328e416..17936359e 100644 --- a/include/nighthawk/common/request_source_plugin_config_factory.h +++ b/include/nighthawk/common/request_source_plugin_config_factory.h @@ -8,28 +8,29 @@ namespace Nighthawk { - - // A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific - // RequestSourcePlugin class after unpacking the plugin-specific config proto. +// A factory that must be implemented for each RequestSourcePlugin. It instantiates the specific +// RequestSourcePlugin class after unpacking the plugin-specific config proto. class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { public: ~RequestSourcePluginConfigFactory() override = default; - //All request source plugins will be in this category. + // All request source plugins will be in this category. std::string category() const override { return "nighthawk.request_source_plugin"; } - - // Instantiates the specific RequestSourcePlugin class. Casts |message| to Any, unpacks it to the - // plugin-specific proto, and passes the strongly typed proto to the plugin constructor. - // - // @param typed_config Any typed_config proto taken from the TypedExtensionConfig. This should be a type listed in request_source_plugin_config.proto - // - // @param api Api parameter that contains timesystem, filesystem, and threadfactory. - // - // @param header RequestHeaderMapPtr parameter that acts as a template header for the requestSource to modify when generating requests. - // - // @return RequestSourcePtr Pointer to the new instance of RequestSource. - // - // @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the - // plugin. + + // Instantiates the specific RequestSourcePlugin class. Casts |message| to Any, unpacks it to the + // plugin-specific proto, and passes the strongly typed proto to the plugin constructor. + // + // @param typed_config Any typed_config proto taken from the TypedExtensionConfig. This should be + // a type listed in request_source_plugin_config.proto + // + // @param api Api parameter that contains timesystem, filesystem, and threadfactory. + // + // @param header RequestHeaderMapPtr parameter that acts as a template header for the + // requestSource to modify when generating requests. + // + // @return RequestSourcePtr Pointer to the new instance of RequestSource. + // + // @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the + // plugin. virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& typed_config, Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) PURE; diff --git a/source/common/request_source_plugin_impl.cc b/source/common/request_source_plugin_impl.cc index 60f19f250..bf0094c43 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/common/request_source_plugin_impl.cc @@ -29,8 +29,7 @@ RequestSourcePtr DummyRequestSourcePluginConfigFactory::createRequestSourcePlugi REGISTER_FACTORY(DummyRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); -DummyRequestSource::DummyRequestSource( - const nighthawk::request_source::StubPluginConfig&) {} +DummyRequestSource::DummyRequestSource(const nighthawk::request_source::StubPluginConfig&) {} RequestGenerator DummyRequestSource::get() { RequestGenerator request_generator = []() { diff --git a/source/common/request_source_plugin_impl.h b/source/common/request_source_plugin_impl.h index 7f39df911..ec6b846b7 100644 --- a/source/common/request_source_plugin_impl.h +++ b/source/common/request_source_plugin_impl.h @@ -15,26 +15,39 @@ namespace Nighthawk { -// Sample Request Source implementation for comparison. +// Stub Request Source implementation for comparison. class DummyRequestSource : public RequestSource { public: - explicit DummyRequestSource( - const nighthawk::request_source::StubPluginConfig& config); + explicit DummyRequestSource(const nighthawk::request_source::StubPluginConfig& config); + // The generator function will only return empty headers. + // The function is threadsafe. RequestGenerator get() override; - //default implementation + // default implementation void initOnThread() override; }; -/** - * Factory that creates a DummyRequestSource from a DummyRequestSourcePluginConfig proto. - * Registered as an Envoy plugin. - */ +// Factory that creates a DummyRequestSource from a DummyRequestSourcePluginConfig proto. +// Registered as an Envoy plugin. +// Stub implementation of RequestSourceConfigFactory which produces a RequestSource. +// RequestSources are used to get RequestGenerators which generate requests for the benchmark +// client. All plugins configuration are specified in the request_source_plugin.proto This class is +// thread-safe, but it doesn't do anything. Usage: assume you are passed an appropriate Any type +// object called config, an Api object called api, and a default header called header. auto& +// config_factory = +// Envoy::Config::Utility::getAndCheckFactoryByName( +// "nighthawk.stub-request-source-plugin"); +// RequestSourcePtr plugin = +// config_factory.createRequestSourcePlugin(config, std::move(api), std::move(header)); + class DummyRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { public: - + // This is a hardcoded string. std::string name() const override; + // This returns an empty version of the expected StubPluginConfig from request_source_plugin.proto Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; + // This is the primary method that is used to get RequestSources. + // This implementation is thread safe, but the RequestSource it generates doesn't do much. RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) override; @@ -43,39 +56,59 @@ class DummyRequestSourcePluginConfigFactory : public virtual RequestSourcePlugin // This factory will be activated through RequestSourceFactory in factories.h DECLARE_FACTORY(DummyRequestSourcePluginConfigFactory); -using RequestOptionsIterator = - Envoy::ProtobufWkt::internal::RepeatedPtrIterator; - -/** - * Sample Request Source for small files. Loads the file in and replays the request specifications - * from the file. Each worker will keep the file contents in memory. It will provide num_requests - * number of requests, looping as required. 0 requests means infinite requests. - */ +// Sample Request Source for small RequestOptionsLists. Loads a copy of the RequestOptionsList in +// memory and replays them. +// @param request_max The number of requests the requestGenerator produced by get() will generate. 0 +// means it is unlimited. +// @param header the default header that will be overridden by values taken from the options_list, +// any values not overridden will be used. +// @param options_list A copy of the options_list will be loaded in memory. The RequestGenerator +// produced by get() will use options from the options_list to overwrite values in the header, and +// create new requests. if request_max is greater than the length of options_list, it will loop. +// This is not thread safe. class RequestOptionsListRequestSource : public RequestSource { public: explicit RequestOptionsListRequestSource( const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, std::unique_ptr options_list); + // This get function is not thread safe, because multiple threads calling get simultaneously will + // result in a collision as it attempts to update its request_count_. RequestGenerator get() override; - //default implementation + // default implementation void initOnThread() override; private: Envoy::Http::RequestHeaderMapPtr header_; const std::unique_ptr options_list_; - std::vector request_iterators_; std::vector request_count_; const uint32_t request_max_; }; -/** - * Registered as an Envoy plugin. - */ +// Factory that creates a RequestOptionsListRequestSource from a FileBasedPluginConfig proto. +// Registered as an Envoy plugin. +// Implementation of RequestSourceConfigFactory which produces a RequestSource that keeps an +// RequestOptionsList in memory RequestSources are used to get RequestGenerators which generate +// requests for the benchmark client. All plugins configuration are specified in the +// request_source_plugin.proto This class is not thread-safe, because it loads its RequestOptionlist +// in memory from a file when first called. The in memory RequestOptionsList is protected by +// file_lock_. Usage: assume you are passed an appropriate Any type object called config, an Api +// object called api, and a default header called header. auto& config_factory = +// Envoy::Config::Utility::getAndCheckFactoryByName( +// "nighthawk.file-based-request-source-plugin"); +// RequestSourcePtr plugin = +// config_factory.createRequestSourcePlugin(config, std::move(api), std::move(header)); class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; + // This returns an empty version of the expected FileBasedPluginConfig from + // request_source_plugin.proto Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; + // This is the primary method that is used to get RequestSources. + // This implementation is not thread safe. Only the first call to createRequestSourcePlugin will + // load the file from memory and subsequent calls just make a copy of the options_list that was + // already loaded. The FileBasedRequestSourcePluginConfigFactory will not work with multiple + // different files for this reason. RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr api, Envoy::Http::RequestHeaderMapPtr header) override; diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index a72e80ab3..31a6aa65e 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -16,8 +16,8 @@ namespace Nighthawk { namespace { -using nighthawk::request_source::StubPluginConfig; using nighthawk::request_source::FileBasedPluginConfig; +using nighthawk::request_source::StubPluginConfig; using ::testing::NiceMock; using ::testing::Test; @@ -93,9 +93,8 @@ TEST_F(FileBasedRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginNam } TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { - nighthawk::request_source::FileBasedPluginConfig config = - MakeFileBasedPluginConfigWithTestYaml( - TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); + nighthawk::request_source::FileBasedPluginConfig config = MakeFileBasedPluginConfigWithTestYaml( + TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); Envoy::ProtobufWkt::Any config_any; config_any.PackFrom(config); auto& config_factory = @@ -110,9 +109,8 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginGetsWorkingRequestGeneratorThatEndsAtNumRequest) { - nighthawk::request_source::FileBasedPluginConfig config = - MakeFileBasedPluginConfigWithTestYaml( - TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); + nighthawk::request_source::FileBasedPluginConfig config = MakeFileBasedPluginConfigWithTestYaml( + TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); config.mutable_num_requests()->set_value(2); Envoy::ProtobufWkt::Any config_any; config_any.PackFrom(config); @@ -136,9 +134,8 @@ TEST_F(FileBasedRequestSourcePluginTest, TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginWithMoreNumRequestsThanInFileGetsWorkingRequestGeneratorThatLoops) { - nighthawk::request_source::FileBasedPluginConfig config = - MakeFileBasedPluginConfigWithTestYaml( - TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); + nighthawk::request_source::FileBasedPluginConfig config = MakeFileBasedPluginConfigWithTestYaml( + TestEnvironment::runfilesPath("test/request_source/test_data/test-config.yaml")); config.mutable_num_requests()->set_value(4); Envoy::ProtobufWkt::Any config_any; config_any.PackFrom(config); From c710d37017d09b109fbc214b0a9abbddc39a46c4 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 28 Sep 2020 04:49:39 +0000 Subject: [PATCH 092/114] Refactor to move RequestSourcePlugins to a top level RequestSource folder. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/common/BUILD | 24 -------------- source/request_source/BUILD | 33 +++++++++++++++++++ .../request_source_plugin_impl.cc | 2 +- .../request_source_plugin_impl.h | 0 test/request_source/BUILD | 2 +- .../request_source_plugin_test.cc | 2 +- 6 files changed, 36 insertions(+), 27 deletions(-) create mode 100644 source/request_source/BUILD rename source/{common => request_source}/request_source_plugin_impl.cc (98%) rename source/{common => request_source}/request_source_plugin_impl.h (100%) diff --git a/source/common/BUILD b/source/common/BUILD index 191077805..fd8cc3701 100644 --- a/source/common/BUILD +++ b/source/common/BUILD @@ -81,30 +81,6 @@ envoy_cc_library( ], ) -envoy_cc_library( - name = "request_source_plugin_impl", - srcs = [ - "request_source_plugin_impl.cc", - ], - hdrs = [ - "request_source_plugin_impl.h", - ], - repository = "@envoy", - visibility = ["//visibility:public"], - deps = [ - ":nighthawk_common_lib", - ":request_impl_lib", - ":request_source_impl_lib", - "//include/nighthawk/common:request_source_plugin_config_factory_lib", - "@envoy//source/common/common:thread_lib_with_external_headers", - "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", - "@envoy//source/common/protobuf:protobuf_with_external_headers", - "@envoy//source/common/protobuf:utility_lib_with_external_headers", - "@envoy//source/exe:platform_header_lib_with_external_headers", - "@envoy//source/exe:platform_impl_lib", - ], -) - envoy_cc_library( name = "version_linkstamp", srcs = ["version_linkstamp.cc"], diff --git a/source/request_source/BUILD b/source/request_source/BUILD new file mode 100644 index 000000000..1e9899703 --- /dev/null +++ b/source/request_source/BUILD @@ -0,0 +1,33 @@ +load( + "@envoy//bazel:envoy_build_system.bzl", + "envoy_cc_library", + "envoy_package", +) + +licenses(["notice"]) # Apache 2 + +envoy_package() + +envoy_cc_library( + name = "request_source_plugin_impl", + srcs = [ + "request_source_plugin_impl.cc", + ], + hdrs = [ + "request_source_plugin_impl.h", + ], + repository = "@envoy", + visibility = ["//visibility:public"], + deps = [ + "//source/common:nighthawk_common_lib", + "//source/common:request_impl_lib", + "//source/common:request_source_impl_lib", + "//include/nighthawk/common:request_source_plugin_config_factory_lib", + "@envoy//source/common/common:thread_lib_with_external_headers", + "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", + "@envoy//source/common/protobuf:protobuf_with_external_headers", + "@envoy//source/common/protobuf:utility_lib_with_external_headers", + "@envoy//source/exe:platform_header_lib_with_external_headers", + "@envoy//source/exe:platform_impl_lib", + ], +) \ No newline at end of file diff --git a/source/common/request_source_plugin_impl.cc b/source/request_source/request_source_plugin_impl.cc similarity index 98% rename from source/common/request_source_plugin_impl.cc rename to source/request_source/request_source_plugin_impl.cc index bf0094c43..ed9bfff21 100644 --- a/source/common/request_source_plugin_impl.cc +++ b/source/request_source/request_source_plugin_impl.cc @@ -1,4 +1,4 @@ -#include "common/request_source_plugin_impl.h" +#include "request_source/request_source_plugin_impl.h" #include "external/envoy/source/common/protobuf/message_validator_impl.h" #include "external/envoy/source/common/protobuf/utility.h" diff --git a/source/common/request_source_plugin_impl.h b/source/request_source/request_source_plugin_impl.h similarity index 100% rename from source/common/request_source_plugin_impl.h rename to source/request_source/request_source_plugin_impl.h diff --git a/test/request_source/BUILD b/test/request_source/BUILD index 1dc858b26..3c55c2af4 100644 --- a/test/request_source/BUILD +++ b/test/request_source/BUILD @@ -16,7 +16,7 @@ envoy_cc_test( ], repository = "@envoy", deps = [ - "//source/common:request_source_plugin_impl", + "//source/request_source:request_source_plugin_impl", "//test/test_common:environment_lib", "@envoy//source/common/config:utility_lib_with_external_headers", "@envoy//test/mocks/api:api_mocks", diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 31a6aa65e..67ed534c6 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -6,7 +6,7 @@ #include "external/envoy/test/test_common/file_system_for_test.h" #include "external/envoy/test/test_common/utility.h" -#include "common/request_source_plugin_impl.h" +#include "request_source/request_source_plugin_impl.h" #include "test/test_common/environment.h" From fbb2fdc99bbaaa92f2d38c2a7776532f6f50e16d Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 28 Sep 2020 04:56:35 +0000 Subject: [PATCH 093/114] Refactor plugins into separate files. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/BUILD | 3 +- ...cc => request_options_list_plugin_impl.cc} | 35 +-------------- source/request_source/stub_plugin_impl.cc | 44 +++++++++++++++++++ 3 files changed, 47 insertions(+), 35 deletions(-) rename source/request_source/{request_source_plugin_impl.cc => request_options_list_plugin_impl.cc} (75%) create mode 100644 source/request_source/stub_plugin_impl.cc diff --git a/source/request_source/BUILD b/source/request_source/BUILD index 1e9899703..4e3ef7515 100644 --- a/source/request_source/BUILD +++ b/source/request_source/BUILD @@ -11,7 +11,8 @@ envoy_package() envoy_cc_library( name = "request_source_plugin_impl", srcs = [ - "request_source_plugin_impl.cc", + "request_options_list_plugin_impl.cc", + "stub_plugin_impl.cc" ], hdrs = [ "request_source_plugin_impl.h", diff --git a/source/request_source/request_source_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc similarity index 75% rename from source/request_source/request_source_plugin_impl.cc rename to source/request_source/request_options_list_plugin_impl.cc index ed9bfff21..e91a809ee 100644 --- a/source/request_source/request_source_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -8,40 +8,7 @@ #include "common/request_impl.h" #include "common/request_source_impl.h" - namespace Nighthawk { - -std::string DummyRequestSourcePluginConfigFactory::name() const { - return "nighthawk.stub-request-source-plugin"; -} - -Envoy::ProtobufTypes::MessagePtr DummyRequestSourcePluginConfigFactory::createEmptyConfigProto() { - return std::make_unique(); -} - -RequestSourcePtr DummyRequestSourcePluginConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr) { - const auto& any = dynamic_cast(message); - nighthawk::request_source::StubPluginConfig config; - Envoy::MessageUtil::unpackTo(any, config); - return std::make_unique(config); -} - -REGISTER_FACTORY(DummyRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); - -DummyRequestSource::DummyRequestSource(const nighthawk::request_source::StubPluginConfig&) {} -RequestGenerator DummyRequestSource::get() { - - RequestGenerator request_generator = []() { - Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); - auto returned_request_impl = std::make_unique(std::move(header)); - return returned_request_impl; - }; - return request_generator; -} - -void DummyRequestSource::initOnThread() {} - std::string FileBasedRequestSourcePluginConfigFactory::name() const { return "nighthawk.file-based-request-source-plugin"; } @@ -122,4 +89,4 @@ RequestGenerator RequestOptionsListRequestSource::get() { void RequestOptionsListRequestSource::initOnThread() {} -} // namespace Nighthawk +} // namespace Nighthawk \ No newline at end of file diff --git a/source/request_source/stub_plugin_impl.cc b/source/request_source/stub_plugin_impl.cc new file mode 100644 index 000000000..f776b48f0 --- /dev/null +++ b/source/request_source/stub_plugin_impl.cc @@ -0,0 +1,44 @@ +#include "request_source/request_source_plugin_impl.h" + +#include "external/envoy/source/common/protobuf/message_validator_impl.h" +#include "external/envoy/source/common/protobuf/utility.h" +#include "external/envoy/source/exe/platform_impl.h" + +#include "api/client/options.pb.h" + +#include "common/request_impl.h" +#include "common/request_source_impl.h" +namespace Nighthawk { + +std::string DummyRequestSourcePluginConfigFactory::name() const { + return "nighthawk.stub-request-source-plugin"; +} + +Envoy::ProtobufTypes::MessagePtr DummyRequestSourcePluginConfigFactory::createEmptyConfigProto() { + return std::make_unique(); +} + +RequestSourcePtr DummyRequestSourcePluginConfigFactory::createRequestSourcePlugin( + const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr) { + const auto& any = dynamic_cast(message); + nighthawk::request_source::StubPluginConfig config; + Envoy::MessageUtil::unpackTo(any, config); + return std::make_unique(config); +} + +REGISTER_FACTORY(DummyRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); + +DummyRequestSource::DummyRequestSource(const nighthawk::request_source::StubPluginConfig&) {} +RequestGenerator DummyRequestSource::get() { + + RequestGenerator request_generator = []() { + Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); + auto returned_request_impl = std::make_unique(std::move(header)); + return returned_request_impl; + }; + return request_generator; +} + +void DummyRequestSource::initOnThread() {} + +} // namespace Nighthawk \ No newline at end of file From ae0f4a8bfd3af0680cdffc6c8d70efb107920b3b Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 28 Sep 2020 04:59:36 +0000 Subject: [PATCH 094/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/BUILD | 6 +++--- source/request_source/request_options_list_plugin_impl.cc | 5 +++-- source/request_source/stub_plugin_impl.cc | 5 +++-- test/request_source/request_source_plugin_test.cc | 3 +-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/source/request_source/BUILD b/source/request_source/BUILD index 4e3ef7515..284304356 100644 --- a/source/request_source/BUILD +++ b/source/request_source/BUILD @@ -12,7 +12,7 @@ envoy_cc_library( name = "request_source_plugin_impl", srcs = [ "request_options_list_plugin_impl.cc", - "stub_plugin_impl.cc" + "stub_plugin_impl.cc", ], hdrs = [ "request_source_plugin_impl.h", @@ -20,10 +20,10 @@ envoy_cc_library( repository = "@envoy", visibility = ["//visibility:public"], deps = [ + "//include/nighthawk/common:request_source_plugin_config_factory_lib", "//source/common:nighthawk_common_lib", "//source/common:request_impl_lib", "//source/common:request_source_impl_lib", - "//include/nighthawk/common:request_source_plugin_config_factory_lib", "@envoy//source/common/common:thread_lib_with_external_headers", "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", @@ -31,4 +31,4 @@ envoy_cc_library( "@envoy//source/exe:platform_header_lib_with_external_headers", "@envoy//source/exe:platform_impl_lib", ], -) \ No newline at end of file +) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index e91a809ee..291a4312f 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -1,5 +1,3 @@ -#include "request_source/request_source_plugin_impl.h" - #include "external/envoy/source/common/protobuf/message_validator_impl.h" #include "external/envoy/source/common/protobuf/utility.h" #include "external/envoy/source/exe/platform_impl.h" @@ -8,6 +6,9 @@ #include "common/request_impl.h" #include "common/request_source_impl.h" + +#include "request_source/request_source_plugin_impl.h" + namespace Nighthawk { std::string FileBasedRequestSourcePluginConfigFactory::name() const { return "nighthawk.file-based-request-source-plugin"; diff --git a/source/request_source/stub_plugin_impl.cc b/source/request_source/stub_plugin_impl.cc index f776b48f0..e11d5207f 100644 --- a/source/request_source/stub_plugin_impl.cc +++ b/source/request_source/stub_plugin_impl.cc @@ -1,5 +1,3 @@ -#include "request_source/request_source_plugin_impl.h" - #include "external/envoy/source/common/protobuf/message_validator_impl.h" #include "external/envoy/source/common/protobuf/utility.h" #include "external/envoy/source/exe/platform_impl.h" @@ -8,6 +6,9 @@ #include "common/request_impl.h" #include "common/request_source_impl.h" + +#include "request_source/request_source_plugin_impl.h" + namespace Nighthawk { std::string DummyRequestSourcePluginConfigFactory::name() const { diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 67ed534c6..868420b1d 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -6,10 +6,9 @@ #include "external/envoy/test/test_common/file_system_for_test.h" #include "external/envoy/test/test_common/utility.h" -#include "request_source/request_source_plugin_impl.h" - #include "test/test_common/environment.h" +#include "request_source/request_source_plugin_impl.h" #include "gmock/gmock.h" #include "gtest/gtest.h" From 19b7aa0444e23a8c4d2aad82499f5da6c7e829cf Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Mon, 28 Sep 2020 18:04:09 +0000 Subject: [PATCH 095/114] Adding gmock and gtest to check_format so it stops complaining at me. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- test/adaptive_load/adaptive_load_controller_test.cc | 6 ++++-- .../fake_input_variable_setter_test.cc | 6 ++++-- .../fake_metrics_plugin/fake_metrics_plugin_test.cc | 6 ++++-- .../fake_step_controller/fake_step_controller_test.cc | 6 ++++-- test/adaptive_load/input_variable_setter_test.cc | 6 ++++-- test/adaptive_load/metrics_evaluator_test.cc | 6 ++++-- test/adaptive_load/metrics_plugin_test.cc | 6 ++++-- test/adaptive_load/plugin_loader_test.cc | 6 ++++-- test/adaptive_load/scoring_function_test.cc | 6 ++++-- test/adaptive_load/session_spec_proto_helper_test.cc | 6 ++++-- test/adaptive_load/step_controller_test.cc | 6 ++++-- test/client_test.cc | 4 ++-- test/client_worker_test.cc | 4 ++-- test/common/fake_time_source_test.cc | 4 ++-- test/common/nighthawk_service_client_test.cc | 3 ++- test/factories_test.cc | 4 ++-- test/mocks/client/mock_options.h | 3 ++- test/options_test.cc | 4 ++-- test/output_formatter_test.cc | 3 ++- test/process_test.cc | 4 ++-- test/python_test.cc | 4 ++-- test/rate_limiter_test.cc | 4 ++-- test/request_source/request_source_plugin_test.cc | 6 ++++-- test/sequencer_test.cc | 4 ++-- test/server/http_dynamic_delay_filter_integration_test.cc | 4 ++-- test/server/http_filter_base_test.cc | 4 ++-- test/server/http_time_tracking_filter_integration_test.cc | 4 ++-- test/statistic_test.cc | 4 ++-- test/stopwatch_test.cc | 4 ++-- test/utility_test.cc | 4 ++-- tools/check_format.sh | 4 ++-- 31 files changed, 86 insertions(+), 59 deletions(-) diff --git a/test/adaptive_load/adaptive_load_controller_test.cc b/test/adaptive_load/adaptive_load_controller_test.cc index 122a7f5e6..9178c1d8b 100644 --- a/test/adaptive_load/adaptive_load_controller_test.cc +++ b/test/adaptive_load/adaptive_load_controller_test.cc @@ -27,6 +27,10 @@ #include "api/client/service.pb.h" #include "api/client/service_mock.grpc.pb.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller.h" #include "test/common/fake_time_source.h" #include "test/mocks/adaptive_load/mock_metrics_evaluator.h" @@ -41,8 +45,6 @@ #include "adaptive_load/plugin_loader.h" #include "adaptive_load/scoring_function_impl.h" #include "adaptive_load/session_spec_proto_helper_impl.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter_test.cc b/test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter_test.cc index f0b8a6a2e..ebb94f389 100644 --- a/test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter_test.cc +++ b/test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter_test.cc @@ -5,11 +5,13 @@ #include "api/adaptive_load/benchmark_result.pb.h" #include "api/client/options.pb.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter.h" #include "adaptive_load/plugin_loader.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { namespace { diff --git a/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc b/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc index bfbc39ad8..1d97b6177 100644 --- a/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc +++ b/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc @@ -5,12 +5,14 @@ #include "api/adaptive_load/benchmark_result.pb.h" #include "api/client/options.pb.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin.h" #include "test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin.pb.h" #include "adaptive_load/plugin_loader.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { namespace { diff --git a/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc b/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc index 905c9fa02..468f1787c 100644 --- a/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc +++ b/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc @@ -5,11 +5,13 @@ #include "api/adaptive_load/benchmark_result.pb.h" #include "api/client/options.pb.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller.h" #include "adaptive_load/plugin_loader.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { namespace { diff --git a/test/adaptive_load/input_variable_setter_test.cc b/test/adaptive_load/input_variable_setter_test.cc index 7d0117ebf..565b16ecd 100644 --- a/test/adaptive_load/input_variable_setter_test.cc +++ b/test/adaptive_load/input_variable_setter_test.cc @@ -1,9 +1,11 @@ #include "external/envoy/source/common/config/utility.h" -#include "adaptive_load/input_variable_setter_impl.h" -#include "gmock/gmock.h" #include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "adaptive_load/input_variable_setter_impl.h" + namespace Nighthawk { namespace { diff --git a/test/adaptive_load/metrics_evaluator_test.cc b/test/adaptive_load/metrics_evaluator_test.cc index 1bf632400..02ba7df38 100644 --- a/test/adaptive_load/metrics_evaluator_test.cc +++ b/test/adaptive_load/metrics_evaluator_test.cc @@ -5,12 +5,14 @@ #include "api/adaptive_load/scoring_function_impl.pb.h" #include "api/client/service.pb.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin.h" #include "test/adaptive_load/minimal_output.h" #include "adaptive_load/metrics_evaluator_impl.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { namespace { diff --git a/test/adaptive_load/metrics_plugin_test.cc b/test/adaptive_load/metrics_plugin_test.cc index 415099bd2..048ed428b 100644 --- a/test/adaptive_load/metrics_plugin_test.cc +++ b/test/adaptive_load/metrics_plugin_test.cc @@ -2,11 +2,13 @@ #include "external/envoy/source/common/config/utility.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "test/adaptive_load/minimal_output.h" #include "adaptive_load/metrics_plugin_impl.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/plugin_loader_test.cc b/test/adaptive_load/plugin_loader_test.cc index 8f92e815d..3551f7e7b 100644 --- a/test/adaptive_load/plugin_loader_test.cc +++ b/test/adaptive_load/plugin_loader_test.cc @@ -12,10 +12,12 @@ #include "api/adaptive_load/scoring_function_impl.pb.h" #include "api/client/options.pb.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "absl/status/status.h" #include "adaptive_load/plugin_loader.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/scoring_function_test.cc b/test/adaptive_load/scoring_function_test.cc index 495a48291..e8f5de907 100644 --- a/test/adaptive_load/scoring_function_test.cc +++ b/test/adaptive_load/scoring_function_test.cc @@ -4,10 +4,12 @@ #include "external/envoy/source/common/config/utility.h" -#include "adaptive_load/scoring_function_impl.h" -#include "gmock/gmock.h" #include "gtest/gtest.h" +#include "gmock/gmock.h" + +#include "adaptive_load/scoring_function_impl.h" + namespace Nighthawk { namespace { diff --git a/test/adaptive_load/session_spec_proto_helper_test.cc b/test/adaptive_load/session_spec_proto_helper_test.cc index 565475994..72b6d6e43 100644 --- a/test/adaptive_load/session_spec_proto_helper_test.cc +++ b/test/adaptive_load/session_spec_proto_helper_test.cc @@ -6,12 +6,14 @@ #include "api/adaptive_load/metric_spec.pb.h" #include "api/client/options.pb.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin.h" #include "adaptive_load/plugin_loader.h" #include "adaptive_load/session_spec_proto_helper_impl.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/step_controller_test.cc b/test/adaptive_load/step_controller_test.cc index 678846b75..6c0a5ffa4 100644 --- a/test/adaptive_load/step_controller_test.cc +++ b/test/adaptive_load/step_controller_test.cc @@ -9,11 +9,13 @@ #include "api/adaptive_load/step_controller_impl.pb.h" #include "api/client/options.pb.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "adaptive_load/plugin_loader.h" #include "adaptive_load/step_controller_impl.h" #include "fake_plugins/fake_input_variable_setter/fake_input_variable_setter.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/client_test.cc b/test/client_test.cc index 549c065e7..bf3802b29 100644 --- a/test/client_test.cc +++ b/test/client_test.cc @@ -5,10 +5,10 @@ #include "client/client.h" -#include "test/client/utility.h" - #include "gtest/gtest.h" +#include "test/client/utility.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/client_worker_test.cc b/test/client_worker_test.cc index 8ffdf6680..9a56d265f 100644 --- a/test/client_worker_test.cc +++ b/test/client_worker_test.cc @@ -15,6 +15,8 @@ #include "client/client_worker_impl.h" +#include "gtest/gtest.h" + #include "test/mocks/client/mock_benchmark_client.h" #include "test/mocks/client/mock_benchmark_client_factory.h" #include "test/mocks/common/mock_request_source.h" @@ -24,8 +26,6 @@ #include "test/mocks/common/mock_termination_predicate.h" #include "test/mocks/common/mock_termination_predicate_factory.h" -#include "gtest/gtest.h" - using namespace testing; using namespace std::chrono_literals; diff --git a/test/common/fake_time_source_test.cc b/test/common/fake_time_source_test.cc index 5a8b7dad9..5ab10527b 100644 --- a/test/common/fake_time_source_test.cc +++ b/test/common/fake_time_source_test.cc @@ -1,7 +1,7 @@ -#include "test/common/fake_time_source.h" - #include "gtest/gtest.h" +#include "test/common/fake_time_source.h" + namespace Nighthawk { namespace { diff --git a/test/common/nighthawk_service_client_test.cc b/test/common/nighthawk_service_client_test.cc index b9a385857..557d3cc1e 100644 --- a/test/common/nighthawk_service_client_test.cc +++ b/test/common/nighthawk_service_client_test.cc @@ -8,9 +8,10 @@ #include "grpcpp/test/mock_stream.h" -#include "gmock/gmock.h" #include "gtest/gtest.h" +#include "gmock/gmock.h" + namespace Nighthawk { namespace { diff --git a/test/factories_test.cc b/test/factories_test.cc index fa4d6dbc7..bbc78b474 100644 --- a/test/factories_test.cc +++ b/test/factories_test.cc @@ -8,12 +8,12 @@ #include "client/factories_impl.h" +#include "gtest/gtest.h" + #include "test/mocks/client/mock_benchmark_client.h" #include "test/mocks/client/mock_options.h" #include "test/mocks/common/mock_termination_predicate.h" -#include "gtest/gtest.h" - using namespace testing; namespace Nighthawk { diff --git a/test/mocks/client/mock_options.h b/test/mocks/client/mock_options.h index 258904cd5..8092b18ef 100644 --- a/test/mocks/client/mock_options.h +++ b/test/mocks/client/mock_options.h @@ -2,9 +2,10 @@ #include "nighthawk/client/options.h" -#include "absl/types/optional.h" #include "gmock/gmock.h" +#include "absl/types/optional.h" + namespace Nighthawk { namespace Client { diff --git a/test/options_test.cc b/test/options_test.cc index ddbb80595..c20aedf02 100644 --- a/test/options_test.cc +++ b/test/options_test.cc @@ -2,10 +2,10 @@ #include "client/options_impl.h" -#include "test/client/utility.h" - #include "gtest/gtest.h" +#include "test/client/utility.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/output_formatter_test.cc b/test/output_formatter_test.cc index 8e23185b7..adc2b5ed2 100644 --- a/test/output_formatter_test.cc +++ b/test/output_formatter_test.cc @@ -16,12 +16,13 @@ #include "client/output_collector_impl.h" #include "client/output_formatter_impl.h" +#include "gtest/gtest.h" + #include "test_common/environment.h" #include "test/mocks/client/mock_options.h" #include "absl/strings/str_replace.h" -#include "gtest/gtest.h" using namespace std::chrono_literals; using namespace testing; diff --git a/test/process_test.cc b/test/process_test.cc index e0bae9a71..d8cd6f6ea 100644 --- a/test/process_test.cc +++ b/test/process_test.cc @@ -14,10 +14,10 @@ #include "client/output_collector_impl.h" #include "client/process_impl.h" -#include "test/client/utility.h" - #include "gtest/gtest.h" +#include "test/client/utility.h" + namespace Nighthawk { namespace Client { namespace { diff --git a/test/python_test.cc b/test/python_test.cc index 70749c98a..c36150862 100644 --- a/test/python_test.cc +++ b/test/python_test.cc @@ -1,7 +1,7 @@ -#include "test/test_common/environment.h" - #include "gtest/gtest.h" +#include "test/test_common/environment.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/rate_limiter_test.cc b/test/rate_limiter_test.cc index 76d9b3e5d..15b94f83c 100644 --- a/test/rate_limiter_test.cc +++ b/test/rate_limiter_test.cc @@ -7,10 +7,10 @@ #include "common/frequency.h" #include "common/rate_limiter_impl.h" -#include "test/mocks/common/mock_rate_limiter.h" - #include "gtest/gtest.h" +#include "test/mocks/common/mock_rate_limiter.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 868420b1d..9456660d1 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -6,11 +6,13 @@ #include "external/envoy/test/test_common/file_system_for_test.h" #include "external/envoy/test/test_common/utility.h" +#include "gtest/gtest.h" + +#include "gmock/gmock.h" + #include "test/test_common/environment.h" #include "request_source/request_source_plugin_impl.h" -#include "gmock/gmock.h" -#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/sequencer_test.cc b/test/sequencer_test.cc index 83d30744d..a1330602c 100644 --- a/test/sequencer_test.cc +++ b/test/sequencer_test.cc @@ -13,12 +13,12 @@ #include "common/sequencer_impl.h" #include "common/statistic_impl.h" +#include "gtest/gtest.h" + #include "test/mocks/common/mock_platform_util.h" #include "test/mocks/common/mock_rate_limiter.h" #include "test/mocks/common/mock_termination_predicate.h" -#include "gtest/gtest.h" - using namespace std::chrono_literals; using namespace nighthawk::client; using namespace testing; diff --git a/test/server/http_dynamic_delay_filter_integration_test.cc b/test/server/http_dynamic_delay_filter_integration_test.cc index 3840a11ec..74440d319 100644 --- a/test/server/http_dynamic_delay_filter_integration_test.cc +++ b/test/server/http_dynamic_delay_filter_integration_test.cc @@ -5,10 +5,10 @@ #include "server/configuration.h" #include "server/http_dynamic_delay_filter.h" -#include "test/server/http_filter_integration_test_base.h" - #include "gtest/gtest.h" +#include "test/server/http_filter_integration_test_base.h" + namespace Nighthawk { const Envoy::Http::LowerCaseString kDelayHeaderString("x-envoy-fault-delay-request"); diff --git a/test/server/http_filter_base_test.cc b/test/server/http_filter_base_test.cc index 212bd59b5..a3aa0581f 100644 --- a/test/server/http_filter_base_test.cc +++ b/test/server/http_filter_base_test.cc @@ -2,10 +2,10 @@ #include "server/http_test_server_filter.h" #include "server/http_time_tracking_filter.h" -#include "test/server/http_filter_integration_test_base.h" - #include "gtest/gtest.h" +#include "test/server/http_filter_integration_test_base.h" + namespace Nighthawk { namespace { diff --git a/test/server/http_time_tracking_filter_integration_test.cc b/test/server/http_time_tracking_filter_integration_test.cc index 5f1348c56..42fdbfc8f 100644 --- a/test/server/http_time_tracking_filter_integration_test.cc +++ b/test/server/http_time_tracking_filter_integration_test.cc @@ -8,10 +8,10 @@ #include "server/configuration.h" #include "server/http_time_tracking_filter.h" -#include "test/server/http_filter_integration_test_base.h" - #include "gtest/gtest.h" +#include "test/server/http_filter_integration_test_base.h" + namespace Nighthawk { namespace { diff --git a/test/statistic_test.cc b/test/statistic_test.cc index 596f04983..0db64c962 100644 --- a/test/statistic_test.cc +++ b/test/statistic_test.cc @@ -13,10 +13,10 @@ #include "common/statistic_impl.h" -#include "test/test_common/environment.h" - #include "gtest/gtest.h" +#include "test/test_common/environment.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/stopwatch_test.cc b/test/stopwatch_test.cc index 31883e1be..1be15d98a 100644 --- a/test/stopwatch_test.cc +++ b/test/stopwatch_test.cc @@ -8,10 +8,10 @@ #include "common/thread_safe_monotonic_time_stopwatch.h" -#include "test/common/fake_time_source.h" - #include "gtest/gtest.h" +#include "test/common/fake_time_source.h" + namespace Nighthawk { namespace { diff --git a/test/utility_test.cc b/test/utility_test.cc index 82c5d3324..b4fa9d476 100644 --- a/test/utility_test.cc +++ b/test/utility_test.cc @@ -7,10 +7,10 @@ #include "common/uri_impl.h" #include "common/utility.h" -#include "test/test_common/environment.h" - #include "gtest/gtest.h" +#include "test/test_common/environment.h" + using namespace testing; namespace Nighthawk { diff --git a/tools/check_format.sh b/tools/check_format.sh index 1389fd4d5..ca74ec874 100755 --- a/tools/check_format.sh +++ b/tools/check_format.sh @@ -8,11 +8,11 @@ TO_CHECK="${2:-$PWD}" bazel run @envoy//tools:code_format/check_format.py -- \ --skip_envoy_build_rule_check --namespace_check Nighthawk \ --build_fixer_check_excluded_paths=$(realpath ".") \ - --include_dir_order envoy,nighthawk,external/source/envoy,external,api,common,source,exe,server,client,grpcpp,test_common,test \ + --include_dir_order envoy,nighthawk,external/source/envoy,external,api,common,source,exe,server,client,grpcpp,gtest,gmock,test_common,test \ $1 $TO_CHECK # The include checker doesn't support per-file checking, so we only # run it when a full check is requested. if [ $PWD == $TO_CHECK ]; then bazel run //tools:check_envoy_includes.py -fi +fi \ No newline at end of file From dae30983b6ef0d0c1234a4f774e4de00c8d7a374 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 29 Sep 2020 16:14:15 +0000 Subject: [PATCH 096/114] Updating to prefix increment, and removing auto. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/request_options_list_plugin_impl.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index 291a4312f..f0732d50f 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -65,9 +65,9 @@ RequestGenerator RequestOptionsListRequestSource::get() { } // Increment the counter and get the request_option from the list for the current iteration. - auto index = lambda_counter % options_list_->options_size(); + unsigned int index = lambda_counter % options_list_->options_size(); nighthawk::client::RequestOptions request_option = options_list_->options().at(index); - lambda_counter++; + ++lambda_counter; // Initialize the header with the values from the default header. Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); @@ -79,7 +79,7 @@ RequestGenerator RequestOptionsListRequestSource::get() { if (content_length > 0) { header->setContentLength(content_length); } - for (const auto& option_header : request_option.request_headers()) { + for (const envoy::config::core::v3::HeaderValueOption& option_header : request_option.request_headers()) { auto lower_case_key = Envoy::Http::LowerCaseString(std::string(option_header.header().key())); header->setCopy(lower_case_key, std::string(option_header.header().value())); } From a4b6fb11b16f4be54c2cb8872d7e4bd89cc8392a Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Tue, 29 Sep 2020 16:30:10 +0000 Subject: [PATCH 097/114] Removing gmock and gtest from script to avoid conflict. Add Request_source instead. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/request_options_list_plugin_impl.cc | 3 ++- test/adaptive_load/adaptive_load_controller_test.cc | 6 ++---- .../fake_input_variable_setter_test.cc | 6 ++---- .../fake_metrics_plugin/fake_metrics_plugin_test.cc | 6 ++---- .../fake_step_controller/fake_step_controller_test.cc | 6 ++---- test/adaptive_load/input_variable_setter_test.cc | 6 ++---- test/adaptive_load/metrics_evaluator_test.cc | 6 ++---- test/adaptive_load/metrics_plugin_test.cc | 6 ++---- test/adaptive_load/plugin_loader_test.cc | 6 ++---- test/adaptive_load/scoring_function_test.cc | 6 ++---- test/adaptive_load/session_spec_proto_helper_test.cc | 6 ++---- test/adaptive_load/step_controller_test.cc | 6 ++---- test/client_test.cc | 4 ++-- test/client_worker_test.cc | 4 ++-- test/common/fake_time_source_test.cc | 4 ++-- test/common/nighthawk_service_client_test.cc | 3 +-- test/factories_test.cc | 4 ++-- test/mocks/client/mock_options.h | 3 +-- test/options_test.cc | 4 ++-- test/output_formatter_test.cc | 3 +-- test/process_test.cc | 4 ++-- test/python_test.cc | 4 ++-- test/rate_limiter_test.cc | 4 ++-- test/request_source/request_source_plugin_test.cc | 7 +++---- test/sequencer_test.cc | 4 ++-- test/server/http_dynamic_delay_filter_integration_test.cc | 4 ++-- test/server/http_filter_base_test.cc | 4 ++-- test/server/http_time_tracking_filter_integration_test.cc | 4 ++-- test/statistic_test.cc | 4 ++-- test/stopwatch_test.cc | 4 ++-- test/utility_test.cc | 4 ++-- tools/check_format.sh | 2 +- 32 files changed, 61 insertions(+), 86 deletions(-) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index f0732d50f..1cec7ec96 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -79,7 +79,8 @@ RequestGenerator RequestOptionsListRequestSource::get() { if (content_length > 0) { header->setContentLength(content_length); } - for (const envoy::config::core::v3::HeaderValueOption& option_header : request_option.request_headers()) { + for (const envoy::config::core::v3::HeaderValueOption& option_header : + request_option.request_headers()) { auto lower_case_key = Envoy::Http::LowerCaseString(std::string(option_header.header().key())); header->setCopy(lower_case_key, std::string(option_header.header().value())); } diff --git a/test/adaptive_load/adaptive_load_controller_test.cc b/test/adaptive_load/adaptive_load_controller_test.cc index 9178c1d8b..122a7f5e6 100644 --- a/test/adaptive_load/adaptive_load_controller_test.cc +++ b/test/adaptive_load/adaptive_load_controller_test.cc @@ -27,10 +27,6 @@ #include "api/client/service.pb.h" #include "api/client/service_mock.grpc.pb.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller.h" #include "test/common/fake_time_source.h" #include "test/mocks/adaptive_load/mock_metrics_evaluator.h" @@ -45,6 +41,8 @@ #include "adaptive_load/plugin_loader.h" #include "adaptive_load/scoring_function_impl.h" #include "adaptive_load/session_spec_proto_helper_impl.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter_test.cc b/test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter_test.cc index ebb94f389..f0b8a6a2e 100644 --- a/test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter_test.cc +++ b/test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter_test.cc @@ -5,13 +5,11 @@ #include "api/adaptive_load/benchmark_result.pb.h" #include "api/client/options.pb.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "test/adaptive_load/fake_plugins/fake_input_variable_setter/fake_input_variable_setter.h" #include "adaptive_load/plugin_loader.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { namespace { diff --git a/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc b/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc index 1d97b6177..bfbc39ad8 100644 --- a/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc +++ b/test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin_test.cc @@ -5,14 +5,12 @@ #include "api/adaptive_load/benchmark_result.pb.h" #include "api/client/options.pb.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin.h" #include "test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin.pb.h" #include "adaptive_load/plugin_loader.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { namespace { diff --git a/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc b/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc index 468f1787c..905c9fa02 100644 --- a/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc +++ b/test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller_test.cc @@ -5,13 +5,11 @@ #include "api/adaptive_load/benchmark_result.pb.h" #include "api/client/options.pb.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "test/adaptive_load/fake_plugins/fake_step_controller/fake_step_controller.h" #include "adaptive_load/plugin_loader.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { namespace { diff --git a/test/adaptive_load/input_variable_setter_test.cc b/test/adaptive_load/input_variable_setter_test.cc index 565b16ecd..7d0117ebf 100644 --- a/test/adaptive_load/input_variable_setter_test.cc +++ b/test/adaptive_load/input_variable_setter_test.cc @@ -1,10 +1,8 @@ #include "external/envoy/source/common/config/utility.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "adaptive_load/input_variable_setter_impl.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/metrics_evaluator_test.cc b/test/adaptive_load/metrics_evaluator_test.cc index 02ba7df38..1bf632400 100644 --- a/test/adaptive_load/metrics_evaluator_test.cc +++ b/test/adaptive_load/metrics_evaluator_test.cc @@ -5,14 +5,12 @@ #include "api/adaptive_load/scoring_function_impl.pb.h" #include "api/client/service.pb.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin.h" #include "test/adaptive_load/minimal_output.h" #include "adaptive_load/metrics_evaluator_impl.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { namespace { diff --git a/test/adaptive_load/metrics_plugin_test.cc b/test/adaptive_load/metrics_plugin_test.cc index 048ed428b..415099bd2 100644 --- a/test/adaptive_load/metrics_plugin_test.cc +++ b/test/adaptive_load/metrics_plugin_test.cc @@ -2,13 +2,11 @@ #include "external/envoy/source/common/config/utility.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "test/adaptive_load/minimal_output.h" #include "adaptive_load/metrics_plugin_impl.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/plugin_loader_test.cc b/test/adaptive_load/plugin_loader_test.cc index 3551f7e7b..8f92e815d 100644 --- a/test/adaptive_load/plugin_loader_test.cc +++ b/test/adaptive_load/plugin_loader_test.cc @@ -12,12 +12,10 @@ #include "api/adaptive_load/scoring_function_impl.pb.h" #include "api/client/options.pb.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "absl/status/status.h" #include "adaptive_load/plugin_loader.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/scoring_function_test.cc b/test/adaptive_load/scoring_function_test.cc index e8f5de907..495a48291 100644 --- a/test/adaptive_load/scoring_function_test.cc +++ b/test/adaptive_load/scoring_function_test.cc @@ -4,11 +4,9 @@ #include "external/envoy/source/common/config/utility.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "adaptive_load/scoring_function_impl.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/session_spec_proto_helper_test.cc b/test/adaptive_load/session_spec_proto_helper_test.cc index 72b6d6e43..565475994 100644 --- a/test/adaptive_load/session_spec_proto_helper_test.cc +++ b/test/adaptive_load/session_spec_proto_helper_test.cc @@ -6,14 +6,12 @@ #include "api/adaptive_load/metric_spec.pb.h" #include "api/client/options.pb.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "test/adaptive_load/fake_plugins/fake_metrics_plugin/fake_metrics_plugin.h" #include "adaptive_load/plugin_loader.h" #include "adaptive_load/session_spec_proto_helper_impl.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/adaptive_load/step_controller_test.cc b/test/adaptive_load/step_controller_test.cc index 6c0a5ffa4..678846b75 100644 --- a/test/adaptive_load/step_controller_test.cc +++ b/test/adaptive_load/step_controller_test.cc @@ -9,13 +9,11 @@ #include "api/adaptive_load/step_controller_impl.pb.h" #include "api/client/options.pb.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" - #include "adaptive_load/plugin_loader.h" #include "adaptive_load/step_controller_impl.h" #include "fake_plugins/fake_input_variable_setter/fake_input_variable_setter.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/client_test.cc b/test/client_test.cc index bf3802b29..549c065e7 100644 --- a/test/client_test.cc +++ b/test/client_test.cc @@ -5,10 +5,10 @@ #include "client/client.h" -#include "gtest/gtest.h" - #include "test/client/utility.h" +#include "gtest/gtest.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/client_worker_test.cc b/test/client_worker_test.cc index 9a56d265f..8ffdf6680 100644 --- a/test/client_worker_test.cc +++ b/test/client_worker_test.cc @@ -15,8 +15,6 @@ #include "client/client_worker_impl.h" -#include "gtest/gtest.h" - #include "test/mocks/client/mock_benchmark_client.h" #include "test/mocks/client/mock_benchmark_client_factory.h" #include "test/mocks/common/mock_request_source.h" @@ -26,6 +24,8 @@ #include "test/mocks/common/mock_termination_predicate.h" #include "test/mocks/common/mock_termination_predicate_factory.h" +#include "gtest/gtest.h" + using namespace testing; using namespace std::chrono_literals; diff --git a/test/common/fake_time_source_test.cc b/test/common/fake_time_source_test.cc index 5ab10527b..5a8b7dad9 100644 --- a/test/common/fake_time_source_test.cc +++ b/test/common/fake_time_source_test.cc @@ -1,7 +1,7 @@ -#include "gtest/gtest.h" - #include "test/common/fake_time_source.h" +#include "gtest/gtest.h" + namespace Nighthawk { namespace { diff --git a/test/common/nighthawk_service_client_test.cc b/test/common/nighthawk_service_client_test.cc index 557d3cc1e..b9a385857 100644 --- a/test/common/nighthawk_service_client_test.cc +++ b/test/common/nighthawk_service_client_test.cc @@ -8,9 +8,8 @@ #include "grpcpp/test/mock_stream.h" -#include "gtest/gtest.h" - #include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/factories_test.cc b/test/factories_test.cc index bbc78b474..fa4d6dbc7 100644 --- a/test/factories_test.cc +++ b/test/factories_test.cc @@ -8,12 +8,12 @@ #include "client/factories_impl.h" -#include "gtest/gtest.h" - #include "test/mocks/client/mock_benchmark_client.h" #include "test/mocks/client/mock_options.h" #include "test/mocks/common/mock_termination_predicate.h" +#include "gtest/gtest.h" + using namespace testing; namespace Nighthawk { diff --git a/test/mocks/client/mock_options.h b/test/mocks/client/mock_options.h index 8092b18ef..258904cd5 100644 --- a/test/mocks/client/mock_options.h +++ b/test/mocks/client/mock_options.h @@ -2,9 +2,8 @@ #include "nighthawk/client/options.h" -#include "gmock/gmock.h" - #include "absl/types/optional.h" +#include "gmock/gmock.h" namespace Nighthawk { namespace Client { diff --git a/test/options_test.cc b/test/options_test.cc index c20aedf02..ddbb80595 100644 --- a/test/options_test.cc +++ b/test/options_test.cc @@ -2,10 +2,10 @@ #include "client/options_impl.h" -#include "gtest/gtest.h" - #include "test/client/utility.h" +#include "gtest/gtest.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/output_formatter_test.cc b/test/output_formatter_test.cc index adc2b5ed2..8e23185b7 100644 --- a/test/output_formatter_test.cc +++ b/test/output_formatter_test.cc @@ -16,13 +16,12 @@ #include "client/output_collector_impl.h" #include "client/output_formatter_impl.h" -#include "gtest/gtest.h" - #include "test_common/environment.h" #include "test/mocks/client/mock_options.h" #include "absl/strings/str_replace.h" +#include "gtest/gtest.h" using namespace std::chrono_literals; using namespace testing; diff --git a/test/process_test.cc b/test/process_test.cc index d8cd6f6ea..e0bae9a71 100644 --- a/test/process_test.cc +++ b/test/process_test.cc @@ -14,10 +14,10 @@ #include "client/output_collector_impl.h" #include "client/process_impl.h" -#include "gtest/gtest.h" - #include "test/client/utility.h" +#include "gtest/gtest.h" + namespace Nighthawk { namespace Client { namespace { diff --git a/test/python_test.cc b/test/python_test.cc index c36150862..70749c98a 100644 --- a/test/python_test.cc +++ b/test/python_test.cc @@ -1,7 +1,7 @@ -#include "gtest/gtest.h" - #include "test/test_common/environment.h" +#include "gtest/gtest.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/rate_limiter_test.cc b/test/rate_limiter_test.cc index 15b94f83c..76d9b3e5d 100644 --- a/test/rate_limiter_test.cc +++ b/test/rate_limiter_test.cc @@ -7,10 +7,10 @@ #include "common/frequency.h" #include "common/rate_limiter_impl.h" -#include "gtest/gtest.h" - #include "test/mocks/common/mock_rate_limiter.h" +#include "gtest/gtest.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 9456660d1..67ed534c6 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -6,13 +6,12 @@ #include "external/envoy/test/test_common/file_system_for_test.h" #include "external/envoy/test/test_common/utility.h" -#include "gtest/gtest.h" - -#include "gmock/gmock.h" +#include "request_source/request_source_plugin_impl.h" #include "test/test_common/environment.h" -#include "request_source/request_source_plugin_impl.h" +#include "gmock/gmock.h" +#include "gtest/gtest.h" namespace Nighthawk { diff --git a/test/sequencer_test.cc b/test/sequencer_test.cc index a1330602c..83d30744d 100644 --- a/test/sequencer_test.cc +++ b/test/sequencer_test.cc @@ -13,12 +13,12 @@ #include "common/sequencer_impl.h" #include "common/statistic_impl.h" -#include "gtest/gtest.h" - #include "test/mocks/common/mock_platform_util.h" #include "test/mocks/common/mock_rate_limiter.h" #include "test/mocks/common/mock_termination_predicate.h" +#include "gtest/gtest.h" + using namespace std::chrono_literals; using namespace nighthawk::client; using namespace testing; diff --git a/test/server/http_dynamic_delay_filter_integration_test.cc b/test/server/http_dynamic_delay_filter_integration_test.cc index 74440d319..3840a11ec 100644 --- a/test/server/http_dynamic_delay_filter_integration_test.cc +++ b/test/server/http_dynamic_delay_filter_integration_test.cc @@ -5,10 +5,10 @@ #include "server/configuration.h" #include "server/http_dynamic_delay_filter.h" -#include "gtest/gtest.h" - #include "test/server/http_filter_integration_test_base.h" +#include "gtest/gtest.h" + namespace Nighthawk { const Envoy::Http::LowerCaseString kDelayHeaderString("x-envoy-fault-delay-request"); diff --git a/test/server/http_filter_base_test.cc b/test/server/http_filter_base_test.cc index a3aa0581f..212bd59b5 100644 --- a/test/server/http_filter_base_test.cc +++ b/test/server/http_filter_base_test.cc @@ -2,10 +2,10 @@ #include "server/http_test_server_filter.h" #include "server/http_time_tracking_filter.h" -#include "gtest/gtest.h" - #include "test/server/http_filter_integration_test_base.h" +#include "gtest/gtest.h" + namespace Nighthawk { namespace { diff --git a/test/server/http_time_tracking_filter_integration_test.cc b/test/server/http_time_tracking_filter_integration_test.cc index 42fdbfc8f..5f1348c56 100644 --- a/test/server/http_time_tracking_filter_integration_test.cc +++ b/test/server/http_time_tracking_filter_integration_test.cc @@ -8,10 +8,10 @@ #include "server/configuration.h" #include "server/http_time_tracking_filter.h" -#include "gtest/gtest.h" - #include "test/server/http_filter_integration_test_base.h" +#include "gtest/gtest.h" + namespace Nighthawk { namespace { diff --git a/test/statistic_test.cc b/test/statistic_test.cc index 0db64c962..596f04983 100644 --- a/test/statistic_test.cc +++ b/test/statistic_test.cc @@ -13,10 +13,10 @@ #include "common/statistic_impl.h" -#include "gtest/gtest.h" - #include "test/test_common/environment.h" +#include "gtest/gtest.h" + using namespace std::chrono_literals; using namespace testing; diff --git a/test/stopwatch_test.cc b/test/stopwatch_test.cc index 1be15d98a..31883e1be 100644 --- a/test/stopwatch_test.cc +++ b/test/stopwatch_test.cc @@ -8,10 +8,10 @@ #include "common/thread_safe_monotonic_time_stopwatch.h" -#include "gtest/gtest.h" - #include "test/common/fake_time_source.h" +#include "gtest/gtest.h" + namespace Nighthawk { namespace { diff --git a/test/utility_test.cc b/test/utility_test.cc index b4fa9d476..82c5d3324 100644 --- a/test/utility_test.cc +++ b/test/utility_test.cc @@ -7,10 +7,10 @@ #include "common/uri_impl.h" #include "common/utility.h" -#include "gtest/gtest.h" - #include "test/test_common/environment.h" +#include "gtest/gtest.h" + using namespace testing; namespace Nighthawk { diff --git a/tools/check_format.sh b/tools/check_format.sh index ca74ec874..847b28ddd 100755 --- a/tools/check_format.sh +++ b/tools/check_format.sh @@ -8,7 +8,7 @@ TO_CHECK="${2:-$PWD}" bazel run @envoy//tools:code_format/check_format.py -- \ --skip_envoy_build_rule_check --namespace_check Nighthawk \ --build_fixer_check_excluded_paths=$(realpath ".") \ - --include_dir_order envoy,nighthawk,external/source/envoy,external,api,common,source,exe,server,client,grpcpp,gtest,gmock,test_common,test \ + --include_dir_order envoy,nighthawk,external/source/envoy,external,api,common,source,exe,server,client,grpcpp,request_source,test_common,test \ $1 $TO_CHECK # The include checker doesn't support per-file checking, so we only From 55f685ecc5ff740017c67d1d1da9e0d75b610318 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 30 Sep 2020 06:18:12 +0000 Subject: [PATCH 098/114] Fixing clang-tidy Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/request_options_list_plugin_impl.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index 1cec7ec96..5a9a56587 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -65,7 +65,7 @@ RequestGenerator RequestOptionsListRequestSource::get() { } // Increment the counter and get the request_option from the list for the current iteration. - unsigned int index = lambda_counter % options_list_->options_size(); + int index = lambda_counter % options_list_->options_size(); nighthawk::client::RequestOptions request_option = options_list_->options().at(index); ++lambda_counter; From 59c5b94de43c2102833041cbac42d215b1e02ae7 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 30 Sep 2020 06:44:29 +0000 Subject: [PATCH 099/114] Using the test value in the stub for better testing. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/request_options_list_plugin_impl.cc | 3 +-- source/request_source/request_source_plugin_impl.h | 5 ++++- source/request_source/stub_plugin_impl.cc | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index 5a9a56587..e3a9cfecb 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -55,8 +55,7 @@ RequestOptionsListRequestSource::RequestOptionsListRequestSource( request_max_(request_max) {} RequestGenerator RequestOptionsListRequestSource::get() { - uint32_t counter = 0; - request_count_.push_back(counter); + request_count_.push_back(0); uint32_t& lambda_counter = request_count_.back(); RequestGenerator request_generator = [this, lambda_counter]() mutable -> RequestPtr { // if request_max is 0, then we never stop generating requests. diff --git a/source/request_source/request_source_plugin_impl.h b/source/request_source/request_source_plugin_impl.h index ec6b846b7..0b7f756dc 100644 --- a/source/request_source/request_source_plugin_impl.h +++ b/source/request_source/request_source_plugin_impl.h @@ -19,12 +19,15 @@ namespace Nighthawk { class DummyRequestSource : public RequestSource { public: explicit DummyRequestSource(const nighthawk::request_source::StubPluginConfig& config); - // The generator function will only return empty headers. + // The generator function will return a header whose only value is the test_value taken from the config. // The function is threadsafe. RequestGenerator get() override; // default implementation void initOnThread() override; +private: + const double test_value_; + }; // Factory that creates a DummyRequestSource from a DummyRequestSourcePluginConfig proto. diff --git a/source/request_source/stub_plugin_impl.cc b/source/request_source/stub_plugin_impl.cc index e11d5207f..767a8b0c3 100644 --- a/source/request_source/stub_plugin_impl.cc +++ b/source/request_source/stub_plugin_impl.cc @@ -29,11 +29,12 @@ RequestSourcePtr DummyRequestSourcePluginConfigFactory::createRequestSourcePlugi REGISTER_FACTORY(DummyRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); -DummyRequestSource::DummyRequestSource(const nighthawk::request_source::StubPluginConfig&) {} +DummyRequestSource::DummyRequestSource(const nighthawk::request_source::StubPluginConfig& config) : test_value_{config.test_value().value()} {} RequestGenerator DummyRequestSource::get() { - RequestGenerator request_generator = []() { + RequestGenerator request_generator = [this] () { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); + header->setCopy(Envoy::Http::LowerCaseString("test_value_"), std::to_string(test_value_)); auto returned_request_impl = std::make_unique(std::move(header)); return returned_request_impl; }; From 2ea0c5e4cfc49d65957673f8fa5ca7295330bf75 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 30 Sep 2020 15:20:24 +0000 Subject: [PATCH 100/114] Getting rid of auto. And updating stubplugintest. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/stub_plugin_impl.cc | 4 +- .../request_source_plugin_test.cc | 45 +++++++++++++------ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/source/request_source/stub_plugin_impl.cc b/source/request_source/stub_plugin_impl.cc index 767a8b0c3..8512bf6eb 100644 --- a/source/request_source/stub_plugin_impl.cc +++ b/source/request_source/stub_plugin_impl.cc @@ -29,12 +29,12 @@ RequestSourcePtr DummyRequestSourcePluginConfigFactory::createRequestSourcePlugi REGISTER_FACTORY(DummyRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); -DummyRequestSource::DummyRequestSource(const nighthawk::request_source::StubPluginConfig& config) : test_value_{config.test_value().value()} {} +DummyRequestSource::DummyRequestSource(const nighthawk::request_source::StubPluginConfig& config) : test_value_{ config.has_test_value() ? config.test_value().value() : 0} {} RequestGenerator DummyRequestSource::get() { RequestGenerator request_generator = [this] () { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); - header->setCopy(Envoy::Http::LowerCaseString("test_value_"), std::to_string(test_value_)); + header->setCopy(Envoy::Http::LowerCaseString("test_value"), std::to_string(test_value_)); auto returned_request_impl = std::make_unique(std::move(header)); return returned_request_impl; }; diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 67ed534c6..949aacef3 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -71,7 +71,24 @@ TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlug config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } - +TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesWorkingPlugin) { + nighthawk::request_source::StubPluginConfig config; + double test_value = 2; + config.mutable_test_value()->set_value(test_value); + Envoy::ProtobufWkt::Any config_any; + config_any.PackFrom(config); + auto& config_factory = + Envoy::Config::Utility::getAndCheckFactoryByName( + "nighthawk.stub-request-source-plugin"); + auto api = Envoy::Api::createApiForTest(stats_store_); + auto template_header = Envoy::Http::RequestHeaderMapImpl::create(); + RequestSourcePtr plugin = + config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(template_header)); + Nighthawk::RequestGenerator generator = plugin->get(); + Nighthawk::RequestPtr request = generator(); + Nighthawk::HeaderMapPtr header = request->header(); + EXPECT_EQ(header->get(Envoy::Http::LowerCaseString("test_value"))->value().getStringView(), absl::string_view(std::to_string(test_value))); +} TEST_F(FileBasedRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( @@ -121,12 +138,12 @@ TEST_F(FileBasedRequestSourcePluginTest, auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); - auto generator = file_based_request_source->get(); - auto request = generator(); - auto request2 = generator(); - auto request3 = generator(); - auto header1 = request->header(); - auto header2 = request2->header(); + Nighthawk::RequestGenerator generator = file_based_request_source->get(); + Nighthawk::RequestPtr request = generator(); + Nighthawk::RequestPtr request2 = generator(); + Nighthawk::RequestPtr request3 = generator(); + Nighthawk::HeaderMapPtr header1 = request->header(); + Nighthawk::HeaderMapPtr header2 = request2->header(); EXPECT_EQ(header1->getPathValue(), "/a"); EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(request3, nullptr); @@ -146,13 +163,13 @@ TEST_F(FileBasedRequestSourcePluginTest, auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr file_based_request_source = config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); - auto generator = file_based_request_source->get(); - auto request = generator(); - auto request2 = generator(); - auto request3 = generator(); - auto header1 = request->header(); - auto header2 = request2->header(); - auto header3 = request3->header(); + Nighthawk::RequestGenerator generator = file_based_request_source->get(); + Nighthawk::RequestPtr request = generator(); + Nighthawk::RequestPtr request2 = generator(); + Nighthawk::RequestPtr request3 = generator(); + Nighthawk::HeaderMapPtr header1 = request->header(); + Nighthawk::HeaderMapPtr header2 = request2->header(); + Nighthawk::HeaderMapPtr header3 = request3->header(); EXPECT_EQ(header1->getPathValue(), "/a"); EXPECT_EQ(header2->getPathValue(), "/b"); EXPECT_EQ(header3->getPathValue(), "/a"); From d40a073f55c032dea9f3b3913cee2b89d1cd4480 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 30 Sep 2020 18:17:06 +0000 Subject: [PATCH 101/114] Further renaming. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source/request_source_plugin_impl.h | 8 ++++---- source/request_source/stub_plugin_impl.cc | 16 ++++++++-------- .../request_source/request_source_plugin_test.cc | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/source/request_source/request_source_plugin_impl.h b/source/request_source/request_source_plugin_impl.h index 0b7f756dc..edfd80a8d 100644 --- a/source/request_source/request_source_plugin_impl.h +++ b/source/request_source/request_source_plugin_impl.h @@ -16,9 +16,9 @@ namespace Nighthawk { // Stub Request Source implementation for comparison. -class DummyRequestSource : public RequestSource { +class StubRequestSource : public RequestSource { public: - explicit DummyRequestSource(const nighthawk::request_source::StubPluginConfig& config); + explicit StubRequestSource(const nighthawk::request_source::StubPluginConfig& config); // The generator function will return a header whose only value is the test_value taken from the config. // The function is threadsafe. RequestGenerator get() override; @@ -43,7 +43,7 @@ class DummyRequestSource : public RequestSource { // RequestSourcePtr plugin = // config_factory.createRequestSourcePlugin(config, std::move(api), std::move(header)); -class DummyRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { +class StubRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { public: // This is a hardcoded string. std::string name() const override; @@ -57,7 +57,7 @@ class DummyRequestSourcePluginConfigFactory : public virtual RequestSourcePlugin }; // This factory will be activated through RequestSourceFactory in factories.h -DECLARE_FACTORY(DummyRequestSourcePluginConfigFactory); +DECLARE_FACTORY(StubRequestSourcePluginConfigFactory); // Sample Request Source for small RequestOptionsLists. Loads a copy of the RequestOptionsList in // memory and replays them. diff --git a/source/request_source/stub_plugin_impl.cc b/source/request_source/stub_plugin_impl.cc index 8512bf6eb..f9fc8e918 100644 --- a/source/request_source/stub_plugin_impl.cc +++ b/source/request_source/stub_plugin_impl.cc @@ -11,26 +11,26 @@ namespace Nighthawk { -std::string DummyRequestSourcePluginConfigFactory::name() const { +std::string StubRequestSourcePluginConfigFactory::name() const { return "nighthawk.stub-request-source-plugin"; } -Envoy::ProtobufTypes::MessagePtr DummyRequestSourcePluginConfigFactory::createEmptyConfigProto() { +Envoy::ProtobufTypes::MessagePtr StubRequestSourcePluginConfigFactory::createEmptyConfigProto() { return std::make_unique(); } -RequestSourcePtr DummyRequestSourcePluginConfigFactory::createRequestSourcePlugin( +RequestSourcePtr StubRequestSourcePluginConfigFactory::createRequestSourcePlugin( const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr) { const auto& any = dynamic_cast(message); nighthawk::request_source::StubPluginConfig config; Envoy::MessageUtil::unpackTo(any, config); - return std::make_unique(config); + return std::make_unique(config); } -REGISTER_FACTORY(DummyRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); +REGISTER_FACTORY(StubRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); -DummyRequestSource::DummyRequestSource(const nighthawk::request_source::StubPluginConfig& config) : test_value_{ config.has_test_value() ? config.test_value().value() : 0} {} -RequestGenerator DummyRequestSource::get() { +StubRequestSource::StubRequestSource(const nighthawk::request_source::StubPluginConfig& config) : test_value_{ config.has_test_value() ? config.test_value().value() : 0} {} +RequestGenerator StubRequestSource::get() { RequestGenerator request_generator = [this] () { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); @@ -41,6 +41,6 @@ RequestGenerator DummyRequestSource::get() { return request_generator; } -void DummyRequestSource::initOnThread() {} +void StubRequestSource::initOnThread() {} } // namespace Nighthawk \ No newline at end of file diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 949aacef3..d536f2935 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -21,7 +21,7 @@ using nighthawk::request_source::StubPluginConfig; using ::testing::NiceMock; using ::testing::Test; -class DummyRequestSourcePluginTest : public Test { +class StubRequestSourcePluginTest : public Test { public: Envoy::Stats::MockIsolatedStatsStore stats_store_; }; @@ -38,7 +38,7 @@ class FileBasedRequestSourcePluginTest : public Test { } }; -TEST_F(DummyRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { +TEST_F(StubRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.stub-request-source-plugin"); @@ -48,7 +48,7 @@ TEST_F(DummyRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { EXPECT_TRUE(Envoy::MessageUtil()(*empty_config, expected_config)); } -TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { +TEST_F(StubRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { nighthawk::request_source::StubPluginConfig config; Envoy::ProtobufWkt::Any config_any; config_any.PackFrom(config); @@ -58,7 +58,7 @@ TEST_F(DummyRequestSourcePluginTest, FactoryRegistrationUsesCorrectPluginName) { EXPECT_EQ(config_factory.name(), "nighthawk.stub-request-source-plugin"); } -TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { +TEST_F(StubRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPluginType) { nighthawk::request_source::StubPluginConfig config; Envoy::ProtobufWkt::Any config_any; config_any.PackFrom(config); @@ -69,9 +69,9 @@ TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlug auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr plugin = config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); - EXPECT_NE(dynamic_cast(plugin.get()), nullptr); + EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } -TEST_F(DummyRequestSourcePluginTest, CreateRequestSourcePluginCreatesWorkingPlugin) { +TEST_F(StubRequestSourcePluginTest, CreateRequestSourcePluginCreatesWorkingPlugin) { nighthawk::request_source::StubPluginConfig config; double test_value = 2; config.mutable_test_value()->set_value(test_value); From 7146079afb3fe029d6a7f53bd90d66f14061ceb6 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 30 Sep 2020 18:29:40 +0000 Subject: [PATCH 102/114] Refactor to move plugins into their own libraries and separate files. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/BUILD | 28 ++++++++- .../request_options_list_plugin_impl.cc | 2 +- ...l.h => request_options_list_plugin_impl.h} | 46 +-------------- source/request_source/stub_plugin_impl.cc | 2 +- source/request_source/stub_plugin_impl.h | 58 +++++++++++++++++++ test/request_source/BUILD | 3 +- .../request_source_plugin_test.cc | 3 +- 7 files changed, 91 insertions(+), 51 deletions(-) rename source/request_source/{request_source_plugin_impl.h => request_options_list_plugin_impl.h} (65%) create mode 100644 source/request_source/stub_plugin_impl.h diff --git a/source/request_source/BUILD b/source/request_source/BUILD index 284304356..ec0ab1b67 100644 --- a/source/request_source/BUILD +++ b/source/request_source/BUILD @@ -9,13 +9,35 @@ licenses(["notice"]) # Apache 2 envoy_package() envoy_cc_library( - name = "request_source_plugin_impl", + name = "stub_plugin_impl", srcs = [ - "request_options_list_plugin_impl.cc", "stub_plugin_impl.cc", ], hdrs = [ - "request_source_plugin_impl.h", + "stub_plugin_impl.h", + ], + repository = "@envoy", + visibility = ["//visibility:public"], + deps = [ + "//include/nighthawk/common:request_source_plugin_config_factory_lib", + "//source/common:nighthawk_common_lib", + "//source/common:request_impl_lib", + "//source/common:request_source_impl_lib", + "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", + "@envoy//source/common/protobuf:protobuf_with_external_headers", + "@envoy//source/common/protobuf:utility_lib_with_external_headers", + "@envoy//source/exe:platform_header_lib_with_external_headers", + "@envoy//source/exe:platform_impl_lib", + ], +) + +envoy_cc_library( + name = "request_options_list_plugin_impl", + srcs = [ + "request_options_list_plugin_impl.cc", + ], + hdrs = [ + "request_options_list_plugin_impl.h", ], repository = "@envoy", visibility = ["//visibility:public"], diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index e3a9cfecb..9b788689b 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -7,7 +7,7 @@ #include "common/request_impl.h" #include "common/request_source_impl.h" -#include "request_source/request_source_plugin_impl.h" +#include "request_source/request_options_list_plugin_impl.h" namespace Nighthawk { std::string FileBasedRequestSourcePluginConfigFactory::name() const { diff --git a/source/request_source/request_source_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h similarity index 65% rename from source/request_source/request_source_plugin_impl.h rename to source/request_source/request_options_list_plugin_impl.h index edfd80a8d..84cd68d15 100644 --- a/source/request_source/request_source_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -15,49 +15,6 @@ namespace Nighthawk { -// Stub Request Source implementation for comparison. -class StubRequestSource : public RequestSource { -public: - explicit StubRequestSource(const nighthawk::request_source::StubPluginConfig& config); - // The generator function will return a header whose only value is the test_value taken from the config. - // The function is threadsafe. - RequestGenerator get() override; - - // default implementation - void initOnThread() override; -private: - const double test_value_; - -}; - -// Factory that creates a DummyRequestSource from a DummyRequestSourcePluginConfig proto. -// Registered as an Envoy plugin. -// Stub implementation of RequestSourceConfigFactory which produces a RequestSource. -// RequestSources are used to get RequestGenerators which generate requests for the benchmark -// client. All plugins configuration are specified in the request_source_plugin.proto This class is -// thread-safe, but it doesn't do anything. Usage: assume you are passed an appropriate Any type -// object called config, an Api object called api, and a default header called header. auto& -// config_factory = -// Envoy::Config::Utility::getAndCheckFactoryByName( -// "nighthawk.stub-request-source-plugin"); -// RequestSourcePtr plugin = -// config_factory.createRequestSourcePlugin(config, std::move(api), std::move(header)); - -class StubRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { -public: - // This is a hardcoded string. - std::string name() const override; - // This returns an empty version of the expected StubPluginConfig from request_source_plugin.proto - Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - // This is the primary method that is used to get RequestSources. - // This implementation is thread safe, but the RequestSource it generates doesn't do much. - RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::ApiPtr api, - Envoy::Http::RequestHeaderMapPtr header) override; -}; - -// This factory will be activated through RequestSourceFactory in factories.h -DECLARE_FACTORY(StubRequestSourcePluginConfigFactory); // Sample Request Source for small RequestOptionsLists. Loads a copy of the RequestOptionsList in // memory and replays them. @@ -124,4 +81,5 @@ class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePl // This factory will be activated through RequestSourceFactory in factories.h DECLARE_FACTORY(FileBasedRequestSourcePluginConfigFactory); -} // namespace Nighthawk + +} \ No newline at end of file diff --git a/source/request_source/stub_plugin_impl.cc b/source/request_source/stub_plugin_impl.cc index f9fc8e918..f21f28bf8 100644 --- a/source/request_source/stub_plugin_impl.cc +++ b/source/request_source/stub_plugin_impl.cc @@ -7,7 +7,7 @@ #include "common/request_impl.h" #include "common/request_source_impl.h" -#include "request_source/request_source_plugin_impl.h" +#include "request_source/stub_plugin_impl.h" namespace Nighthawk { diff --git a/source/request_source/stub_plugin_impl.h b/source/request_source/stub_plugin_impl.h new file mode 100644 index 000000000..dd07248c3 --- /dev/null +++ b/source/request_source/stub_plugin_impl.h @@ -0,0 +1,58 @@ +// Implementations of RequestSourceConfigFactory and the RequestSources that those factories make. +#pragma once + +#include "envoy/registry/registry.h" + +#include "nighthawk/common/request_source_plugin_config_factory.h" + +#include "api/client/options.pb.h" +#include "api/request_source/request_source_plugin.pb.h" + +#include "common/uri_impl.h" + +namespace Nighthawk { + +// Stub Request Source implementation for comparison. +class StubRequestSource : public RequestSource { +public: + explicit StubRequestSource(const nighthawk::request_source::StubPluginConfig& config); + // The generator function will return a header whose only value is the test_value taken from the config. + // The function is threadsafe. + RequestGenerator get() override; + + // default implementation + void initOnThread() override; +private: + const double test_value_; + +}; + +// Factory that creates a StubRequestSource from a StubRequestSourcePluginConfig proto. +// Registered as an Envoy plugin. +// Stub implementation of RequestSourceConfigFactory which produces a RequestSource. +// RequestSources are used to get RequestGenerators which generate requests for the benchmark +// client. All plugins configuration are specified in the request_source_plugin.proto This class is +// thread-safe, but it doesn't do anything. Usage: assume you are passed an appropriate Any type +// object called config, an Api object called api, and a default header called header. auto& +// config_factory = +// Envoy::Config::Utility::getAndCheckFactoryByName( +// "nighthawk.stub-request-source-plugin"); +// RequestSourcePtr plugin = +// config_factory.createRequestSourcePlugin(config, std::move(api), std::move(header)); + +class StubRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { +public: + // This is a hardcoded string. + std::string name() const override; + // This returns an empty version of the expected StubPluginConfig from request_source_plugin.proto + Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; + // This is the primary method that is used to get RequestSources. + // This implementation is thread safe, but the RequestSource it generates doesn't do much. + RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, + Envoy::Api::ApiPtr api, + Envoy::Http::RequestHeaderMapPtr header) override; +}; + +// This factory will be activated through RequestSourceFactory in factories.h +DECLARE_FACTORY(StubRequestSourcePluginConfigFactory); +} \ No newline at end of file diff --git a/test/request_source/BUILD b/test/request_source/BUILD index 3c55c2af4..139c8fb11 100644 --- a/test/request_source/BUILD +++ b/test/request_source/BUILD @@ -16,7 +16,8 @@ envoy_cc_test( ], repository = "@envoy", deps = [ - "//source/request_source:request_source_plugin_impl", + "//source/request_source:stub_plugin_impl", + "//source/request_source:request_options_list_plugin_impl", "//test/test_common:environment_lib", "@envoy//source/common/config:utility_lib_with_external_headers", "@envoy//test/mocks/api:api_mocks", diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index d536f2935..153d4e159 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -6,7 +6,8 @@ #include "external/envoy/test/test_common/file_system_for_test.h" #include "external/envoy/test/test_common/utility.h" -#include "request_source/request_source_plugin_impl.h" +#include "request_source/stub_plugin_impl.h" +#include "request_source/request_options_list_plugin_impl.h" #include "test/test_common/environment.h" From 7ab1132cee673ad6e86581bb3a53667b875763b2 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 30 Sep 2020 19:00:50 +0000 Subject: [PATCH 103/114] Moving request_source_plugin_config_factory into its own folder. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/BUILD | 14 ----------- include/nighthawk/request_source/BUILD | 24 +++++++++++++++++++ .../request_source_plugin_config_factory.h | 0 source/request_source/BUILD | 4 ++-- .../request_options_list_plugin_impl.h | 2 +- source/request_source/stub_plugin_impl.h | 2 +- 6 files changed, 28 insertions(+), 18 deletions(-) create mode 100644 include/nighthawk/request_source/BUILD rename include/nighthawk/{common => request_source}/request_source_plugin_config_factory.h (100%) diff --git a/include/nighthawk/common/BUILD b/include/nighthawk/common/BUILD index 71aefd7f7..4fa972f41 100644 --- a/include/nighthawk/common/BUILD +++ b/include/nighthawk/common/BUILD @@ -64,20 +64,6 @@ envoy_basic_cc_library( ], ) -envoy_basic_cc_library( - name = "request_source_plugin_config_factory_lib", - hdrs = [ - "request_source_plugin_config_factory.h", - ], - include_prefix = "nighthawk/common", - deps = [ - ":request_source_lib", - "//api/request_source:request_source_plugin_cc_proto", - "@envoy//include/envoy/common:base_includes", - "@envoy//include/envoy/config:typed_config_interface", - "@envoy//source/common/api:api_lib_with_external_headers", - ], -) envoy_basic_cc_library( name = "request_source_lib", diff --git a/include/nighthawk/request_source/BUILD b/include/nighthawk/request_source/BUILD new file mode 100644 index 000000000..433a599fe --- /dev/null +++ b/include/nighthawk/request_source/BUILD @@ -0,0 +1,24 @@ +load( + "@envoy//bazel:envoy_build_system.bzl", + "envoy_basic_cc_library", + "envoy_package", +) + +licenses(["notice"]) # Apache 2 + +envoy_package() + +envoy_basic_cc_library( + name = "request_source_plugin_config_factory_lib", + hdrs = [ + "request_source_plugin_config_factory.h", + ], + include_prefix = "nighthawk/request_source", + deps = [ + "//include/nighthawk/common:request_source_lib", + "//api/request_source:request_source_plugin_cc_proto", + "@envoy//include/envoy/common:base_includes", + "@envoy//include/envoy/config:typed_config_interface", + "@envoy//source/common/api:api_lib_with_external_headers", + ], +) \ No newline at end of file diff --git a/include/nighthawk/common/request_source_plugin_config_factory.h b/include/nighthawk/request_source/request_source_plugin_config_factory.h similarity index 100% rename from include/nighthawk/common/request_source_plugin_config_factory.h rename to include/nighthawk/request_source/request_source_plugin_config_factory.h diff --git a/source/request_source/BUILD b/source/request_source/BUILD index ec0ab1b67..cb9e596b9 100644 --- a/source/request_source/BUILD +++ b/source/request_source/BUILD @@ -19,7 +19,7 @@ envoy_cc_library( repository = "@envoy", visibility = ["//visibility:public"], deps = [ - "//include/nighthawk/common:request_source_plugin_config_factory_lib", + "//include/nighthawk/request_source:request_source_plugin_config_factory_lib", "//source/common:nighthawk_common_lib", "//source/common:request_impl_lib", "//source/common:request_source_impl_lib", @@ -42,7 +42,7 @@ envoy_cc_library( repository = "@envoy", visibility = ["//visibility:public"], deps = [ - "//include/nighthawk/common:request_source_plugin_config_factory_lib", + "//include/nighthawk/request_source:request_source_plugin_config_factory_lib", "//source/common:nighthawk_common_lib", "//source/common:request_impl_lib", "//source/common:request_source_impl_lib", diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index 84cd68d15..4865df474 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -3,7 +3,7 @@ #include "envoy/registry/registry.h" -#include "nighthawk/common/request_source_plugin_config_factory.h" +#include "nighthawk/request_source/request_source_plugin_config_factory.h" #include "external/envoy/source/common/common/lock_guard.h" #include "external/envoy/source/common/common/thread.h" diff --git a/source/request_source/stub_plugin_impl.h b/source/request_source/stub_plugin_impl.h index dd07248c3..b69d68a7b 100644 --- a/source/request_source/stub_plugin_impl.h +++ b/source/request_source/stub_plugin_impl.h @@ -3,7 +3,7 @@ #include "envoy/registry/registry.h" -#include "nighthawk/common/request_source_plugin_config_factory.h" +#include "nighthawk/request_source/request_source_plugin_config_factory.h" #include "api/client/options.pb.h" #include "api/request_source/request_source_plugin.pb.h" From 72c23d0b43ac83a285475988a3cd0777e6fe7408 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Wed, 30 Sep 2020 19:59:59 +0000 Subject: [PATCH 104/114] Refactor to make it testonly. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/BUILD | 23 ------------------ .../request_options_list_plugin_impl.h | 6 ++--- test/request_source/BUILD | 24 ++++++++++++++++++- .../request_source_plugin_test.cc | 2 +- .../request_source/stub_plugin_impl.cc | 2 +- .../request_source/stub_plugin_impl.h | 0 6 files changed, 27 insertions(+), 30 deletions(-) rename {source => test}/request_source/stub_plugin_impl.cc (97%) rename {source => test}/request_source/stub_plugin_impl.h (100%) diff --git a/source/request_source/BUILD b/source/request_source/BUILD index cb9e596b9..9fdbf5151 100644 --- a/source/request_source/BUILD +++ b/source/request_source/BUILD @@ -8,29 +8,6 @@ licenses(["notice"]) # Apache 2 envoy_package() -envoy_cc_library( - name = "stub_plugin_impl", - srcs = [ - "stub_plugin_impl.cc", - ], - hdrs = [ - "stub_plugin_impl.h", - ], - repository = "@envoy", - visibility = ["//visibility:public"], - deps = [ - "//include/nighthawk/request_source:request_source_plugin_config_factory_lib", - "//source/common:nighthawk_common_lib", - "//source/common:request_impl_lib", - "//source/common:request_source_impl_lib", - "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", - "@envoy//source/common/protobuf:protobuf_with_external_headers", - "@envoy//source/common/protobuf:utility_lib_with_external_headers", - "@envoy//source/exe:platform_header_lib_with_external_headers", - "@envoy//source/exe:platform_impl_lib", - ], -) - envoy_cc_library( name = "request_options_list_plugin_impl", srcs = [ diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index 4865df474..6d4eb83e0 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -48,11 +48,9 @@ class RequestOptionsListRequestSource : public RequestSource { // Factory that creates a RequestOptionsListRequestSource from a FileBasedPluginConfig proto. // Registered as an Envoy plugin. // Implementation of RequestSourceConfigFactory which produces a RequestSource that keeps an -// RequestOptionsList in memory RequestSources are used to get RequestGenerators which generate -// requests for the benchmark client. All plugins configuration are specified in the +// RequestOptionsList in memory, and loads it with the RequestOptions taken from a file. All plugins configuration are specified in the // request_source_plugin.proto This class is not thread-safe, because it loads its RequestOptionlist -// in memory from a file when first called. The in memory RequestOptionsList is protected by -// file_lock_. Usage: assume you are passed an appropriate Any type object called config, an Api +// in memory from a file when first called. Usage: assume you are passed an appropriate Any type object called config, an Api // object called api, and a default header called header. auto& config_factory = // Envoy::Config::Utility::getAndCheckFactoryByName( // "nighthawk.file-based-request-source-plugin"); diff --git a/test/request_source/BUILD b/test/request_source/BUILD index 139c8fb11..28b5f3347 100644 --- a/test/request_source/BUILD +++ b/test/request_source/BUILD @@ -1,6 +1,7 @@ load( "@envoy//bazel:envoy_build_system.bzl", "envoy_cc_test", + "envoy_cc_test_library", "envoy_package", ) @@ -8,6 +9,27 @@ licenses(["notice"]) # Apache 2 envoy_package() +envoy_cc_test_library( + name = "stub_plugin_impl", + srcs = [ + "stub_plugin_impl.cc", + ], + hdrs = [ + "stub_plugin_impl.h", + ], + repository = "@envoy", + deps = [ + "//include/nighthawk/request_source:request_source_plugin_config_factory_lib", + "//source/common:nighthawk_common_lib", + "//source/common:request_impl_lib", + "//source/common:request_source_impl_lib", + "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", + "@envoy//source/common/protobuf:protobuf_with_external_headers", + "@envoy//source/common/protobuf:utility_lib_with_external_headers", + "@envoy//source/exe:platform_header_lib_with_external_headers", + "@envoy//source/exe:platform_impl_lib", + ], +) envoy_cc_test( name = "request_source_plugin_test", srcs = ["request_source_plugin_test.cc"], @@ -16,7 +38,7 @@ envoy_cc_test( ], repository = "@envoy", deps = [ - "//source/request_source:stub_plugin_impl", + "//test/request_source:stub_plugin_impl", "//source/request_source:request_options_list_plugin_impl", "//test/test_common:environment_lib", "@envoy//source/common/config:utility_lib_with_external_headers", diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 153d4e159..5ac63079b 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -6,7 +6,7 @@ #include "external/envoy/test/test_common/file_system_for_test.h" #include "external/envoy/test/test_common/utility.h" -#include "request_source/stub_plugin_impl.h" +#include "test/request_source/stub_plugin_impl.h" #include "request_source/request_options_list_plugin_impl.h" #include "test/test_common/environment.h" diff --git a/source/request_source/stub_plugin_impl.cc b/test/request_source/stub_plugin_impl.cc similarity index 97% rename from source/request_source/stub_plugin_impl.cc rename to test/request_source/stub_plugin_impl.cc index f21f28bf8..993fc7ec9 100644 --- a/source/request_source/stub_plugin_impl.cc +++ b/test/request_source/stub_plugin_impl.cc @@ -7,7 +7,7 @@ #include "common/request_impl.h" #include "common/request_source_impl.h" -#include "request_source/stub_plugin_impl.h" +#include "test/request_source/stub_plugin_impl.h" namespace Nighthawk { diff --git a/source/request_source/stub_plugin_impl.h b/test/request_source/stub_plugin_impl.h similarity index 100% rename from source/request_source/stub_plugin_impl.h rename to test/request_source/stub_plugin_impl.h From 2b1170c3bcc8f582c9e292c905f81b5061422a2f Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 1 Oct 2020 04:45:48 +0000 Subject: [PATCH 105/114] Using references instead of making a copy of the option list. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_options_list_plugin_impl.cc | 12 +++++------- .../request_options_list_plugin_impl.h | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index 9b788689b..21eafc739 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -30,7 +30,6 @@ RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourceP if (api->fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) { throw NighthawkException("file size must be less than max_file_size"); } - auto temp_list = std::make_unique(); // Locking to avoid issues with multiple threads reading the same file. { @@ -40,18 +39,17 @@ RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourceP util.loadFromFile(config.file_path(), options_list_, Envoy::ProtobufMessage::getStrictValidationVisitor(), *api, true); } - temp_list->CopyFrom(options_list_); } return std::make_unique(config.num_requests().value(), - std::move(header), std::move(temp_list)); + std::move(header), options_list_); } REGISTER_FACTORY(FileBasedRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); RequestOptionsListRequestSource::RequestOptionsListRequestSource( const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, - std::unique_ptr options_list) - : header_(std::move(header)), options_list_(std::move(options_list)), + const nighthawk::client::RequestOptionsList& options_list) + : header_(std::move(header)), options_list_(options_list), request_max_(request_max) {} RequestGenerator RequestOptionsListRequestSource::get() { @@ -64,8 +62,8 @@ RequestGenerator RequestOptionsListRequestSource::get() { } // Increment the counter and get the request_option from the list for the current iteration. - int index = lambda_counter % options_list_->options_size(); - nighthawk::client::RequestOptions request_option = options_list_->options().at(index); + int index = lambda_counter % options_list_.options_size(); + nighthawk::client::RequestOptions request_option = options_list_.options().at(index); ++lambda_counter; // Initialize the header with the values from the default header. diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index 6d4eb83e0..eef87f1a0 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -30,7 +30,7 @@ class RequestOptionsListRequestSource : public RequestSource { public: explicit RequestOptionsListRequestSource( const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, - std::unique_ptr options_list); + const nighthawk::client::RequestOptionsList& options_list); // This get function is not thread safe, because multiple threads calling get simultaneously will // result in a collision as it attempts to update its request_count_. RequestGenerator get() override; @@ -40,7 +40,7 @@ class RequestOptionsListRequestSource : public RequestSource { private: Envoy::Http::RequestHeaderMapPtr header_; - const std::unique_ptr options_list_; + const nighthawk::client::RequestOptionsList& options_list_; std::vector request_count_; const uint32_t request_max_; }; @@ -73,7 +73,7 @@ class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePl private: Envoy::Thread::MutexBasicLockable file_lock_; - nighthawk::client::RequestOptionsList options_list_ ABSL_GUARDED_BY(file_lock_); + nighthawk::client::RequestOptionsList options_list_; }; // This factory will be activated through RequestSourceFactory in factories.h From 9dc3c4b89862d49db2d82468accd5eab644cae8c Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 1 Oct 2020 05:28:45 +0000 Subject: [PATCH 106/114] Passing in a reference to api instead of apiptr. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- .../request_source_plugin_config_factory.h | 2 +- .../request_options_list_plugin_impl.cc | 6 +++--- .../request_options_list_plugin_impl.h | 2 +- .../request_source_plugin_test.cc | 19 +++++++++---------- test/request_source/stub_plugin_impl.cc | 2 +- test/request_source/stub_plugin_impl.h | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/include/nighthawk/request_source/request_source_plugin_config_factory.h b/include/nighthawk/request_source/request_source_plugin_config_factory.h index 17936359e..3feccffc9 100644 --- a/include/nighthawk/request_source/request_source_plugin_config_factory.h +++ b/include/nighthawk/request_source/request_source_plugin_config_factory.h @@ -32,7 +32,7 @@ class RequestSourcePluginConfigFactory : public Envoy::Config::TypedFactory { // @throw Envoy::EnvoyException If the Any proto cannot be unpacked as the type expected by the // plugin. virtual RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& typed_config, - Envoy::Api::ApiPtr api, + Envoy::Api::Api& api, Envoy::Http::RequestHeaderMapPtr header) PURE; }; diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index 21eafc739..5d1dc7e7f 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -20,14 +20,14 @@ FileBasedRequestSourcePluginConfigFactory::createEmptyConfigProto() { } RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr api, + const Envoy::Protobuf::Message& message, Envoy::Api::Api& api, Envoy::Http::RequestHeaderMapPtr header) { const auto& any = dynamic_cast(message); nighthawk::request_source::FileBasedPluginConfig config; Envoy::MessageUtil util; util.unpackTo(any, config); - if (api->fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) { + if (api.fileSystem().fileSize(config.file_path()) > config.max_file_size().value()) { throw NighthawkException("file size must be less than max_file_size"); } @@ -37,7 +37,7 @@ RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourceP // Reading the file only the first time. if (options_list_.options_size() == 0) { util.loadFromFile(config.file_path(), options_list_, - Envoy::ProtobufMessage::getStrictValidationVisitor(), *api, true); + Envoy::ProtobufMessage::getStrictValidationVisitor(), api, true); } } return std::make_unique(config.num_requests().value(), diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index eef87f1a0..b21711e0f 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -68,7 +68,7 @@ class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePl // already loaded. The FileBasedRequestSourcePluginConfigFactory will not work with multiple // different files for this reason. RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::ApiPtr api, + Envoy::Api::Api& api, Envoy::Http::RequestHeaderMapPtr header) override; private: diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 5ac63079b..365af67fe 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -24,12 +24,16 @@ using ::testing::Test; class StubRequestSourcePluginTest : public Test { public: + StubRequestSourcePluginTest() : api_(Envoy::Api::createApiForTest(stats_store_)) {} Envoy::Stats::MockIsolatedStatsStore stats_store_; + Envoy::Api::ApiPtr api_; }; class FileBasedRequestSourcePluginTest : public Test { public: + FileBasedRequestSourcePluginTest() : api_(Envoy::Api::createApiForTest(stats_store_)) {} Envoy::Stats::MockIsolatedStatsStore stats_store_; + Envoy::Api::ApiPtr api_; nighthawk::request_source::FileBasedPluginConfig MakeFileBasedPluginConfigWithTestYaml(absl::string_view request_file) { nighthawk::request_source::FileBasedPluginConfig config; @@ -66,10 +70,9 @@ TEST_F(StubRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrectPlugi auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.stub-request-source-plugin"); - auto api = Envoy::Api::createApiForTest(stats_store_); auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr plugin = - config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); + config_factory.createRequestSourcePlugin(config_any, *api_, std::move(header)); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } TEST_F(StubRequestSourcePluginTest, CreateRequestSourcePluginCreatesWorkingPlugin) { @@ -81,10 +84,9 @@ TEST_F(StubRequestSourcePluginTest, CreateRequestSourcePluginCreatesWorkingPlugi auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.stub-request-source-plugin"); - auto api = Envoy::Api::createApiForTest(stats_store_); auto template_header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr plugin = - config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(template_header)); + config_factory.createRequestSourcePlugin(config_any, *api_, std::move(template_header)); Nighthawk::RequestGenerator generator = plugin->get(); Nighthawk::RequestPtr request = generator(); Nighthawk::HeaderMapPtr header = request->header(); @@ -118,10 +120,9 @@ TEST_F(FileBasedRequestSourcePluginTest, CreateRequestSourcePluginCreatesCorrect auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - auto api = Envoy::Api::createApiForTest(stats_store_); auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr plugin = - config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); + config_factory.createRequestSourcePlugin(config_any, *api_, std::move(header)); EXPECT_NE(dynamic_cast(plugin.get()), nullptr); } @@ -135,10 +136,9 @@ TEST_F(FileBasedRequestSourcePluginTest, auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - auto api = Envoy::Api::createApiForTest(stats_store_); auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr file_based_request_source = - config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); + config_factory.createRequestSourcePlugin(config_any,*api_, std::move(header)); Nighthawk::RequestGenerator generator = file_based_request_source->get(); Nighthawk::RequestPtr request = generator(); Nighthawk::RequestPtr request2 = generator(); @@ -160,10 +160,9 @@ TEST_F(FileBasedRequestSourcePluginTest, auto& config_factory = Envoy::Config::Utility::getAndCheckFactoryByName( "nighthawk.file-based-request-source-plugin"); - auto api = Envoy::Api::createApiForTest(stats_store_); auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr file_based_request_source = - config_factory.createRequestSourcePlugin(config_any, std::move(api), std::move(header)); + config_factory.createRequestSourcePlugin(config_any, *api_, std::move(header)); Nighthawk::RequestGenerator generator = file_based_request_source->get(); Nighthawk::RequestPtr request = generator(); Nighthawk::RequestPtr request2 = generator(); diff --git a/test/request_source/stub_plugin_impl.cc b/test/request_source/stub_plugin_impl.cc index 993fc7ec9..d5c00662b 100644 --- a/test/request_source/stub_plugin_impl.cc +++ b/test/request_source/stub_plugin_impl.cc @@ -20,7 +20,7 @@ Envoy::ProtobufTypes::MessagePtr StubRequestSourcePluginConfigFactory::createEmp } RequestSourcePtr StubRequestSourcePluginConfigFactory::createRequestSourcePlugin( - const Envoy::Protobuf::Message& message, Envoy::Api::ApiPtr, Envoy::Http::RequestHeaderMapPtr) { + const Envoy::Protobuf::Message& message, Envoy::Api::Api&, Envoy::Http::RequestHeaderMapPtr) { const auto& any = dynamic_cast(message); nighthawk::request_source::StubPluginConfig config; Envoy::MessageUtil::unpackTo(any, config); diff --git a/test/request_source/stub_plugin_impl.h b/test/request_source/stub_plugin_impl.h index b69d68a7b..c56436f27 100644 --- a/test/request_source/stub_plugin_impl.h +++ b/test/request_source/stub_plugin_impl.h @@ -49,7 +49,7 @@ class StubRequestSourcePluginConfigFactory : public virtual RequestSourcePluginC // This is the primary method that is used to get RequestSources. // This implementation is thread safe, but the RequestSource it generates doesn't do much. RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, - Envoy::Api::ApiPtr api, + Envoy::Api::Api& api, Envoy::Http::RequestHeaderMapPtr header) override; }; From b555a71f0d672567319e0db08aa506455a444839 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 1 Oct 2020 05:36:17 +0000 Subject: [PATCH 107/114] Renaming request_max to total_requests Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/request_options_list_plugin_impl.cc | 6 +++--- source/request_source/request_options_list_plugin_impl.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index 5d1dc7e7f..412a5e279 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -47,17 +47,17 @@ RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourceP REGISTER_FACTORY(FileBasedRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); RequestOptionsListRequestSource::RequestOptionsListRequestSource( - const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, + const uint32_t total_requests, Envoy::Http::RequestHeaderMapPtr header, const nighthawk::client::RequestOptionsList& options_list) : header_(std::move(header)), options_list_(options_list), - request_max_(request_max) {} + total_requests_(total_requests) {} RequestGenerator RequestOptionsListRequestSource::get() { request_count_.push_back(0); uint32_t& lambda_counter = request_count_.back(); RequestGenerator request_generator = [this, lambda_counter]() mutable -> RequestPtr { // if request_max is 0, then we never stop generating requests. - if (lambda_counter >= request_max_ && request_max_ != 0) { + if (lambda_counter >= total_requests_ && total_requests_ != 0) { return nullptr; } diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index b21711e0f..82cfae493 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -18,18 +18,18 @@ namespace Nighthawk { // Sample Request Source for small RequestOptionsLists. Loads a copy of the RequestOptionsList in // memory and replays them. -// @param request_max The number of requests the requestGenerator produced by get() will generate. 0 +// @param total_requests The number of requests the requestGenerator produced by get() will generate. 0 // means it is unlimited. // @param header the default header that will be overridden by values taken from the options_list, // any values not overridden will be used. // @param options_list A copy of the options_list will be loaded in memory. The RequestGenerator // produced by get() will use options from the options_list to overwrite values in the header, and -// create new requests. if request_max is greater than the length of options_list, it will loop. +// create new requests. if total_requests is greater than the length of options_list, it will loop. // This is not thread safe. class RequestOptionsListRequestSource : public RequestSource { public: explicit RequestOptionsListRequestSource( - const uint32_t request_max, Envoy::Http::RequestHeaderMapPtr header, + const uint32_t total_requests, Envoy::Http::RequestHeaderMapPtr header, const nighthawk::client::RequestOptionsList& options_list); // This get function is not thread safe, because multiple threads calling get simultaneously will // result in a collision as it attempts to update its request_count_. @@ -42,7 +42,7 @@ class RequestOptionsListRequestSource : public RequestSource { Envoy::Http::RequestHeaderMapPtr header_; const nighthawk::client::RequestOptionsList& options_list_; std::vector request_count_; - const uint32_t request_max_; + const uint32_t total_requests_; }; // Factory that creates a RequestOptionsListRequestSource from a FileBasedPluginConfig proto. From 3924eee7d951d938046371f4f71fd7b975a0908b Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 1 Oct 2020 05:42:56 +0000 Subject: [PATCH 108/114] Updating comments and removing explicit. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/request_options_list_plugin_impl.h | 9 +++++---- test/request_source/stub_plugin_impl.h | 5 +---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index 82cfae493..e107cf58b 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -28,9 +28,10 @@ namespace Nighthawk { // This is not thread safe. class RequestOptionsListRequestSource : public RequestSource { public: - explicit RequestOptionsListRequestSource( + RequestOptionsListRequestSource( const uint32_t total_requests, Envoy::Http::RequestHeaderMapPtr header, const nighthawk::client::RequestOptionsList& options_list); + // This get function is not thread safe, because multiple threads calling get simultaneously will // result in a collision as it attempts to update its request_count_. RequestGenerator get() override; @@ -59,14 +60,14 @@ class RequestOptionsListRequestSource : public RequestSource { class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; - // This returns an empty version of the expected FileBasedPluginConfig from - // request_source_plugin.proto + Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - // This is the primary method that is used to get RequestSources. + // This implementation is not thread safe. Only the first call to createRequestSourcePlugin will // load the file from memory and subsequent calls just make a copy of the options_list that was // already loaded. The FileBasedRequestSourcePluginConfigFactory will not work with multiple // different files for this reason. + // This method will also error if the file can not be loaded correctly, e.g. the file is too large or could not be found. RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api, Envoy::Http::RequestHeaderMapPtr header) override; diff --git a/test/request_source/stub_plugin_impl.h b/test/request_source/stub_plugin_impl.h index c56436f27..0f002b5b7 100644 --- a/test/request_source/stub_plugin_impl.h +++ b/test/request_source/stub_plugin_impl.h @@ -15,7 +15,7 @@ namespace Nighthawk { // Stub Request Source implementation for comparison. class StubRequestSource : public RequestSource { public: - explicit StubRequestSource(const nighthawk::request_source::StubPluginConfig& config); + StubRequestSource(const nighthawk::request_source::StubPluginConfig& config); // The generator function will return a header whose only value is the test_value taken from the config. // The function is threadsafe. RequestGenerator get() override; @@ -42,11 +42,8 @@ class StubRequestSource : public RequestSource { class StubRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { public: - // This is a hardcoded string. std::string name() const override; - // This returns an empty version of the expected StubPluginConfig from request_source_plugin.proto Envoy::ProtobufTypes::MessagePtr createEmptyConfigProto() override; - // This is the primary method that is used to get RequestSources. // This implementation is thread safe, but the RequestSource it generates doesn't do much. RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api, From 75eca07f12c2fcead11866ed1832b935c8847e68 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 1 Oct 2020 15:58:04 +0000 Subject: [PATCH 109/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- include/nighthawk/common/BUILD | 1 - include/nighthawk/request_source/BUILD | 4 +-- .../request_options_list_plugin_impl.cc | 7 +++-- .../request_options_list_plugin_impl.h | 26 +++++++++---------- test/request_source/BUILD | 3 ++- .../request_source_plugin_test.cc | 7 ++--- test/request_source/stub_plugin_impl.cc | 9 ++++--- test/request_source/stub_plugin_impl.h | 10 +++---- 8 files changed, 34 insertions(+), 33 deletions(-) diff --git a/include/nighthawk/common/BUILD b/include/nighthawk/common/BUILD index 4fa972f41..20f89ef3d 100644 --- a/include/nighthawk/common/BUILD +++ b/include/nighthawk/common/BUILD @@ -64,7 +64,6 @@ envoy_basic_cc_library( ], ) - envoy_basic_cc_library( name = "request_source_lib", hdrs = [ diff --git a/include/nighthawk/request_source/BUILD b/include/nighthawk/request_source/BUILD index 433a599fe..7185a6dae 100644 --- a/include/nighthawk/request_source/BUILD +++ b/include/nighthawk/request_source/BUILD @@ -15,10 +15,10 @@ envoy_basic_cc_library( ], include_prefix = "nighthawk/request_source", deps = [ - "//include/nighthawk/common:request_source_lib", "//api/request_source:request_source_plugin_cc_proto", + "//include/nighthawk/common:request_source_lib", "@envoy//include/envoy/common:base_includes", "@envoy//include/envoy/config:typed_config_interface", "@envoy//source/common/api:api_lib_with_external_headers", ], -) \ No newline at end of file +) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index 412a5e279..fc21a01dd 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -1,3 +1,5 @@ +#include "request_source/request_options_list_plugin_impl.h" + #include "external/envoy/source/common/protobuf/message_validator_impl.h" #include "external/envoy/source/common/protobuf/utility.h" #include "external/envoy/source/exe/platform_impl.h" @@ -7,8 +9,6 @@ #include "common/request_impl.h" #include "common/request_source_impl.h" -#include "request_source/request_options_list_plugin_impl.h" - namespace Nighthawk { std::string FileBasedRequestSourcePluginConfigFactory::name() const { return "nighthawk.file-based-request-source-plugin"; @@ -49,8 +49,7 @@ REGISTER_FACTORY(FileBasedRequestSourcePluginConfigFactory, RequestSourcePluginC RequestOptionsListRequestSource::RequestOptionsListRequestSource( const uint32_t total_requests, Envoy::Http::RequestHeaderMapPtr header, const nighthawk::client::RequestOptionsList& options_list) - : header_(std::move(header)), options_list_(options_list), - total_requests_(total_requests) {} + : header_(std::move(header)), options_list_(options_list), total_requests_(total_requests) {} RequestGenerator RequestOptionsListRequestSource::get() { request_count_.push_back(0); diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index e107cf58b..38e2c34dd 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -15,11 +15,10 @@ namespace Nighthawk { - // Sample Request Source for small RequestOptionsLists. Loads a copy of the RequestOptionsList in // memory and replays them. -// @param total_requests The number of requests the requestGenerator produced by get() will generate. 0 -// means it is unlimited. +// @param total_requests The number of requests the requestGenerator produced by get() will +// generate. 0 means it is unlimited. // @param header the default header that will be overridden by values taken from the options_list, // any values not overridden will be used. // @param options_list A copy of the options_list will be loaded in memory. The RequestGenerator @@ -28,9 +27,9 @@ namespace Nighthawk { // This is not thread safe. class RequestOptionsListRequestSource : public RequestSource { public: - RequestOptionsListRequestSource( - const uint32_t total_requests, Envoy::Http::RequestHeaderMapPtr header, - const nighthawk::client::RequestOptionsList& options_list); + RequestOptionsListRequestSource(const uint32_t total_requests, + Envoy::Http::RequestHeaderMapPtr header, + const nighthawk::client::RequestOptionsList& options_list); // This get function is not thread safe, because multiple threads calling get simultaneously will // result in a collision as it attempts to update its request_count_. @@ -49,10 +48,11 @@ class RequestOptionsListRequestSource : public RequestSource { // Factory that creates a RequestOptionsListRequestSource from a FileBasedPluginConfig proto. // Registered as an Envoy plugin. // Implementation of RequestSourceConfigFactory which produces a RequestSource that keeps an -// RequestOptionsList in memory, and loads it with the RequestOptions taken from a file. All plugins configuration are specified in the -// request_source_plugin.proto This class is not thread-safe, because it loads its RequestOptionlist -// in memory from a file when first called. Usage: assume you are passed an appropriate Any type object called config, an Api -// object called api, and a default header called header. auto& config_factory = +// RequestOptionsList in memory, and loads it with the RequestOptions taken from a file. All plugins +// configuration are specified in the request_source_plugin.proto This class is not thread-safe, +// because it loads its RequestOptionlist in memory from a file when first called. Usage: assume you +// are passed an appropriate Any type object called config, an Api object called api, and a default +// header called header. auto& config_factory = // Envoy::Config::Utility::getAndCheckFactoryByName( // "nighthawk.file-based-request-source-plugin"); // RequestSourcePtr plugin = @@ -67,7 +67,8 @@ class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePl // load the file from memory and subsequent calls just make a copy of the options_list that was // already loaded. The FileBasedRequestSourcePluginConfigFactory will not work with multiple // different files for this reason. - // This method will also error if the file can not be loaded correctly, e.g. the file is too large or could not be found. + // This method will also error if the file can not be loaded correctly, e.g. the file is too large + // or could not be found. RequestSourcePtr createRequestSourcePlugin(const Envoy::Protobuf::Message& message, Envoy::Api::Api& api, Envoy::Http::RequestHeaderMapPtr header) override; @@ -80,5 +81,4 @@ class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePl // This factory will be activated through RequestSourceFactory in factories.h DECLARE_FACTORY(FileBasedRequestSourcePluginConfigFactory); - -} \ No newline at end of file +} // namespace Nighthawk \ No newline at end of file diff --git a/test/request_source/BUILD b/test/request_source/BUILD index 28b5f3347..9b1e6bf18 100644 --- a/test/request_source/BUILD +++ b/test/request_source/BUILD @@ -30,6 +30,7 @@ envoy_cc_test_library( "@envoy//source/exe:platform_impl_lib", ], ) + envoy_cc_test( name = "request_source_plugin_test", srcs = ["request_source_plugin_test.cc"], @@ -38,8 +39,8 @@ envoy_cc_test( ], repository = "@envoy", deps = [ - "//test/request_source:stub_plugin_impl", "//source/request_source:request_options_list_plugin_impl", + "//test/request_source:stub_plugin_impl", "//test/test_common:environment_lib", "@envoy//source/common/config:utility_lib_with_external_headers", "@envoy//test/mocks/api:api_mocks", diff --git a/test/request_source/request_source_plugin_test.cc b/test/request_source/request_source_plugin_test.cc index 365af67fe..a7fa62cec 100644 --- a/test/request_source/request_source_plugin_test.cc +++ b/test/request_source/request_source_plugin_test.cc @@ -6,9 +6,9 @@ #include "external/envoy/test/test_common/file_system_for_test.h" #include "external/envoy/test/test_common/utility.h" -#include "test/request_source/stub_plugin_impl.h" #include "request_source/request_options_list_plugin_impl.h" +#include "test/request_source/stub_plugin_impl.h" #include "test/test_common/environment.h" #include "gmock/gmock.h" @@ -90,7 +90,8 @@ TEST_F(StubRequestSourcePluginTest, CreateRequestSourcePluginCreatesWorkingPlugi Nighthawk::RequestGenerator generator = plugin->get(); Nighthawk::RequestPtr request = generator(); Nighthawk::HeaderMapPtr header = request->header(); - EXPECT_EQ(header->get(Envoy::Http::LowerCaseString("test_value"))->value().getStringView(), absl::string_view(std::to_string(test_value))); + EXPECT_EQ(header->get(Envoy::Http::LowerCaseString("test_value"))->value().getStringView(), + absl::string_view(std::to_string(test_value))); } TEST_F(FileBasedRequestSourcePluginTest, CreateEmptyConfigProtoCreatesCorrectType) { auto& config_factory = @@ -138,7 +139,7 @@ TEST_F(FileBasedRequestSourcePluginTest, "nighthawk.file-based-request-source-plugin"); auto header = Envoy::Http::RequestHeaderMapImpl::create(); RequestSourcePtr file_based_request_source = - config_factory.createRequestSourcePlugin(config_any,*api_, std::move(header)); + config_factory.createRequestSourcePlugin(config_any, *api_, std::move(header)); Nighthawk::RequestGenerator generator = file_based_request_source->get(); Nighthawk::RequestPtr request = generator(); Nighthawk::RequestPtr request2 = generator(); diff --git a/test/request_source/stub_plugin_impl.cc b/test/request_source/stub_plugin_impl.cc index d5c00662b..7ca882263 100644 --- a/test/request_source/stub_plugin_impl.cc +++ b/test/request_source/stub_plugin_impl.cc @@ -1,3 +1,5 @@ +#include "test/request_source/stub_plugin_impl.h" + #include "external/envoy/source/common/protobuf/message_validator_impl.h" #include "external/envoy/source/common/protobuf/utility.h" #include "external/envoy/source/exe/platform_impl.h" @@ -7,8 +9,6 @@ #include "common/request_impl.h" #include "common/request_source_impl.h" -#include "test/request_source/stub_plugin_impl.h" - namespace Nighthawk { std::string StubRequestSourcePluginConfigFactory::name() const { @@ -29,10 +29,11 @@ RequestSourcePtr StubRequestSourcePluginConfigFactory::createRequestSourcePlugin REGISTER_FACTORY(StubRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); -StubRequestSource::StubRequestSource(const nighthawk::request_source::StubPluginConfig& config) : test_value_{ config.has_test_value() ? config.test_value().value() : 0} {} +StubRequestSource::StubRequestSource(const nighthawk::request_source::StubPluginConfig& config) + : test_value_{config.has_test_value() ? config.test_value().value() : 0} {} RequestGenerator StubRequestSource::get() { - RequestGenerator request_generator = [this] () { + RequestGenerator request_generator = [this]() { Envoy::Http::RequestHeaderMapPtr header = Envoy::Http::RequestHeaderMapImpl::create(); header->setCopy(Envoy::Http::LowerCaseString("test_value"), std::to_string(test_value_)); auto returned_request_impl = std::make_unique(std::move(header)); diff --git a/test/request_source/stub_plugin_impl.h b/test/request_source/stub_plugin_impl.h index 0f002b5b7..ad96c119b 100644 --- a/test/request_source/stub_plugin_impl.h +++ b/test/request_source/stub_plugin_impl.h @@ -16,15 +16,15 @@ namespace Nighthawk { class StubRequestSource : public RequestSource { public: StubRequestSource(const nighthawk::request_source::StubPluginConfig& config); - // The generator function will return a header whose only value is the test_value taken from the config. - // The function is threadsafe. + // The generator function will return a header whose only value is the test_value taken from the + // config. The function is threadsafe. RequestGenerator get() override; // default implementation void initOnThread() override; -private: - const double test_value_; +private: + const double test_value_; }; // Factory that creates a StubRequestSource from a StubRequestSourcePluginConfig proto. @@ -52,4 +52,4 @@ class StubRequestSourcePluginConfigFactory : public virtual RequestSourcePluginC // This factory will be activated through RequestSourceFactory in factories.h DECLARE_FACTORY(StubRequestSourcePluginConfigFactory); -} \ No newline at end of file +} // namespace Nighthawk \ No newline at end of file From e2af886aad714723e6f517165f2143936bb2e7be Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 1 Oct 2020 18:48:12 +0000 Subject: [PATCH 110/114] Clean up. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/request_options_list_plugin_impl.cc | 2 +- source/request_source/request_options_list_plugin_impl.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index fc21a01dd..d4050cf28 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -61,7 +61,7 @@ RequestGenerator RequestOptionsListRequestSource::get() { } // Increment the counter and get the request_option from the list for the current iteration. - int index = lambda_counter % options_list_.options_size(); + const uint32_t index = lambda_counter % options_list_.options_size(); nighthawk::client::RequestOptions request_option = options_list_.options().at(index); ++lambda_counter; diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index 38e2c34dd..e7e1d17ca 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -21,8 +21,8 @@ namespace Nighthawk { // generate. 0 means it is unlimited. // @param header the default header that will be overridden by values taken from the options_list, // any values not overridden will be used. -// @param options_list A copy of the options_list will be loaded in memory. The RequestGenerator -// produced by get() will use options from the options_list to overwrite values in the header, and +// @param options_list This is const because it is intended to be shared by multiple threads. The RequestGenerator +// produced by get() will use options from the options_list to overwrite values in the default header, and // create new requests. if total_requests is greater than the length of options_list, it will loop. // This is not thread safe. class RequestOptionsListRequestSource : public RequestSource { From edae9be520af269fb01bd13e9446afd96c547aad Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Thu, 1 Oct 2020 19:05:48 +0000 Subject: [PATCH 111/114] Rename FilebasedConfigFactory to OptionListFromFileFactory Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/request_options_list_plugin_impl.cc | 8 ++++---- source/request_source/request_options_list_plugin_impl.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index d4050cf28..e5a656635 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -10,16 +10,16 @@ #include "common/request_source_impl.h" namespace Nighthawk { -std::string FileBasedRequestSourcePluginConfigFactory::name() const { +std::string OptionsListFromFileRequestSourceFactory::name() const { return "nighthawk.file-based-request-source-plugin"; } Envoy::ProtobufTypes::MessagePtr -FileBasedRequestSourcePluginConfigFactory::createEmptyConfigProto() { +OptionsListFromFileRequestSourceFactory::createEmptyConfigProto() { return std::make_unique(); } -RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourcePlugin( +RequestSourcePtr OptionsListFromFileRequestSourceFactory::createRequestSourcePlugin( const Envoy::Protobuf::Message& message, Envoy::Api::Api& api, Envoy::Http::RequestHeaderMapPtr header) { const auto& any = dynamic_cast(message); @@ -44,7 +44,7 @@ RequestSourcePtr FileBasedRequestSourcePluginConfigFactory::createRequestSourceP std::move(header), options_list_); } -REGISTER_FACTORY(FileBasedRequestSourcePluginConfigFactory, RequestSourcePluginConfigFactory); +REGISTER_FACTORY(OptionsListFromFileRequestSourceFactory, RequestSourcePluginConfigFactory); RequestOptionsListRequestSource::RequestOptionsListRequestSource( const uint32_t total_requests, Envoy::Http::RequestHeaderMapPtr header, diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index e7e1d17ca..5c155a314 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -57,7 +57,7 @@ class RequestOptionsListRequestSource : public RequestSource { // "nighthawk.file-based-request-source-plugin"); // RequestSourcePtr plugin = // config_factory.createRequestSourcePlugin(config, std::move(api), std::move(header)); -class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePluginConfigFactory { +class OptionsListFromFileRequestSourceFactory : public virtual RequestSourcePluginConfigFactory { public: std::string name() const override; @@ -65,7 +65,7 @@ class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePl // This implementation is not thread safe. Only the first call to createRequestSourcePlugin will // load the file from memory and subsequent calls just make a copy of the options_list that was - // already loaded. The FileBasedRequestSourcePluginConfigFactory will not work with multiple + // already loaded. The OptionsListFromFileRequestSourceFactory will not work with multiple // different files for this reason. // This method will also error if the file can not be loaded correctly, e.g. the file is too large // or could not be found. @@ -79,6 +79,6 @@ class FileBasedRequestSourcePluginConfigFactory : public virtual RequestSourcePl }; // This factory will be activated through RequestSourceFactory in factories.h -DECLARE_FACTORY(FileBasedRequestSourcePluginConfigFactory); +DECLARE_FACTORY(OptionsListFromFileRequestSourceFactory); } // namespace Nighthawk \ No newline at end of file From 949d73146354b4d63184c31b6f190533ff6e4adc Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 2 Oct 2020 16:40:41 +0000 Subject: [PATCH 112/114] Improving Comments. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/request_source/request_source_plugin.proto | 2 +- source/request_source/request_options_list_plugin_impl.h | 2 +- test/request_source/stub_plugin_impl.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index ff717ffbd..0d8c7a5c7 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -30,6 +30,6 @@ message FileBasedPluginConfig { // mechanism using a minimal version of plugin that does not require a more complicated proto or // file reading. message StubPluginConfig { - // test input value. + // test input value which is the only output value in the headers produced from the requestGenerator for the StubRequestSource. google.protobuf.DoubleValue test_value = 1; } diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index 5c155a314..8227ac21e 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -1,4 +1,4 @@ -// Implementations of RequestSourceConfigFactory and the RequestSources that those factories make. +// Implementations of RequestSourceConfigFactories that make a RequestOptionsListRequestSource. #pragma once #include "envoy/registry/registry.h" diff --git a/test/request_source/stub_plugin_impl.h b/test/request_source/stub_plugin_impl.h index ad96c119b..92d0c840a 100644 --- a/test/request_source/stub_plugin_impl.h +++ b/test/request_source/stub_plugin_impl.h @@ -1,4 +1,4 @@ -// Implementations of RequestSourceConfigFactory and the RequestSources that those factories make. +// Test implementations of RequestSourceConfigFactory and RequestSource that perform minimum functionality for testing purposes. #pragma once #include "envoy/registry/registry.h" From 59d490fab23ae084a60ddafc87dbf783d30c4967 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 2 Oct 2020 16:44:26 +0000 Subject: [PATCH 113/114] Fix format. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- api/request_source/request_source_plugin.proto | 3 ++- source/request_source/request_options_list_plugin_impl.cc | 3 +-- source/request_source/request_options_list_plugin_impl.h | 8 ++++---- test/request_source/stub_plugin_impl.h | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api/request_source/request_source_plugin.proto b/api/request_source/request_source_plugin.proto index 0d8c7a5c7..1af69a60a 100644 --- a/api/request_source/request_source_plugin.proto +++ b/api/request_source/request_source_plugin.proto @@ -30,6 +30,7 @@ message FileBasedPluginConfig { // mechanism using a minimal version of plugin that does not require a more complicated proto or // file reading. message StubPluginConfig { - // test input value which is the only output value in the headers produced from the requestGenerator for the StubRequestSource. + // test input value which is the only output value in the headers produced from the + // requestGenerator for the StubRequestSource. google.protobuf.DoubleValue test_value = 1; } diff --git a/source/request_source/request_options_list_plugin_impl.cc b/source/request_source/request_options_list_plugin_impl.cc index e5a656635..7fd25f3aa 100644 --- a/source/request_source/request_options_list_plugin_impl.cc +++ b/source/request_source/request_options_list_plugin_impl.cc @@ -14,8 +14,7 @@ std::string OptionsListFromFileRequestSourceFactory::name() const { return "nighthawk.file-based-request-source-plugin"; } -Envoy::ProtobufTypes::MessagePtr -OptionsListFromFileRequestSourceFactory::createEmptyConfigProto() { +Envoy::ProtobufTypes::MessagePtr OptionsListFromFileRequestSourceFactory::createEmptyConfigProto() { return std::make_unique(); } diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index 8227ac21e..2cc29670e 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -21,10 +21,10 @@ namespace Nighthawk { // generate. 0 means it is unlimited. // @param header the default header that will be overridden by values taken from the options_list, // any values not overridden will be used. -// @param options_list This is const because it is intended to be shared by multiple threads. The RequestGenerator -// produced by get() will use options from the options_list to overwrite values in the default header, and -// create new requests. if total_requests is greater than the length of options_list, it will loop. -// This is not thread safe. +// @param options_list This is const because it is intended to be shared by multiple threads. The +// RequestGenerator produced by get() will use options from the options_list to overwrite values in +// the default header, and create new requests. if total_requests is greater than the length of +// options_list, it will loop. This is not thread safe. class RequestOptionsListRequestSource : public RequestSource { public: RequestOptionsListRequestSource(const uint32_t total_requests, diff --git a/test/request_source/stub_plugin_impl.h b/test/request_source/stub_plugin_impl.h index 92d0c840a..b45e64c9e 100644 --- a/test/request_source/stub_plugin_impl.h +++ b/test/request_source/stub_plugin_impl.h @@ -1,4 +1,5 @@ -// Test implementations of RequestSourceConfigFactory and RequestSource that perform minimum functionality for testing purposes. +// Test implementations of RequestSourceConfigFactory and RequestSource that perform minimum +// functionality for testing purposes. #pragma once #include "envoy/registry/registry.h" From 078329af3ba47432a7b32c1d937fdf4fed159523 Mon Sep 17 00:00:00 2001 From: William Juan <66322422+wjuan-AFK@users.noreply.github.com> Date: Fri, 2 Oct 2020 17:00:14 +0000 Subject: [PATCH 114/114] More comment cleanup. Signed-off-by: William Juan <66322422+wjuan-AFK@users.noreply.github.com> --- source/request_source/request_options_list_plugin_impl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/request_source/request_options_list_plugin_impl.h b/source/request_source/request_options_list_plugin_impl.h index 2cc29670e..3fbf485ff 100644 --- a/source/request_source/request_options_list_plugin_impl.h +++ b/source/request_source/request_options_list_plugin_impl.h @@ -49,10 +49,10 @@ class RequestOptionsListRequestSource : public RequestSource { // Registered as an Envoy plugin. // Implementation of RequestSourceConfigFactory which produces a RequestSource that keeps an // RequestOptionsList in memory, and loads it with the RequestOptions taken from a file. All plugins -// configuration are specified in the request_source_plugin.proto This class is not thread-safe, -// because it loads its RequestOptionlist in memory from a file when first called. Usage: assume you -// are passed an appropriate Any type object called config, an Api object called api, and a default -// header called header. auto& config_factory = +// configuration are specified in the request_source_plugin.proto. This class is not thread-safe, +// because it loads its RequestOptionlist in memory from a file when first called. +// Usage: assume you are passed an appropriate Any type object called config, an Api object called +// api, and a default header called header. auto& config_factory = // Envoy::Config::Utility::getAndCheckFactoryByName( // "nighthawk.file-based-request-source-plugin"); // RequestSourcePtr plugin =