-
Notifications
You must be signed in to change notification settings - Fork 89
Adaptive load session spec proto helpers #508
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
Merged
dubious90
merged 52 commits into
envoyproxy:master
from
eric846:adaptive-rps-spec-validation
Sep 11, 2020
Merged
Changes from all commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
8ea442d
Merge pull request #5 from envoyproxy/master
eric846 5ac755a
Merge pull request #6 from envoyproxy/master
eric846 b8c25a5
Merge pull request #7 from envoyproxy/master
eric846 1c19c68
initial commit
eric846 7050686
fix comments
eric846 0776563
fix format
eric846 16fd8f6
rename adaptive_rps to adaptive_load
eric846 c383010
add field_selector in example
eric846 6e1a483
fix example comment
eric846 4ef1140
fix format
eric846 4111bf4
add support for fault injection headers
eric846 871a959
replace linear and binary search with exponential search
eric846 1fd77c1
add InputVariableSetter mechanism
eric846 edc36b2
add input variable setter to build file
eric846 4d0364e
fix syntax errors
eric846 aed6d94
rename samples/adaptive_rps
eric846 d9ae87d
improve comments, change step controller initial value from int64 to …
eric846 a05a6f5
add proto validation rules, fix comments, make rps the default input_…
eric846 8cd4d21
fix comment wording
eric846 d814a96
simplify protos, add defaults, specify required or optional
eric846 5f5a885
add missing newline
eric846 7e20a78
Kick CI
eric846 9048267
simplify protos
eric846 306c0ec
fix format
eric846 d33f543
fix some optional field comments and rules
eric846 442cca9
Merge pull request #10 from envoyproxy/master
eric846 677b783
add Nighthawk status field in BenchmarkResult as nested nighthawk.cli…
eric846 cefb366
switch to standard Envoy plugin config proto, add prefix to internal …
eric846 f3684df
Merge remote-tracking branch 'upstream/master' into adaptive-rps-protos2
eric846 5463051
create headers
eric846 46e0e25
fix format
eric846 f634642
use docstring format
eric846 3c39faa
fix typos in comments
eric846 b9c8f2b
split build target, get rid of ostream, change InputValueSetter to us…
eric846 5fc4db4
remove nested namespace, remove redundant _include in target names
eric846 64e7852
merge from upstream
eric846 12807f1
Merge remote-tracking branch 'upstream/master' into adaptive-rps-headers
eric846 e8e960f
merge from upstream
eric846 6306b4e
Merge remote-tracking branch 'upstream/master' into master2
eric846 1ece783
Merge remote-tracking branch 'upstream/master' into master2
eric846 70705e9
Merge remote-tracking branch 'upstream/master' into master2
eric846 e576bc1
Merge remote-tracking branch 'upstream/master' into master2
eric846 1fca528
Merge remote-tracking branch 'upstream/master' into master2
eric846 8eae526
initial commit - session spec proto helper and FakeMetricsPlugin helper
eric846 a10b625
rename SetDefaults
eric846 f2dccb2
fix clang-tidy
eric846 ed32856
Merge remote-tracking branch 'upstream/master' into master2
eric846 eecf00d
Merge remote-tracking branch 'upstream/master' into master2
eric846 ce68373
Merge branch 'master2' into adaptive-rps-spec-validation
eric846 07493ae
remove accidental comment
eric846 13179fb
Merge remote-tracking branch 'upstream/master' into master2
eric846 6bcae4d
Merge branch 'master2' into adaptive-rps-spec-validation
eric846 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
include/nighthawk/adaptive_load/session_spec_proto_helper.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #pragma once | ||
|
|
||
| #include "envoy/common/pure.h" | ||
|
|
||
| #include "api/adaptive_load/adaptive_load.pb.h" | ||
|
|
||
| #include "absl/status/status.h" | ||
|
|
||
| namespace Nighthawk { | ||
|
|
||
| /** | ||
| * Utilities for setting default values and validating user settings in the main | ||
| * AdaptiveLoadSessionSpec proto. | ||
| */ | ||
| class AdaptiveLoadSessionSpecProtoHelper { | ||
| public: | ||
| virtual ~AdaptiveLoadSessionSpecProtoHelper() = default; | ||
|
|
||
| /** | ||
| * Returns a copy of the input spec with default values inserted. Avoids overriding pre-set values | ||
| * in the original spec. | ||
| * | ||
| * @param spec Valid adaptive load session spec. | ||
| * | ||
| * @return Adaptive load session spec with default values inserted. | ||
| */ | ||
| virtual nighthawk::adaptive_load::AdaptiveLoadSessionSpec | ||
| SetSessionSpecDefaults(nighthawk::adaptive_load::AdaptiveLoadSessionSpec spec) PURE; | ||
|
|
||
| /** | ||
| * Checks whether a session spec is valid: No forbidden fields in Nighthawk traffic spec; no bad | ||
| * plugin references or bad plugin configurations (step controller, metric, scoring function); no | ||
| * nonexistent metric names. Reports all errors in one pass. | ||
| * | ||
| * @param spec A potentially invalid adaptive load session spec. | ||
| * | ||
| * @return Status OK if no problems were found, or InvalidArgument with all errors. | ||
| */ | ||
| virtual absl::Status | ||
| CheckSessionSpec(const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec) PURE; | ||
| }; | ||
|
|
||
| } // namespace Nighthawk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| #include "adaptive_load/session_spec_proto_helper_impl.h" | ||
|
|
||
| #include "nighthawk/adaptive_load/metrics_plugin.h" | ||
| #include "nighthawk/adaptive_load/step_controller.h" | ||
|
|
||
| #include "api/adaptive_load/adaptive_load.pb.h" | ||
| #include "api/adaptive_load/metric_spec.pb.h" | ||
|
|
||
| #include "absl/container/flat_hash_map.h" | ||
| #include "absl/strings/str_join.h" | ||
| #include "absl/strings/string_view.h" | ||
| #include "adaptive_load/metrics_plugin_impl.h" | ||
| #include "adaptive_load/plugin_loader.h" | ||
|
|
||
| namespace Nighthawk { | ||
|
|
||
| nighthawk::adaptive_load::AdaptiveLoadSessionSpec | ||
| AdaptiveLoadSessionSpecProtoHelperImpl::SetSessionSpecDefaults( | ||
| nighthawk::adaptive_load::AdaptiveLoadSessionSpec spec) { | ||
| if (!spec.nighthawk_traffic_template().has_open_loop()) { | ||
| spec.mutable_nighthawk_traffic_template()->mutable_open_loop()->set_value(true); | ||
| } | ||
| if (!spec.has_measuring_period()) { | ||
| spec.mutable_measuring_period()->set_seconds(10); | ||
| } | ||
| if (!spec.has_convergence_deadline()) { | ||
| spec.mutable_convergence_deadline()->set_seconds(300); | ||
| } | ||
| if (!spec.has_testing_stage_duration()) { | ||
| spec.mutable_testing_stage_duration()->set_seconds(30); | ||
| } | ||
| for (nighthawk::adaptive_load::MetricSpecWithThreshold& threshold : | ||
| *spec.mutable_metric_thresholds()) { | ||
| if (threshold.metric_spec().metrics_plugin_name().empty()) { | ||
| threshold.mutable_metric_spec()->set_metrics_plugin_name("nighthawk.builtin"); | ||
| } | ||
| if (!threshold.threshold_spec().has_weight()) { | ||
| threshold.mutable_threshold_spec()->mutable_weight()->set_value(1.0); | ||
| } | ||
| } | ||
| for (nighthawk::adaptive_load::MetricSpec& metric_spec : | ||
| *spec.mutable_informational_metric_specs()) { | ||
| if (metric_spec.metrics_plugin_name().empty()) { | ||
| metric_spec.set_metrics_plugin_name("nighthawk.builtin"); | ||
| } | ||
| } | ||
| return spec; | ||
| } | ||
|
|
||
| absl::Status AdaptiveLoadSessionSpecProtoHelperImpl::CheckSessionSpec( | ||
| const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec) { | ||
| std::vector<std::string> errors; | ||
| if (spec.nighthawk_traffic_template().has_duration()) { | ||
| errors.emplace_back( | ||
| "nighthawk_traffic_template should not have |duration| set. Set |measuring_period| " | ||
| "and |testing_stage_duration| in the AdaptiveLoadSessionSpec proto instead."); | ||
| } | ||
| absl::flat_hash_map<std::string, MetricsPluginPtr> plugin_from_name; | ||
| std::vector<std::string> plugin_names = {"nighthawk.builtin"}; | ||
| plugin_from_name["nighthawk.builtin"] = | ||
| std::make_unique<NighthawkStatsEmulatedMetricsPlugin>(nighthawk::client::Output()); | ||
| for (const envoy::config::core::v3::TypedExtensionConfig& config : | ||
| spec.metrics_plugin_configs()) { | ||
| plugin_names.push_back(config.name()); | ||
| absl::StatusOr<MetricsPluginPtr> metrics_plugin_or = LoadMetricsPlugin(config); | ||
| if (!metrics_plugin_or.ok()) { | ||
| errors.emplace_back( | ||
| absl::StrCat("Failed to load MetricsPlugin: ", metrics_plugin_or.status().message())); | ||
| continue; | ||
| } | ||
| plugin_from_name[config.name()] = std::move(metrics_plugin_or.value()); | ||
| } | ||
| absl::StatusOr<StepControllerPtr> step_controller_or = | ||
| LoadStepControllerPlugin(spec.step_controller_config(), spec.nighthawk_traffic_template()); | ||
| if (!step_controller_or.ok()) { | ||
| errors.emplace_back(absl::StrCat("Failed to load StepController plugin: ", | ||
| step_controller_or.status().message())); | ||
| } | ||
| std::vector<nighthawk::adaptive_load::MetricSpec> all_metric_specs; | ||
| for (const nighthawk::adaptive_load::MetricSpecWithThreshold& metric_threshold : | ||
| spec.metric_thresholds()) { | ||
| all_metric_specs.push_back(metric_threshold.metric_spec()); | ||
| absl::StatusOr<ScoringFunctionPtr> scoring_function_or = | ||
| LoadScoringFunctionPlugin(metric_threshold.threshold_spec().scoring_function()); | ||
| if (!scoring_function_or.ok()) { | ||
| errors.emplace_back(absl::StrCat("Failed to load ScoringFunction plugin: ", | ||
| scoring_function_or.status().message())); | ||
| } | ||
| } | ||
| for (const nighthawk::adaptive_load::MetricSpec& metric_spec : | ||
| spec.informational_metric_specs()) { | ||
| all_metric_specs.push_back(metric_spec); | ||
| } | ||
| for (const nighthawk::adaptive_load::MetricSpec& metric_spec : all_metric_specs) { | ||
| if (plugin_from_name.contains(metric_spec.metrics_plugin_name())) { | ||
| std::vector<std::string> supported_metrics = | ||
| plugin_from_name[metric_spec.metrics_plugin_name()]->GetAllSupportedMetricNames(); | ||
| if (std::find(supported_metrics.begin(), supported_metrics.end(), | ||
| metric_spec.metric_name()) == supported_metrics.end()) { | ||
| errors.emplace_back( | ||
| absl::StrCat("Metric named '", metric_spec.metric_name(), | ||
| "' not implemented by plugin '", metric_spec.metrics_plugin_name(), | ||
| "'. Metrics implemented: ", absl::StrJoin(supported_metrics, ", "), ".")); | ||
| } | ||
| } else { | ||
| errors.emplace_back(absl::StrCat( | ||
| "MetricSpec referred to nonexistent metrics_plugin_name '", | ||
| metric_spec.metrics_plugin_name(), | ||
| "'. You must declare the plugin in metrics_plugin_configs or use plugin ", | ||
| "'nighthawk.builtin'. Available plugins: ", absl::StrJoin(plugin_names, ", "), ".")); | ||
| } | ||
| } | ||
| if (errors.size() > 0) { | ||
| return absl::InvalidArgumentError(absl::StrJoin(errors, "\n")); | ||
| } | ||
| return absl::OkStatus(); | ||
| } | ||
|
|
||
| } // namespace Nighthawk | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #include "nighthawk/adaptive_load/session_spec_proto_helper.h" | ||
|
|
||
| namespace Nighthawk { | ||
|
|
||
| class AdaptiveLoadSessionSpecProtoHelperImpl : public AdaptiveLoadSessionSpecProtoHelper { | ||
| public: | ||
| nighthawk::adaptive_load::AdaptiveLoadSessionSpec | ||
| SetSessionSpecDefaults(nighthawk::adaptive_load::AdaptiveLoadSessionSpec spec) override; | ||
|
|
||
| absl::Status | ||
| CheckSessionSpec(const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec) override; | ||
| }; | ||
|
|
||
| } // namespace Nighthawk |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.