forked from envoyproxy/nighthawk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadaptive_load_controller_impl.h
83 lines (76 loc) · 4.21 KB
/
adaptive_load_controller_impl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "envoy/common/time.h"
#include "nighthawk/adaptive_load/adaptive_load_controller.h"
#include "nighthawk/adaptive_load/metrics_evaluator.h"
#include "nighthawk/adaptive_load/session_spec_proto_helper.h"
#include "nighthawk/adaptive_load/step_controller.h"
#include "nighthawk/common/nighthawk_service_client.h"
namespace Nighthawk {
class AdaptiveLoadControllerImpl : public AdaptiveLoadController {
public:
/**
* Constructs an implementation of the adaptive load controller main loop that relies on logic in
* several helper objects. Through helpers, it performs Nighthawk Service benchmarks, obtains
* metrics from MetricsPlugins, scores the results, and consults a StepController plugin to
* determine the next load and detect convergence. All plugins are specified through the
* AdaptiveLoadSessionSpec proto.
*
* This class is thread-safe, but Nighthawk Service itself does not support multiple simultaneous
* benchmarks.
*
* Usage:
*
* AdaptiveLoadControllerImpl controller(
* NighthawkServiceClientImpl(),
* MetricsEvaluatorImpl(),
* AdaptiveLoadSessionSpecProtoHelperImpl(),
* Envoy::Event::RealTimeSystem()); // NO_CHECK_FORMAT(real_time))
* AdaptiveLoadSessionSpec spec;
* // (set spec fields here)
* StatusOr<AdaptiveLoadSessionOutput> output =
* controller.PerformAdaptiveLoadSession(&nighthawk_service_stub, spec);
*
* @param nighthawk_service_client A helper that executes Nighthawk Service benchmarks given a
* gRPC stub.
* @param metrics_evaluator A helper that obtains metrics from MetricsPlugins and Nighthawk
* Service responses, then scores them.
* @param session_spec_proto_helper A helper that sets default values and performs validation in
* an AdaptiveLoadSessionSpec proto.
* @param time_source An abstraction of the system clock. Normally, just construct an
* Envoy::Event::RealTimeSystem and pass it. NO_CHECK_FORMAT(real_time). If calling from an
* Envoy-based process, there may be an existing TimeSource or TimeSystem to use. If calling
* from a test, pass a fake TimeSource.
*/
AdaptiveLoadControllerImpl(const NighthawkServiceClient& nighthawk_service_client,
const MetricsEvaluator& metrics_evaluator,
const AdaptiveLoadSessionSpecProtoHelper& session_spec_proto_helper,
Envoy::TimeSource& time_source);
absl::StatusOr<nighthawk::adaptive_load::AdaptiveLoadSessionOutput> PerformAdaptiveLoadSession(
nighthawk::client::NighthawkService::StubInterface* nighthawk_service_stub,
const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec) override;
private:
/**
* Gets the current load from the StepController, performs a benchmark via a Nighthawk Service,
* hands the result off for analysis, and reports the scores back to the StepController.
*
* @param nighthawk_service_stub Nighthawk Service gRPC stub.
* @param spec Proto describing the overall adaptive load session.
* @param name_to_custom_plugin_map Common map from plugin names to MetricsPlugins loaded and
* initialized once at the beginning of the session and passed to all calls of this function.
* @param step_controller The active StepController specified in the session spec proto.
* @param duration The duration of the benchmark to insert into the traffic template, different
* between adjusting and testing stages.
*
* @return BenchmarkResult Proto containing either an error status or raw Nighthawk Service
* results, metric values, and metric scores.
*/
absl::StatusOr<nighthawk::adaptive_load::BenchmarkResult> PerformAndAnalyzeNighthawkBenchmark(
nighthawk::client::NighthawkService::StubInterface* nighthawk_service_stub,
const nighthawk::adaptive_load::AdaptiveLoadSessionSpec& spec,
const absl::flat_hash_map<std::string, MetricsPluginPtr>& name_to_custom_plugin_map,
StepController& step_controller, Envoy::ProtobufWkt::Duration duration);
const NighthawkServiceClient& nighthawk_service_client_;
const MetricsEvaluator& metrics_evaluator_;
const AdaptiveLoadSessionSpecProtoHelper& session_spec_proto_helper_;
Envoy::TimeSource& time_source_;
};
} // namespace Nighthawk