-
Notifications
You must be signed in to change notification settings - Fork 89
Adaptive Load metrics evaluator library #495
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 61 commits into
envoyproxy:master
from
eric846:adaptive-rps-metric-evaluation
Sep 10, 2020
Merged
Changes from all commits
Commits
Show all changes
61 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 7a5cc6d
initial commit: MetricsEvaluator library
eric846 2090763
add class comment
eric846 c8dee61
fix format
eric846 b1e8ea8
fix comments
eric846 f0595f7
remove unused includes, try to fix strange clang-tidy-only compilatio…
eric846 6306b4e
Merge remote-tracking branch 'upstream/master' into master2
eric846 1ece783
Merge remote-tracking branch 'upstream/master' into master2
eric846 ee1bf99
Merge branch 'master2' into adaptive-rps-metric-evaluation
eric846 d61db72
fix clang-tidy
eric846 283965f
fix clang-tidy: move some includes to impl
eric846 ea9f562
change ExtractMetricSpecs output parameters to returned pair
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 f663975
rename unit tests, fix compile error
eric846 f367120
make ExtractMetricSpecs return const containers
eric846 93f42dc
Merge branch 'master2' into adaptive-rps-metric-evaluation
eric846 d2e502f
remove bazelrc
eric846 ed32856
Merge remote-tracking branch 'upstream/master' into master2
eric846 eecf00d
Merge remote-tracking branch 'upstream/master' into master2
eric846 788fa07
Merge branch 'master2' into adaptive-rps-metric-evaluation
eric846 34b81da
return vector of pairs from ExtractMetricSpecs
eric846 edc82db
improve comments
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
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,90 @@ | ||
| #include "envoy/config/core/v3/base.pb.h" | ||
|
|
||
| #include "nighthawk/adaptive_load/metrics_plugin.h" | ||
|
|
||
| #include "external/envoy/source/common/common/logger.h" | ||
| #include "external/envoy/source/common/common/statusor.h" | ||
| #include "external/envoy/source/common/protobuf/protobuf.h" | ||
|
|
||
| #include "api/adaptive_load/adaptive_load.pb.h" | ||
| #include "api/adaptive_load/benchmark_result.pb.h" | ||
| #include "api/adaptive_load/metric_spec.pb.h" | ||
| #include "api/client/options.pb.h" | ||
| #include "api/client/output.pb.h" | ||
| #include "api/client/service.pb.h" | ||
|
|
||
| #include "absl/container/flat_hash_map.h" | ||
| #include "absl/status/status.h" | ||
| #include "absl/strings/str_join.h" | ||
|
|
||
| namespace Nighthawk { | ||
|
|
||
| /** | ||
| * A utility for calling MetricsPlugins and scoring metrics according to ThresholdSpecs. | ||
| * | ||
| * AnalyzeNighthawkBenchmark() is intended to be called repeatedly from the adaptive load controller | ||
| * main loop after each Nighthawk Service call. The controller maintains a set of shared | ||
| * MetricsPlugins that are initialized once for the whole session. AnalyzeNighthawkBenchmark() calls | ||
| * EvaluateMetric() and ExtractMetricSpecs() internally. The AdaptiveLoadSessionSpec is consulted | ||
| * for MetricSpec, ThresholdSpec, and MetricsPlugin information. | ||
| */ | ||
| class MetricsEvaluator { | ||
| public: | ||
| virtual ~MetricsEvaluator() = default; | ||
|
|
||
| /** | ||
| * Calls a MetricPlugin to obtain the metric value defined by the MetricSpec, then scores the | ||
| * value according to a ThresholdSpec if one is present. | ||
| * | ||
| * @param metric_spec The MetricSpec identifying the metric by name and plugin name. | ||
| * @param metrics_plugin A MetricsPlugin that will be queried. The plugin must correspond to the | ||
| * plugin name in the MetricSpec, and it should support the requested metric name in the | ||
| * MetricSpec. | ||
| * @param threshold_spec A proto describing the threshold and scoring function. Nullptr if the | ||
| * metric is informational only. | ||
| * | ||
| * @return StatusOr<MetricEvaluation> A proto containing the metric value (and its score if a | ||
| * threshold was specified), or an error status if the metric could not be obtained from the | ||
| * MetricsPlugin. | ||
| */ | ||
| virtual absl::StatusOr<nighthawk::adaptive_load::MetricEvaluation> | ||
| EvaluateMetric(const nighthawk::adaptive_load::MetricSpec& metric_spec, | ||
| MetricsPlugin& metrics_plugin, | ||
| const nighthawk::adaptive_load::ThresholdSpec* threshold_spec) const PURE; | ||
|
|
||
| /** | ||
| * Extracts pointers to metric descriptors and corresponding thresholds from a top-level adaptive | ||
| * load session spec to an ordered list and a map. Allows for uniform treatment of scored and | ||
| * informational metrics. | ||
| * | ||
| * @param spec The adaptive load session spec. | ||
| * @return Vector of pairs of pointers to MetricSpec and ThresholdSpec within |spec|. For | ||
| * informational metrics, the ThresholdSpec pointer is nullptr. | ||
| */ | ||
| virtual const std::vector<std::pair<const nighthawk::adaptive_load::MetricSpec*, | ||
| const nighthawk::adaptive_load::ThresholdSpec*>> | ||
| ExtractMetricSpecs(const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec) const PURE; | ||
|
|
||
| /** | ||
| * Analyzes a Nighthawk Service benchmark against configured MetricThresholds. For each | ||
| * MetricSpec, queries a MetricsPlugin for the current metric value. Assumes that the values from | ||
| * MetricsPlugins correspond timewise with the Nighthawk benchmark. | ||
| * | ||
| * @param nighthawk_response Proto returned from Nighthawk Service describing the latest single | ||
| * benchmark session. To be translated into scorable metrics by the "nighthawk.builtin" | ||
| * MetricsPlugin. | ||
| * @param spec Top-level proto defining the adaptive load session. | ||
| * @param name_to_custom_metrics_plugin_map Map from plugin names to initialized MetricsPlugins. | ||
| * Must include all MetricsPlugins referenced in the spec other than "nighthawk.builtin". | ||
| * | ||
| * @return StatusOr<BenchmarkResult> A proto containing all metric scores for this Nighthawk | ||
| * Service benchmark session, or an error propagated from a MetricsPlugin. | ||
| */ | ||
| virtual absl::StatusOr<nighthawk::adaptive_load::BenchmarkResult> | ||
| AnalyzeNighthawkBenchmark(const nighthawk::client::ExecutionResponse& nighthawk_response, | ||
| const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec, | ||
| const absl::flat_hash_map<std::string, MetricsPluginPtr>& | ||
| name_to_custom_metrics_plugin_map) const 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,114 @@ | ||
| #include "adaptive_load/metrics_evaluator_impl.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "api/adaptive_load/metric_spec.pb.h" | ||
|
|
||
| #include "adaptive_load/metrics_plugin_impl.h" | ||
| #include "adaptive_load/plugin_loader.h" | ||
|
|
||
| namespace Nighthawk { | ||
|
|
||
| namespace { | ||
|
|
||
| using ::nighthawk::adaptive_load::MetricSpec; | ||
| using ::nighthawk::adaptive_load::MetricSpecWithThreshold; | ||
| using ::nighthawk::adaptive_load::ThresholdSpec; | ||
|
|
||
| } // namespace | ||
|
|
||
| absl::StatusOr<nighthawk::adaptive_load::MetricEvaluation> | ||
| MetricsEvaluatorImpl::EvaluateMetric(const MetricSpec& metric_spec, MetricsPlugin& metrics_plugin, | ||
| const ThresholdSpec* threshold_spec) const { | ||
| nighthawk::adaptive_load::MetricEvaluation evaluation; | ||
| evaluation.set_metric_id( | ||
| absl::StrCat(metric_spec.metrics_plugin_name(), "/", metric_spec.metric_name())); | ||
| const absl::StatusOr<double> metric_value_or = | ||
| metrics_plugin.GetMetricByName(metric_spec.metric_name()); | ||
| if (!metric_value_or.ok()) { | ||
| return absl::Status(static_cast<absl::StatusCode>(metric_value_or.status().code()), | ||
| absl::StrCat("Error calling MetricsPlugin '", | ||
| metric_spec.metrics_plugin_name(), ": ", | ||
| metric_value_or.status().message())); | ||
| } | ||
| const double metric_value = metric_value_or.value(); | ||
| evaluation.set_metric_value(metric_value); | ||
| if (threshold_spec == nullptr) { | ||
| // Informational metric. | ||
| evaluation.set_weight(0.0); | ||
| } else { | ||
| evaluation.set_weight(threshold_spec->weight().value()); | ||
| absl::StatusOr<ScoringFunctionPtr> scoring_function_or = | ||
| LoadScoringFunctionPlugin(threshold_spec->scoring_function()); | ||
| RELEASE_ASSERT(scoring_function_or.ok(), | ||
| absl::StrCat("ScoringFunction plugin loading error should have been caught " | ||
| "during input validation: ", | ||
| scoring_function_or.status().message())); | ||
| ScoringFunctionPtr scoring_function = std::move(scoring_function_or.value()); | ||
| evaluation.set_threshold_score(scoring_function->EvaluateMetric(metric_value)); | ||
| } | ||
| return evaluation; | ||
| } | ||
|
|
||
| const std::vector<std::pair<const MetricSpec*, const ThresholdSpec*>> | ||
| MetricsEvaluatorImpl::ExtractMetricSpecs( | ||
| const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec) const { | ||
| std::vector<std::pair<const MetricSpec*, const ThresholdSpec*>> spec_threshold_pairs; | ||
| for (const MetricSpecWithThreshold& metric_threshold : spec.metric_thresholds()) { | ||
| spec_threshold_pairs.emplace_back(&metric_threshold.metric_spec(), | ||
| &metric_threshold.threshold_spec()); | ||
| } | ||
| for (const MetricSpec& metric_spec : spec.informational_metric_specs()) { | ||
| spec_threshold_pairs.emplace_back(&metric_spec, nullptr); | ||
| } | ||
| return spec_threshold_pairs; | ||
| } | ||
|
|
||
| absl::StatusOr<nighthawk::adaptive_load::BenchmarkResult> | ||
| MetricsEvaluatorImpl::AnalyzeNighthawkBenchmark( | ||
| const nighthawk::client::ExecutionResponse& nighthawk_response, | ||
| const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec, | ||
| const absl::flat_hash_map<std::string, MetricsPluginPtr>& name_to_custom_metrics_plugin_map) | ||
| const { | ||
| if (nighthawk_response.error_detail().code() != static_cast<int>(absl::StatusCode::kOk)) { | ||
dubious90 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return absl::Status(static_cast<absl::StatusCode>(nighthawk_response.error_detail().code()), | ||
| nighthawk_response.error_detail().message()); | ||
| } | ||
|
|
||
| nighthawk::adaptive_load::BenchmarkResult benchmark_result; | ||
| *benchmark_result.mutable_nighthawk_service_output() = nighthawk_response.output(); | ||
|
|
||
| // A map containing all available MetricsPlugins: preloaded custom plugins shared across all | ||
| // benchmarks, and a freshly instantiated builtin plugin for this benchmark only. | ||
| absl::flat_hash_map<std::string, MetricsPlugin*> name_to_plugin_map; | ||
| for (const auto& name_plugin_pair : name_to_custom_metrics_plugin_map) { | ||
| name_to_plugin_map[name_plugin_pair.first] = name_plugin_pair.second.get(); | ||
| } | ||
| auto builtin_plugin = | ||
| std::make_unique<NighthawkStatsEmulatedMetricsPlugin>(nighthawk_response.output()); | ||
| name_to_plugin_map["nighthawk.builtin"] = builtin_plugin.get(); | ||
|
|
||
| const std::vector<std::pair<const MetricSpec*, const ThresholdSpec*>> spec_threshold_pairs = | ||
| ExtractMetricSpecs(spec); | ||
|
|
||
| std::vector<std::string> errors; | ||
| for (const std::pair<const MetricSpec*, const ThresholdSpec*>& spec_threshold_pair : | ||
| spec_threshold_pairs) { | ||
| absl::StatusOr<nighthawk::adaptive_load::MetricEvaluation> evaluation_or = | ||
| EvaluateMetric(*spec_threshold_pair.first, | ||
| *name_to_plugin_map[spec_threshold_pair.first->metrics_plugin_name()], | ||
| spec_threshold_pair.second); | ||
| if (!evaluation_or.ok()) { | ||
| errors.emplace_back(absl::StrCat("Error evaluating metric: ", evaluation_or.status().code(), | ||
| ": ", evaluation_or.status().message())); | ||
| continue; | ||
| } | ||
| *benchmark_result.mutable_metric_evaluations()->Add() = evaluation_or.value(); | ||
| } | ||
| if (!errors.empty()) { | ||
| return absl::InternalError(absl::StrJoin(errors, "\n")); | ||
| } | ||
| return benchmark_result; | ||
| } | ||
|
|
||
| } // 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,23 @@ | ||
| #include "nighthawk/adaptive_load/metrics_evaluator.h" | ||
|
|
||
| namespace Nighthawk { | ||
|
|
||
| class MetricsEvaluatorImpl : public MetricsEvaluator { | ||
| public: | ||
| absl::StatusOr<nighthawk::adaptive_load::MetricEvaluation> | ||
| EvaluateMetric(const nighthawk::adaptive_load::MetricSpec& metric_spec, | ||
| MetricsPlugin& metrics_plugin, | ||
| const nighthawk::adaptive_load::ThresholdSpec* threshold_spec) const override; | ||
|
|
||
| const std::vector<std::pair<const nighthawk::adaptive_load::MetricSpec*, | ||
| const nighthawk::adaptive_load::ThresholdSpec*>> | ||
| ExtractMetricSpecs(const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec) const override; | ||
|
|
||
| absl::StatusOr<nighthawk::adaptive_load::BenchmarkResult> | ||
| AnalyzeNighthawkBenchmark(const nighthawk::client::ExecutionResponse& nighthawk_response, | ||
| const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec, | ||
| const absl::flat_hash_map<std::string, MetricsPluginPtr>& | ||
| name_to_custom_metrics_plugin_map) const 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
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.