Skip to content
Merged
Show file tree
Hide file tree
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 Jun 1, 2020
5ac755a
Merge pull request #6 from envoyproxy/master
eric846 Jun 28, 2020
b8c25a5
Merge pull request #7 from envoyproxy/master
eric846 Jul 7, 2020
1c19c68
initial commit
eric846 Jul 9, 2020
7050686
fix comments
eric846 Jul 9, 2020
0776563
fix format
eric846 Jul 9, 2020
16fd8f6
rename adaptive_rps to adaptive_load
eric846 Jul 10, 2020
c383010
add field_selector in example
eric846 Jul 10, 2020
6e1a483
fix example comment
eric846 Jul 10, 2020
4ef1140
fix format
eric846 Jul 10, 2020
4111bf4
add support for fault injection headers
eric846 Jul 10, 2020
871a959
replace linear and binary search with exponential search
eric846 Jul 10, 2020
1fd77c1
add InputVariableSetter mechanism
eric846 Jul 11, 2020
edc36b2
add input variable setter to build file
eric846 Jul 11, 2020
4d0364e
fix syntax errors
eric846 Jul 11, 2020
aed6d94
rename samples/adaptive_rps
eric846 Jul 11, 2020
d9ae87d
improve comments, change step controller initial value from int64 to …
eric846 Jul 12, 2020
a05a6f5
add proto validation rules, fix comments, make rps the default input_…
eric846 Jul 13, 2020
8cd4d21
fix comment wording
eric846 Jul 13, 2020
d814a96
simplify protos, add defaults, specify required or optional
eric846 Jul 14, 2020
5f5a885
add missing newline
eric846 Jul 14, 2020
7e20a78
Kick CI
eric846 Jul 14, 2020
9048267
simplify protos
eric846 Jul 15, 2020
306c0ec
fix format
eric846 Jul 15, 2020
d33f543
fix some optional field comments and rules
eric846 Jul 15, 2020
442cca9
Merge pull request #10 from envoyproxy/master
eric846 Jul 16, 2020
677b783
add Nighthawk status field in BenchmarkResult as nested nighthawk.cli…
eric846 Jul 19, 2020
cefb366
switch to standard Envoy plugin config proto, add prefix to internal …
eric846 Jul 22, 2020
f3684df
Merge remote-tracking branch 'upstream/master' into adaptive-rps-protos2
eric846 Jul 22, 2020
5463051
create headers
eric846 Jul 22, 2020
46e0e25
fix format
eric846 Jul 22, 2020
f634642
use docstring format
eric846 Jul 22, 2020
3c39faa
fix typos in comments
eric846 Jul 23, 2020
b9c8f2b
split build target, get rid of ostream, change InputValueSetter to us…
eric846 Jul 24, 2020
5fc4db4
remove nested namespace, remove redundant _include in target names
eric846 Jul 26, 2020
64e7852
merge from upstream
eric846 Jul 29, 2020
12807f1
Merge remote-tracking branch 'upstream/master' into adaptive-rps-headers
eric846 Jul 29, 2020
e8e960f
merge from upstream
eric846 Aug 27, 2020
7a5cc6d
initial commit: MetricsEvaluator library
eric846 Aug 27, 2020
2090763
add class comment
eric846 Aug 27, 2020
c8dee61
fix format
eric846 Aug 27, 2020
b1e8ea8
fix comments
eric846 Aug 27, 2020
f0595f7
remove unused includes, try to fix strange clang-tidy-only compilatio…
eric846 Aug 27, 2020
6306b4e
Merge remote-tracking branch 'upstream/master' into master2
eric846 Aug 27, 2020
1ece783
Merge remote-tracking branch 'upstream/master' into master2
eric846 Aug 28, 2020
ee1bf99
Merge branch 'master2' into adaptive-rps-metric-evaluation
eric846 Aug 28, 2020
d61db72
fix clang-tidy
eric846 Aug 28, 2020
283965f
fix clang-tidy: move some includes to impl
eric846 Aug 28, 2020
ea9f562
change ExtractMetricSpecs output parameters to returned pair
eric846 Aug 29, 2020
70705e9
Merge remote-tracking branch 'upstream/master' into master2
eric846 Aug 31, 2020
e576bc1
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 1, 2020
1fca528
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 3, 2020
f663975
rename unit tests, fix compile error
eric846 Sep 3, 2020
f367120
make ExtractMetricSpecs return const containers
eric846 Sep 3, 2020
93f42dc
Merge branch 'master2' into adaptive-rps-metric-evaluation
eric846 Sep 3, 2020
d2e502f
remove bazelrc
eric846 Sep 3, 2020
ed32856
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 3, 2020
eecf00d
Merge remote-tracking branch 'upstream/master' into master2
eric846 Sep 8, 2020
788fa07
Merge branch 'master2' into adaptive-rps-metric-evaluation
eric846 Sep 8, 2020
34b81da
return vector of pairs from ExtractMetricSpecs
eric846 Sep 8, 2020
edc82db
improve comments
eric846 Sep 9, 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
15 changes: 15 additions & 0 deletions include/nighthawk/adaptive_load/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ envoy_basic_cc_library(
],
)

envoy_basic_cc_library(
name = "metrics_evaluator",
hdrs = [
"metrics_evaluator.h",
],
include_prefix = "nighthawk/adaptive_load",
deps = [
":metrics_plugin",
"//api/adaptive_load:adaptive_load_proto_cc_proto",
"@envoy//include/envoy/common:base_includes",
"@envoy//include/envoy/config:typed_config_interface",
"@envoy//source/common/common:statusor_lib_with_external_headers",
],
)

envoy_basic_cc_library(
name = "metrics_plugin",
hdrs = [
Expand Down
90 changes: 90 additions & 0 deletions include/nighthawk/adaptive_load/metrics_evaluator.h
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
21 changes: 21 additions & 0 deletions source/adaptive_load/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "metrics_evaluator_impl",
srcs = [
"metrics_evaluator_impl.cc",
],
hdrs = [
"metrics_evaluator_impl.h",
],
repository = "@envoy",
visibility = ["//visibility:public"],
deps = [
":metrics_plugin_impl",
":plugin_loader",
"//api/adaptive_load:adaptive_load_proto_cc_proto",
"//api/client:base_cc_proto",
"//include/nighthawk/adaptive_load:adaptive_load_controller",
"//include/nighthawk/adaptive_load:metrics_evaluator",
"//include/nighthawk/adaptive_load:scoring_function",
],
)

envoy_cc_library(
name = "metrics_plugin_impl",
srcs = [
Expand Down
114 changes: 114 additions & 0 deletions source/adaptive_load/metrics_evaluator_impl.cc
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)) {
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
23 changes: 23 additions & 0 deletions source/adaptive_load/metrics_evaluator_impl.h
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
12 changes: 12 additions & 0 deletions test/adaptive_load/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ envoy_cc_test(
],
)

envoy_cc_test(
name = "metrics_evaluator_test",
srcs = ["metrics_evaluator_test.cc"],
repository = "@envoy",
deps = [
":minimal_output",
"//source/adaptive_load:metrics_evaluator_impl",
"//source/adaptive_load:scoring_function_impl",
"//test/adaptive_load/fake_plugins/fake_metrics_plugin",
],
)

envoy_cc_test(
name = "metrics_plugin_test",
srcs = ["metrics_plugin_test.cc"],
Expand Down
Loading