forked from envoyproxy/nighthawk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_variable_setter_impl.cc
48 lines (37 loc) · 1.84 KB
/
input_variable_setter_impl.cc
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
#include "source/adaptive_load/input_variable_setter_impl.h"
#include <limits>
#include "external/envoy/source/common/protobuf/protobuf.h"
namespace Nighthawk {
RequestsPerSecondInputVariableSetter::RequestsPerSecondInputVariableSetter(
const nighthawk::adaptive_load::RequestsPerSecondInputVariableSetterConfig&) {}
absl::Status RequestsPerSecondInputVariableSetter::SetInputVariable(
nighthawk::client::CommandLineOptions& command_line_options, double input_value) {
if (input_value < 0.0 || input_value > std::numeric_limits<uint32_t>::max()) {
return absl::InternalError(
absl::StrCat("Input value out of range for uint32 requests_per_second: ", input_value));
}
command_line_options.mutable_requests_per_second()->set_value(
static_cast<unsigned int>(input_value));
return absl::OkStatus();
}
std::string RequestsPerSecondInputVariableSetterConfigFactory::name() const {
return "nighthawk.rps";
}
Envoy::ProtobufTypes::MessagePtr
RequestsPerSecondInputVariableSetterConfigFactory::createEmptyConfigProto() {
return std::make_unique<nighthawk::adaptive_load::RequestsPerSecondInputVariableSetterConfig>();
}
InputVariableSetterPtr RequestsPerSecondInputVariableSetterConfigFactory::createInputVariableSetter(
const Envoy::Protobuf::Message& message) {
const auto& any = dynamic_cast<const Envoy::ProtobufWkt::Any&>(message);
nighthawk::adaptive_load::RequestsPerSecondInputVariableSetterConfig config;
Envoy::MessageUtil::unpackTo(any, config);
return std::make_unique<RequestsPerSecondInputVariableSetter>(config);
}
absl::Status RequestsPerSecondInputVariableSetterConfigFactory::ValidateConfig(
const Envoy::Protobuf::Message&) const {
return absl::OkStatus();
}
REGISTER_FACTORY(RequestsPerSecondInputVariableSetterConfigFactory,
InputVariableSetterConfigFactory);
} // namespace Nighthawk