Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory plugin implementation #566

Merged
merged 208 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
208 commits
Select commit Hold shift + click to select a range
99f45d1
Adding a multiple path test to confirm that expected paths are hit
wjuan-AFK Jul 15, 2020
075a4cf
fixing asan problems
wjuan-AFK Jul 17, 2020
ecbf407
Fix Format
wjuan-AFK Jul 17, 2020
8fb11b6
Removeing unused comments
wjuan-AFK Jul 17, 2020
032dbba
Removing unnecessary invoke calls for cleanliness
wjuan-AFK Jul 17, 2020
953e953
Merge branch 'master' into RequestSourceUnitTestBenchmarkMultiplePath
wjuan-AFK Jul 17, 2020
6185edb
Refactoring test to take in request generator parameter instead of using
wjuan-AFK Jul 20, 2020
cded6ad
Changing to pass by reference.
wjuan-AFK Jul 20, 2020
fbfe523
Merge branch 'master' into RequestSourceUnitTestBenchmarkMultiplePath
wjuan-AFK Jul 20, 2020
0d70179
Merge branch 'master' into RequestSourceUnitTestBenchmarkMultiplePath
wjuan-AFK Jul 21, 2020
cdb7efe
Refactoring per comments in PR. Moving helpers, renaming functions.
wjuan-AFK Jul 21, 2020
f15bb47
Adding comments and renaming testbasicfunctionality for clarity
wjuan-AFK Jul 21, 2020
59359a2
Consistent unit test naming convention using should. Clarifying comments
wjuan-AFK Jul 21, 2020
f63df91
Fix format
wjuan-AFK Jul 21, 2020
406bd6b
Adding a clarifying comment for helper function.
wjuan-AFK Jul 22, 2020
f0b697b
Fixing typo and other nits
wjuan-AFK Jul 23, 2020
8425e48
Renaming testBenchmarkClient for clarity
wjuan-AFK Jul 23, 2020
fb4f372
Replacing Flat hash map with flat hash set for simplicity.
wjuan-AFK Jul 24, 2020
c6eae6c
Comment clarification.
wjuan-AFK Jul 24, 2020
96ae38b
Small refactor for factory method for more dependency injection.
wjuan-AFK Jul 27, 2020
b17240f
Fix format.
wjuan-AFK Jul 27, 2020
5c5a146
Refactor to inject the requestsourceconstructor.
wjuan-AFK Jul 27, 2020
29591ff
Moving helper functions.
wjuan-AFK Jul 27, 2020
7d928a9
Merge branch 'RequestSourceUnitTestBenchmarkMultiplePath' into Adding…
wjuan-AFK Jul 27, 2020
ff82d95
Fix format.
wjuan-AFK Jul 27, 2020
98381a4
Adding test using the new mock requestsourceconstructor to get remote
wjuan-AFK Jul 28, 2020
83ac556
Fix format.
wjuan-AFK Jul 28, 2020
38c5084
Adding missing request source constructor files.
wjuan-AFK Jul 28, 2020
fa4e285
Changing helper functions to anonymous namespace.
wjuan-AFK Jul 28, 2020
8551c76
Changing to use a nullable pointer instead of reference for clarity.
wjuan-AFK Jul 28, 2020
437de5e
Formatting fixes per PR.
wjuan-AFK Jul 28, 2020
6cef87e
Fix format.
wjuan-AFK Jul 28, 2020
c84ba4d
Merge branch 'master' into RequestSourceUnitTestBenchmarkMultiplePath
wjuan-AFK Jul 28, 2020
77d33f9
Fix format after merge.
wjuan-AFK Jul 29, 2020
73aa686
Testing a theory.
wjuan-AFK Jul 29, 2020
ef77d65
Fix format.
wjuan-AFK Jul 29, 2020
b9182a0
Merge branch 'RequestSourceUnitTestBenchmarkMultiplePath' into Adding…
wjuan-AFK Jul 29, 2020
e38dd80
Merge branch 'master' into RequestSourceUnitTestBenchmarkMultiplePath
wjuan-AFK Jul 29, 2020
21734e4
Merge branch 'RequestSourceUnitTestBenchmarkMultiplePath' into Adding…
wjuan-AFK Jul 29, 2020
7cda9d2
Merge branch 'master' into AddingTestForRequestSourceFactory
wjuan-AFK Aug 17, 2020
f827aca
Adding initial protos and stubs.
wjuan-AFK Aug 19, 2020
d194736
Adding impl for Dummy request source plugin.
wjuan-AFK Aug 19, 2020
7820cf9
Adding test for request source factory creation.
wjuan-AFK Aug 19, 2020
bee7805
Adding some more protos.
wjuan-AFK Aug 19, 2020
3db68ce
Merge branch 'master' into AddingTestForRequestSourceFactory
wjuan-AFK Aug 19, 2020
c0ec4dd
Merge branch 'AddingTestForRequestSourceFactory' into AddingConfigFac…
wjuan-AFK Aug 19, 2020
a1dd3f2
Fixing mockrequestsourcefactory impacted by the refactor.
wjuan-AFK Aug 20, 2020
0b25261
Adding more factories to the impl.h
wjuan-AFK Aug 20, 2020
c3fa23c
Fixing clang tidy.
wjuan-AFK Aug 20, 2020
547977e
Updating the impl.cc with a stub for the new factories.
wjuan-AFK Aug 20, 2020
c300203
Adding test for file based request source plugin
wjuan-AFK Aug 26, 2020
8f4d4d9
Adding test yaml file.
wjuan-AFK Aug 26, 2020
5ae2d51
Merge branch 'AddingTestForRequestSourceFactory' into AddingConfigFac…
wjuan-AFK Aug 26, 2020
fe74b6d
First try getting requests working.
wjuan-AFK Aug 27, 2020
6d87aea
Switching to using multiple requestOptions instead of one.
wjuan-AFK Sep 1, 2020
ca7a0c2
Removing unused comments.
wjuan-AFK Sep 2, 2020
967e3f8
Adding api dependency injection.
wjuan-AFK Sep 2, 2020
14b7d79
Getting the multiple paths parsing into the test.
wjuan-AFK Sep 3, 2020
c4985bb
Comment clean up and using loadfromfile instead of reading the file and
wjuan-AFK Sep 3, 2020
922639a
Switching to using iterators in a vector instead of a smart pointer.
wjuan-AFK Sep 9, 2020
81dfece
Removing unused comments.
wjuan-AFK Sep 9, 2020
bf08661
Small cleanup.
wjuan-AFK Sep 10, 2020
34900c5
Merge branch 'master' into AddingTestForRequestSourceFactory
wjuan-AFK Sep 10, 2020
768fa81
Merge branch 'AddingTestForRequestSourceFactory' into AddingConfigFac…
wjuan-AFK Sep 10, 2020
e93bb58
Reverting changes to RequestSourceConstructor.
wjuan-AFK Sep 10, 2020
f47cbd4
Removing RPCRequestSourcePlugin
wjuan-AFK Sep 10, 2020
7c5c6b2
Fix format.
wjuan-AFK Sep 10, 2020
1b02cec
Fix format.
wjuan-AFK Sep 10, 2020
4d75602
Fixing clang problems.
wjuan-AFK Sep 11, 2020
c74f535
Fixing clang.
wjuan-AFK Sep 11, 2020
9949fb8
Fix format.
wjuan-AFK Sep 11, 2020
fcf10d3
Fixing clang tidy.
wjuan-AFK Sep 11, 2020
fd9744d
Fix Format
wjuan-AFK Sep 11, 2020
68c1037
Rename requestOptionses to requestOptionsList.
wjuan-AFK Sep 14, 2020
883ee30
Renaming proto.
wjuan-AFK Sep 15, 2020
8c34b25
Updating to take a number of requests.
wjuan-AFK Sep 16, 2020
6ce7e74
Clean up tests.
wjuan-AFK Sep 16, 2020
92927e5
Changing visibility of RequestSourcePlugin's inheritance.
wjuan-AFK Sep 16, 2020
a62f2d5
Switching to using lock_guard.
wjuan-AFK Sep 16, 2020
16f89c6
Clean up.
wjuan-AFK Sep 16, 2020
f4257e3
Fix Format.
wjuan-AFK Sep 16, 2020
d075588
Addressing comments on PR. Cleaning up formatting.
wjuan-AFK Sep 17, 2020
eb10a3b
Getting rid of RequestSourcePluginPtr, and adding comments.
wjuan-AFK Sep 17, 2020
cdbd6bf
Removing unnecessary RequestSourcePlugin interface for improved testa…
wjuan-AFK Sep 17, 2020
17acc5f
Fix format
wjuan-AFK Sep 17, 2020
55a0e62
Cleanup unintentional whitespace.
wjuan-AFK Sep 18, 2020
fa23aad
Swapping to exception instead of Release_assert.
wjuan-AFK Sep 18, 2020
b8e2447
Renaming the request_source_plugin to request_source_plugin_config_fa…
wjuan-AFK Sep 18, 2020
248f439
Using a context struct for extensability.
wjuan-AFK Sep 22, 2020
91703b5
Spacing and comments.
wjuan-AFK Sep 22, 2020
bbc0c2a
Fix format.
wjuan-AFK Sep 22, 2020
517c83d
Adding test for multiple request sources thread lock.
wjuan-AFK Sep 22, 2020
c1d0428
Additional comment
wjuan-AFK Sep 22, 2020
bc86c09
Getting rid of context object because the Register Factory mechanism …
wjuan-AFK Sep 22, 2020
33e3564
Adding option to circumvent file reading.
wjuan-AFK Sep 23, 2020
338a874
Merge branch 'master' into AddingConfigFactory
wjuan-AFK Sep 23, 2020
402ada2
Fix format.
wjuan-AFK Sep 23, 2020
017481f
Getting rid of default constructors.
wjuan-AFK Sep 23, 2020
3ed43fc
Renames for clarity.
wjuan-AFK Sep 23, 2020
247b71b
Fix format.
wjuan-AFK Sep 23, 2020
718e4cd
Adding initial CLI code for requestSourceplugin.
wjuan-AFK Sep 24, 2020
50c0c07
Fixing build.
wjuan-AFK Sep 24, 2020
171fb2e
Splitting factory off into a separate pr.
wjuan-AFK Sep 24, 2020
5df83ed
Proto cleanup/rename
wjuan-AFK Sep 24, 2020
0af3ffd
Comment cleanup.
wjuan-AFK Sep 24, 2020
ff90e59
Proto comments and dummy -> stub clean up.
wjuan-AFK Sep 24, 2020
e57c05f
Cleaning up comments
wjuan-AFK Sep 28, 2020
55244b0
Updating class comments.
wjuan-AFK Sep 28, 2020
3d0b1a2
Merge pull request #3 from wjuan-AFK/AddingConfigFactory
wjuan-AFK Sep 28, 2020
c710d37
Refactor to move RequestSourcePlugins to a top level RequestSource fo…
wjuan-AFK Sep 28, 2020
fbb2fdc
Refactor plugins into separate files.
wjuan-AFK Sep 28, 2020
ae0f4a8
Fix format.
wjuan-AFK Sep 28, 2020
e092de0
Merge branch 'master' into AddingConfigFactory
wjuan-AFK Sep 28, 2020
1b87b71
Merge branch 'AddingConfigFactory' into CLIChangeForFileBasedRequestS…
wjuan-AFK Sep 28, 2020
6a72987
Merge branch 'CLIChangeForFileBasedRequestSource' of github.com:wjuan…
wjuan-AFK Sep 28, 2020
a080eec
Clean up after refactor moving plugins.
wjuan-AFK Sep 28, 2020
19b7aa0
Adding gmock and gtest to check_format so it stops complaining at me.
wjuan-AFK Sep 28, 2020
dae3098
Updating to prefix increment, and removing auto.
wjuan-AFK Sep 29, 2020
a4b6fb1
Removing gmock and gtest from script to avoid conflict. Add Request_s…
wjuan-AFK Sep 29, 2020
55f685e
Fixing clang-tidy
wjuan-AFK Sep 30, 2020
59c5b94
Using the test value in the stub for better testing.
wjuan-AFK Sep 30, 2020
2ea0c5e
Getting rid of auto. And updating stubplugintest.
wjuan-AFK Sep 30, 2020
d40a073
Further renaming.
wjuan-AFK Sep 30, 2020
7146079
Refactor to move plugins into their own libraries and separate files.
wjuan-AFK Sep 30, 2020
7ab1132
Moving request_source_plugin_config_factory into its own folder.
wjuan-AFK Sep 30, 2020
72c23d0
Refactor to make it testonly.
wjuan-AFK Sep 30, 2020
2b1170c
Using references instead of making a copy of the option list.
wjuan-AFK Oct 1, 2020
9dc3c4b
Passing in a reference to api instead of apiptr.
wjuan-AFK Oct 1, 2020
b555a71
Renaming request_max to total_requests
wjuan-AFK Oct 1, 2020
3924eee
Updating comments and removing explicit.
wjuan-AFK Oct 1, 2020
75eca07
Fix format.
wjuan-AFK Oct 1, 2020
9c93ff9
Merge branch 'master' into AddingConfigFactory
wjuan-AFK Oct 1, 2020
0040b33
Merge branch 'AddingConfigFactory' into CLIChangeForFileBasedRequestS…
wjuan-AFK Oct 1, 2020
e2af886
Clean up.
wjuan-AFK Oct 1, 2020
edae9be
Rename FilebasedConfigFactory to OptionListFromFileFactory
wjuan-AFK Oct 1, 2020
949d731
Improving Comments.
wjuan-AFK Oct 2, 2020
59d490f
Fix format.
wjuan-AFK Oct 2, 2020
078329a
More comment cleanup.
wjuan-AFK Oct 2, 2020
63e5d2b
Merge branch 'AddingConfigFactory' into CLIChangeForFileBasedRequestS…
wjuan-AFK Oct 2, 2020
530cc9c
Adding proto request source factory.
wjuan-AFK Oct 7, 2020
22cc3f8
Merge branch 'master' into AddingProtoOnlyFactory
wjuan-AFK Oct 7, 2020
32489d0
Fix format.
wjuan-AFK Oct 7, 2020
324bb23
Fixing Clang tidy.
wjuan-AFK Oct 7, 2020
5d6bb26
Clarifying proto comments.
wjuan-AFK Oct 8, 2020
32ae13d
Rename, using optional, and moving functions in test.
wjuan-AFK Oct 8, 2020
12708ac
Need to stop forggetting to add blank lines or update the fix format …
wjuan-AFK Oct 8, 2020
eff2f4e
Replacing request with request1
wjuan-AFK Oct 8, 2020
b890df4
Renaming tests for clarity
wjuan-AFK Oct 8, 2020
a907913
Adding assertions for safety.
wjuan-AFK Oct 8, 2020
49a47a4
Clarifying comments on parameters
wjuan-AFK Oct 8, 2020
b711028
Fix format.
wjuan-AFK Oct 8, 2020
8a2d792
Renames based on feedback, and swapping to using uint32 instead of ui…
wjuan-AFK Oct 9, 2020
22b93aa
Fix format.
wjuan-AFK Oct 9, 2020
7b9c175
Cleaning up comments per feedback.
wjuan-AFK Oct 21, 2020
bab49fc
Clarifying comments.
wjuan-AFK Oct 21, 2020
7184695
Adding test for CLI changes.
wjuan-AFK Oct 21, 2020
fc7eda6
Removing implementation detail from comment.
wjuan-AFK Oct 22, 2020
49e6eec
Fix Format.
wjuan-AFK Oct 22, 2020
43de3d8
Merge branch 'master' into AddingProtoOnlyFactory
wjuan-AFK Oct 22, 2020
fef08dd
Merge branch 'AddingProtoOnlyFactory' into CLIChangeForFileBasedReque…
wjuan-AFK Oct 22, 2020
264355c
Fixing merge.
wjuan-AFK Oct 22, 2020
fa4d4c9
Adding inlineoptionslist test.
wjuan-AFK Oct 22, 2020
546449a
Formatting.
wjuan-AFK Oct 22, 2020
1a28a30
Cleaning up.
wjuan-AFK Oct 22, 2020
fa2adc5
Fix format.
wjuan-AFK Oct 22, 2020
01959ea
Additional cleanup.
wjuan-AFK Oct 22, 2020
6696b5e
Merge branch 'master' into CLIChangeForFileBasedRequestSource
wjuan-AFK Oct 22, 2020
6168223
Fixing build.
wjuan-AFK Oct 22, 2020
3043405
Fix format.
wjuan-AFK Oct 22, 2020
309f75b
Updating ReadMe via updateReadme command.
wjuan-AFK Oct 22, 2020
4a63c18
Lowering threshold for CI integration test coverage so the PR can be …
wjuan-AFK Oct 26, 2020
55a7460
Comment cleanup. Signed-off-by: William Juan <66322422+wjuan-AFK@user…
wjuan-AFK Oct 26, 2020
a1646e6
Adding factory implementation.
wjuan-AFK Oct 26, 2020
eababba
Python test is passing.
wjuan-AFK Oct 26, 2020
f935dbc
fix format
wjuan-AFK Oct 26, 2020
1aa000a
Enabling the RequestSourcePlugins.
wjuan-AFK Oct 26, 2020
e471e2b
Fix format.
wjuan-AFK Oct 28, 2020
edfdbf3
Reverting the threshold change since this PR has the python tests in it.
wjuan-AFK Oct 28, 2020
fdb84d2
Enforcing mutual exclusivity.
wjuan-AFK Oct 28, 2020
592345a
Adding decimal point to clarify the precision.
wjuan-AFK Oct 28, 2020
e98211f
Adding coverage for initOnThread.
wjuan-AFK Oct 29, 2020
436f952
Adding maxFileSize test, fixing bug.
wjuan-AFK Oct 29, 2020
fee4328
fix format.
wjuan-AFK Nov 2, 2020
c37cde2
Adding bad json test.
wjuan-AFK Nov 2, 2020
8e56850
Adding TODO.
wjuan-AFK Nov 2, 2020
ac18ebb
Clarifying comments.
wjuan-AFK Nov 2, 2020
66cd5ed
Replacing string comparison with empty check per style.
wjuan-AFK Nov 2, 2020
fc254f0
Switching to parametrized test.
wjuan-AFK Nov 2, 2020
9a409dd
Small cleanup for stylistic reasons.
wjuan-AFK Nov 2, 2020
314f924
Comment clean up.
wjuan-AFK Nov 3, 2020
587cf3c
Adding back additional comparison to avoid edge cases missed.
wjuan-AFK Nov 3, 2020
8401dd5
Fix format
wjuan-AFK Nov 3, 2020
f25fd1e
Merge branch 'CLIChangeForFileBasedRequestSource' into FactoryPluginI…
wjuan-AFK Nov 3, 2020
77782cd
Adding factory test for RequestSourcePlugin.
wjuan-AFK Nov 4, 2020
95070b1
Adding check for plugin use in integration test.
wjuan-AFK Nov 4, 2020
5034b19
Removing unnecessary prints.
wjuan-AFK Nov 4, 2020
5c4a717
Adding additional integration test.
wjuan-AFK Nov 4, 2020
8937c6a
Merge
wjuan-AFK Nov 5, 2020
835a42e
Changing api_ to a private datamember.
wjuan-AFK Nov 6, 2020
177b16c
Adding additional coverage for remote request source.
wjuan-AFK Nov 7, 2020
6d4323f
Adding clarifying comments.
wjuan-AFK Nov 9, 2020
f73c20c
Parametrizing integration test.
wjuan-AFK Nov 9, 2020
d04aa5e
changing to exception over assert, and adding tests.
wjuan-AFK Nov 9, 2020
3be39ae
Removing new line since check format was complaining.
wjuan-AFK Nov 9, 2020
932de71
Fix format
wjuan-AFK Nov 9, 2020
e9572a8
Adding python format exclusion because of weird conflict between fix …
wjuan-AFK Nov 9, 2020
b6b5b64
Update comment.
wjuan-AFK Nov 11, 2020
dc5d9c8
Merge branch 'master' into FactoryPluginImplementation
wjuan-AFK Nov 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions source/client/factories_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "client/output_collector_impl.h"
#include "client/output_formatter_impl.h"

#include "request_source/request_options_list_plugin_impl.h"

using namespace std::chrono_literals;

namespace Nighthawk {
Expand Down Expand Up @@ -117,8 +119,8 @@ OutputFormatterPtr OutputFormatterFactoryImpl::create(
}
}

RequestSourceFactoryImpl::RequestSourceFactoryImpl(const Options& options)
: OptionBasedFactoryImpl(options) {}
RequestSourceFactoryImpl::RequestSourceFactoryImpl(const Options& options, Envoy::Api::Api& api)
: OptionBasedFactoryImpl(options), api_(api) {}

void RequestSourceFactoryImpl::setRequestHeader(Envoy::Http::RequestHeaderMap& header,
absl::string_view key,
Expand Down Expand Up @@ -168,18 +170,41 @@ RequestSourceFactoryImpl::create(const Envoy::Upstream::ClusterManagerPtr& clust
for (const auto& option_header : request_options.request_headers()) {
setRequestHeader(*header, option_header.header().key(), option_header.header().value());
}

if (!options_.requestSource().empty()) {
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<RemoteRequestSourceImpl>(cluster_manager, dispatcher, scope,
service_cluster_name, std::move(header),
options_.requestsPerSecond());
} else if (options_.requestSourcePluginConfig().has_value()) {
absl::StatusOr<RequestSourcePtr> plugin_or = LoadRequestSourcePlugin(
options_.requestSourcePluginConfig().value(), api_, std::move(header));
if (!plugin_or.ok()) {
throw NighthawkException(
absl::StrCat("Request Source plugin loading error should have been caught "
"during input validation: ",
plugin_or.status().message()));
}
RequestSourcePtr request_source = std::move(plugin_or.value());
return request_source;
} else {
return std::make_unique<StaticRequestSourceImpl>(std::move(header));
}
}
absl::StatusOr<RequestSourcePtr> RequestSourceFactoryImpl::LoadRequestSourcePlugin(
const envoy::config::core::v3::TypedExtensionConfig& config, Envoy::Api::Api& api,
Envoy::Http::RequestHeaderMapPtr header) const {
try {
auto& config_factory =
Envoy::Config::Utility::getAndCheckFactoryByName<RequestSourcePluginConfigFactory>(
config.name());
return config_factory.createRequestSourcePlugin(config.typed_config(), api, std::move(header));
} catch (const Envoy::EnvoyException& e) {
return absl::InvalidArgumentError(
absl::StrCat("Could not load plugin: ", config.name(), ": ", e.what()));
}
}

TerminationPredicateFactoryImpl::TerminationPredicateFactoryImpl(const Options& options)
: OptionBasedFactoryImpl(options) {}
Expand Down
22 changes: 21 additions & 1 deletion source/client/factories_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include "nighthawk/common/termination_predicate.h"
#include "nighthawk/common/uri.h"

#include "external/envoy/source/common/common/statusor.h"
#include "external/envoy/source/common/config/utility.h"

#include "common/platform_util_impl.h"

namespace Nighthawk {
Expand Down Expand Up @@ -58,14 +61,31 @@ class OutputFormatterFactoryImpl : public OutputFormatterFactory {

class RequestSourceFactoryImpl : public OptionBasedFactoryImpl, public RequestSourceFactory {
public:
RequestSourceFactoryImpl(const Options& options);
RequestSourceFactoryImpl(const Options& options, Envoy::Api::Api& api);
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:
Envoy::Api::Api& api_;
void setRequestHeader(Envoy::Http::RequestHeaderMap& header, absl::string_view key,
absl::string_view value) const;
/**
* Instantiates a RequestSource using a RequestSourcePluginFactory based on the plugin name in
* |config|, unpacking the plugin-specific config proto within |config|. Validates the config
* proto.
*
* @param config Proto containing plugin name and plugin-specific config proto.
* @param api Api parameter that contains timesystem, filesystem, and threadfactory.
* @param header Any headers in request specifiers yielded by the request
* source plugin will override what is specified here.

* @return absl::StatusOr<RequestSourcePtr> Initialized plugin or error status due to missing
* plugin or config proto validation error.
*/
absl::StatusOr<RequestSourcePtr>
LoadRequestSourcePlugin(const envoy::config::core::v3::TypedExtensionConfig& config,
Envoy::Api::Api& api, Envoy::Http::RequestHeaderMapPtr header) const;
};

class TerminationPredicateFactoryImpl : public OptionBasedFactoryImpl,
Expand Down
3 changes: 2 additions & 1 deletion source/client/process_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ ProcessImpl::ProcessImpl(const Options& options, Envoy::Event::TimeSystem& time_
generator_)),
dispatcher_(api_->allocateDispatcher("main_thread")), benchmark_client_factory_(options),
termination_predicate_factory_(options), sequencer_factory_(options),
request_generator_factory_(options), options_(options), init_manager_("nh_init_manager"),
request_generator_factory_(options, *api_), options_(options),
init_manager_("nh_init_manager"),
local_info_(new Envoy::LocalInfo::LocalInfoImpl(
{}, Envoy::Network::Utility::getLocalAddress(Envoy::Network::Address::IpVersion::v4),
"nighthawk_service_zone", "nighthawk_service_cluster", "nighthawk_service_node")),
Expand Down
1 change: 1 addition & 0 deletions test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ envoy_cc_test(
"//test/mocks/client:mock_benchmark_client",
"//test/mocks/client:mock_options",
"//test/mocks/common:mock_termination_predicate",
"//test/test_common:environment_lib",
"@envoy//test/mocks/event:event_mocks",
"@envoy//test/mocks/tracing:tracing_mocks",
"@envoy//test/test_common:simulated_time_system_lib",
Expand Down
114 changes: 110 additions & 4 deletions test/factories_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#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/test_common/environment.h"

#include "gtest/gtest.h"

Expand Down Expand Up @@ -52,20 +53,125 @@ TEST_F(FactoriesTest, CreateBenchmarkClient) {
EXPECT_NE(nullptr, benchmark_client.get());
}

TEST_F(FactoriesTest, CreateRequestSourcePluginWithWorkingJsonReturnsWorkingRequestSource) {
absl::optional<envoy::config::core::v3::TypedExtensionConfig> request_source_plugin_config;
std::string request_source_plugin_config_json =
"{"
"name:\"nighthawk.in-line-options-list-request-source-plugin\","
"typed_config:{"
"\"@type\":\"type.googleapis.com/"
"nighthawk.request_source.InLineOptionsListRequestSourceConfig\","
"options_list:{"
"options:[{request_method:\"1\",request_headers:[{header:{key:\":path\",value:\"inlinepath\"}"
"}]}]"
"},"
"}"
"}";
request_source_plugin_config.emplace(envoy::config::core::v3::TypedExtensionConfig());
Envoy::MessageUtil::loadFromJson(request_source_plugin_config_json,
request_source_plugin_config.value(),
Envoy::ProtobufMessage::getStrictValidationVisitor());
EXPECT_CALL(options_, requestMethod()).Times(1);
EXPECT_CALL(options_, requestBodySize()).Times(1);
EXPECT_CALL(options_, uri()).Times(2).WillRepeatedly(Return("http://foo/"));
EXPECT_CALL(options_, requestSource()).Times(1);
EXPECT_CALL(options_, requestSourcePluginConfig())
.Times(2)
.WillRepeatedly(ReturnRef(request_source_plugin_config));
auto cmd = std::make_unique<nighthawk::client::CommandLineOptions>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit) Can we replace some of these auto statements with the actual type? Only needed in places where the type isn't obvious from the expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood.

envoy::config::core::v3::HeaderValueOption* 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_, *api_);
Envoy::Upstream::ClusterManagerPtr cluster_manager;
Nighthawk::RequestSourcePtr request_source = factory.create(
cluster_manager, dispatcher_, *stats_store_.createScope("foo."), "requestsource");
EXPECT_NE(nullptr, request_source.get());
Nighthawk::RequestGenerator generator = request_source->get();
Nighthawk::RequestPtr request = generator();
EXPECT_EQ("inlinepath", request->header()->getPathValue());
}

TEST_F(FactoriesTest, CreateRequestSourcePluginWithNonWorkingJsonThrowsError) {
absl::optional<envoy::config::core::v3::TypedExtensionConfig> request_source_plugin_config;
std::string request_source_plugin_config_json =
"{"
R"(name:"nighthawk.file-based-request-source-plugin",)"
"typed_config:{"
R"("@type":"type.googleapis.com/)"
R"(nighthawk.request_source.FileBasedOptionsListRequestSourceConfig",)"
R"(file_path:")" +
TestEnvironment::runfilesPath("test/request_source/test_data/NotARealFile.yaml") +
"\","
"}"
"}";
request_source_plugin_config.emplace(envoy::config::core::v3::TypedExtensionConfig());
Envoy::MessageUtil::loadFromJson(request_source_plugin_config_json,
request_source_plugin_config.value(),
Envoy::ProtobufMessage::getStrictValidationVisitor());
EXPECT_CALL(options_, requestMethod()).Times(1);
EXPECT_CALL(options_, requestBodySize()).Times(1);
EXPECT_CALL(options_, uri()).Times(2).WillRepeatedly(Return("http://foo/"));
EXPECT_CALL(options_, requestSource()).Times(1);
EXPECT_CALL(options_, requestSourcePluginConfig())
.Times(2)
.WillRepeatedly(ReturnRef(request_source_plugin_config));
auto cmd = std::make_unique<nighthawk::client::CommandLineOptions>();
envoy::config::core::v3::HeaderValueOption* 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_, *api_);
Envoy::Upstream::ClusterManagerPtr cluster_manager;
EXPECT_THROW_WITH_REGEX(
factory.create(cluster_manager, dispatcher_, *stats_store_.createScope("foo."),
"requestsource"),
NighthawkException,
"Request Source plugin loading error should have been caught during input validation");
}

TEST_F(FactoriesTest, CreateRequestSource) {
absl::optional<envoy::config::core::v3::TypedExtensionConfig> request_source_plugin_config;
EXPECT_CALL(options_, requestMethod()).Times(1);
EXPECT_CALL(options_, requestBodySize()).Times(1);
EXPECT_CALL(options_, uri()).Times(2).WillRepeatedly(Return("http://foo/"));
EXPECT_CALL(options_, requestSource()).Times(1);
EXPECT_CALL(options_, requestSourcePluginConfig())
.Times(1)
.WillRepeatedly(ReturnRef(request_source_plugin_config));
auto cmd = std::make_unique<nighthawk::client::CommandLineOptions>();
envoy::config::core::v3::HeaderValueOption* 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_, *api_);
Envoy::Upstream::ClusterManagerPtr cluster_manager;
RequestSourcePtr request_generator = factory.create(
cluster_manager, dispatcher_, *stats_store_.createScope("foo."), "requestsource");
EXPECT_NE(nullptr, request_generator.get());
}

TEST_F(FactoriesTest, CreateRemoteRequestSource) {
absl::optional<envoy::config::core::v3::TypedExtensionConfig> request_source_plugin_config;
EXPECT_CALL(options_, requestMethod()).Times(1);
EXPECT_CALL(options_, requestBodySize()).Times(1);
EXPECT_CALL(options_, uri()).Times(2).WillRepeatedly(Return("http://foo/"));
EXPECT_CALL(options_, requestSource()).Times(1).WillRepeatedly(Return("http://bar/"));
EXPECT_CALL(options_, requestsPerSecond()).Times(1).WillRepeatedly(Return(5));
auto cmd = std::make_unique<nighthawk::client::CommandLineOptions>();
auto request_headers = cmd->mutable_request_options()->add_request_headers();
envoy::config::core::v3::HeaderValueOption* 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_);
RequestSourceFactoryImpl factory(options_, *api_);
Envoy::Upstream::ClusterManagerPtr cluster_manager;
auto request_generator = factory.create(cluster_manager, dispatcher_,
*stats_store_.createScope("foo."), "requestsource");
RequestSourcePtr request_generator = factory.create(
cluster_manager, dispatcher_, *stats_store_.createScope("foo."), "requestsource");
EXPECT_NE(nullptr, request_generator.get());
}

Expand Down
59 changes: 59 additions & 0 deletions test/integration/test_request_source_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Tests for the nighthawk_service binary."""

import pytest
import os

from test.integration.integration_test_fixtures import (http_test_server_fixture, server_config)
from test.integration import utility
from test.integration import asserts


@pytest.mark.parametrize(
"request_source_config,expected_min,expected_max",
[
pytest.param("""
{
name:"nighthawk.in-line-options-list-request-source-plugin",
typed_config:{
"@type":"type.googleapis.com/nighthawk.request_source.InLineOptionsListRequestSourceConfig",
options_list:{
options:[
{request_method:"1",request_body_size:"1",request_headers:[{header:{"key":"x-nighthawk-test-server-config","value":"{response_body_size:13}"}}]},
{request_method:"1",request_body_size:"2",request_headers:[{header:{"key":"x-nighthawk-test-server-config","value":"{response_body_size:17}"}}]},
]
},
}
}""",
13,
17,
id="in-line"),
pytest.param("""
{
name:"nighthawk.file-based-request-source-plugin",
typed_config:{
"@type":"type.googleapis.com/nighthawk.request_source.FileBasedOptionsListRequestSourceConfig",
file_path:"%s",
}
}""" % (os.path.dirname(os.path.abspath(os.path.dirname(__file__))) +
"/request_source/test_data/test-config.yaml"),
13,
17,
id="file-based"),
],
)
def test_request_source_plugin_happy_flow_parametrized(http_test_server_fixture,
request_source_config, expected_min,
expected_max):
"""Test that the nighthawkClient can run with request-source-plugin option."""
parsed_json, _ = http_test_server_fixture.runNighthawkClient([
"--termination-predicate", "benchmark.http_2xx:5", "--rps 10",
"--request-source-plugin-config %s" % request_source_config,
http_test_server_fixture.getTestServerRootUri(), "--request-header", "host: sni.com"
])
counters = http_test_server_fixture.getNighthawkCounterMapFromJson(parsed_json)
global_histograms = http_test_server_fixture.getNighthawkGlobalHistogramsbyIdFromJson(parsed_json)
asserts.assertGreaterEqual(counters["benchmark.http_2xx"], 5)
asserts.assertEqual(int(global_histograms["benchmark_http_client.response_body_size"]["raw_max"]),
expected_max)
asserts.assertEqual(int(global_histograms["benchmark_http_client.response_body_size"]["raw_min"]),
expected_min)
18 changes: 8 additions & 10 deletions test/request_source/test_data/test-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
options:
- request_body_size: 10
- request_method: 1
request_body_size: 10
request_headers:
- { header: { key: ":path", value: "/a" } }
- { header: { key: "foo", value: "bar" } }
- { header: { key: "foo", value: "bar2" } }
- { header: { key: "x-nh", value: "1" } }
- request_body_size: 10
- { header: { key: ":path", value: "/a" } }
- { header: { key: "x-nighthawk-test-server-config", value: "{response_body_size:13}" } }
- request_method: 1
request_body_size: 10
request_headers:
- { header: { key: ":path", value: "/b" } }
- { header: { key: "bar", value: "foo" } }
- { header: { key: "bar", value: "foo2" } }
- { header: { key: "x-nh", value: "2" } }
- { header: { key: ":path", value: "/b" } }
- { header: { key: "x-nighthawk-test-server-config", value: "{response_body_size:17}" } }
3 changes: 2 additions & 1 deletion tools/format_python_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ EXCLUDE="--exclude=benchmarks/tmp/*,.cache/*,*/venv/*,tools/format_python_tools.
# E124 Closing bracket does not match visual indentation
# E125 Continuation line with same indent as next logical line
# E126 Continuation line over-indented for hanging indent
# W504 line break after binary operator

# We ignore false positives because of what look like pytest peculiarities
# F401 Module imported but unused
# F811 Redefinition of unused name from line n
flake8 . ${EXCLUDE} --ignore=E114,E111,E501,F401,F811,E124,E125,E126,D --count --show-source --statistics
flake8 . ${EXCLUDE} --ignore=E114,E111,E501,F401,F811,E124,E125,E126,W504,D --count --show-source --statistics
# D = Doc comment related checks (We check both p257 AND google conventions).
flake8 . ${EXCLUDE} --docstring-convention pep257 --select=D --count --show-source --statistics
flake8 . ${EXCLUDE} --docstring-convention google --select=D --count --show-source --statistics
Expand Down