Skip to content

Commit

Permalink
Convert overload manager config literals to YAML (#13518)
Browse files Browse the repository at this point in the history
YAML is better documented and more widely understood than textproto.

Signed-off-by: Alex Konradi <akonradi@google.com>
  • Loading branch information
akonradi authored Oct 13, 2020
1 parent 55fb16d commit 366fb79
Showing 1 changed file with 77 additions and 124 deletions.
201 changes: 77 additions & 124 deletions test/server/overload_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,60 +119,10 @@ class OverloadManagerImplTest : public testing::Test {

envoy::config::overload::v3::OverloadManager parseConfig(const std::string& config) {
envoy::config::overload::v3::OverloadManager proto;
bool success = Protobuf::TextFormat::ParseFromString(config, &proto);
ASSERT(success);
TestUtility::loadFromYaml(config, proto);
return proto;
}

std::string getConfig() {
return R"EOF(
refresh_interval {
seconds: 1
}
resource_monitors {
name: "envoy.resource_monitors.fake_resource1"
}
resource_monitors {
name: "envoy.resource_monitors.fake_resource2"
}
resource_monitors {
name: "envoy.resource_monitors.fake_resource3"
}
resource_monitors {
name: "envoy.resource_monitors.fake_resource4"
}
actions {
name: "envoy.overload_actions.dummy_action"
triggers {
name: "envoy.resource_monitors.fake_resource1"
threshold {
value: 0.9
}
}
triggers {
name: "envoy.resource_monitors.fake_resource2"
threshold {
value: 0.8
}
}
triggers {
name: "envoy.resource_monitors.fake_resource3"
scaled {
scaling_threshold: 0.5
saturation_threshold: 0.8
}
}
triggers {
name: "envoy.resource_monitors.fake_resource4"
scaled {
scaling_threshold: 0.5
saturation_threshold: 0.8
}
}
}
)EOF";
}

std::unique_ptr<OverloadManagerImpl> createOverloadManager(const std::string& config) {
return std::make_unique<OverloadManagerImpl>(dispatcher_, stats_, thread_local_,
parseConfig(config), validation_visitor_, *api_);
Expand All @@ -195,10 +145,37 @@ class OverloadManagerImplTest : public testing::Test {
Api::ApiPtr api_;
};

constexpr char kRegularStateConfig[] = R"YAML(
refresh_interval:
seconds: 1
resource_monitors:
- name: envoy.resource_monitors.fake_resource1
- name: envoy.resource_monitors.fake_resource2
- name: envoy.resource_monitors.fake_resource3
- name: envoy.resource_monitors.fake_resource4
actions:
- name: envoy.overload_actions.dummy_action
triggers:
- name: envoy.resource_monitors.fake_resource1
threshold:
value: 0.9
- name: envoy.resource_monitors.fake_resource2
threshold:
value: 0.8
- name: envoy.resource_monitors.fake_resource3
scaled:
scaling_threshold: 0.5
saturation_threshold: 0.8
- name: envoy.resource_monitors.fake_resource4
scaled:
scaling_threshold: 0.5
saturation_threshold: 0.8
)YAML";

TEST_F(OverloadManagerImplTest, CallbackOnlyFiresWhenStateChanges) {
setDispatcherExpectation();

auto manager(createOverloadManager(getConfig()));
auto manager(createOverloadManager(kRegularStateConfig));
bool is_active = false;
int cb_count = 0;
manager->registerForAction("envoy.overload_actions.dummy_action", dispatcher_,
Expand Down Expand Up @@ -306,7 +283,7 @@ TEST_F(OverloadManagerImplTest, CallbackOnlyFiresWhenStateChanges) {
TEST_F(OverloadManagerImplTest, ScaledTrigger) {
setDispatcherExpectation();

auto manager(createOverloadManager(getConfig()));
auto manager(createOverloadManager(kRegularStateConfig));
manager->start();
const auto& action_state =
manager->getThreadLocalOverloadState().getState("envoy.overload_actions.dummy_action");
Expand Down Expand Up @@ -350,7 +327,7 @@ TEST_F(OverloadManagerImplTest, ScaledTrigger) {

TEST_F(OverloadManagerImplTest, FailedUpdates) {
setDispatcherExpectation();
auto manager(createOverloadManager(getConfig()));
auto manager(createOverloadManager(kRegularStateConfig));
manager->start();
Stats::Counter& failed_updates =
stats_.counter("overload.envoy.resource_monitors.fake_resource1.failed_updates");
Expand All @@ -366,7 +343,7 @@ TEST_F(OverloadManagerImplTest, FailedUpdates) {

TEST_F(OverloadManagerImplTest, AggregatesMultipleResourceUpdates) {
setDispatcherExpectation();
auto manager(createOverloadManager(getConfig()));
auto manager(createOverloadManager(kRegularStateConfig));
manager->start();

const OverloadActionState& action_state =
Expand All @@ -388,7 +365,7 @@ TEST_F(OverloadManagerImplTest, AggregatesMultipleResourceUpdates) {

TEST_F(OverloadManagerImplTest, DelayedUpdatesAreCoalesced) {
setDispatcherExpectation();
auto manager(createOverloadManager(getConfig()));
auto manager(createOverloadManager(kRegularStateConfig));
manager->start();

const OverloadActionState& action_state =
Expand All @@ -412,7 +389,7 @@ TEST_F(OverloadManagerImplTest, DelayedUpdatesAreCoalesced) {

TEST_F(OverloadManagerImplTest, FlushesUpdatesEvenWithOneUnresponsive) {
setDispatcherExpectation();
auto manager(createOverloadManager(getConfig()));
auto manager(createOverloadManager(kRegularStateConfig));
manager->start();

const OverloadActionState& action_state =
Expand All @@ -436,7 +413,7 @@ TEST_F(OverloadManagerImplTest, FlushesUpdatesEvenWithOneUnresponsive) {
TEST_F(OverloadManagerImplTest, SkippedUpdates) {
setDispatcherExpectation();

auto manager(createOverloadManager(getConfig()));
auto manager(createOverloadManager(kRegularStateConfig));
manager->start();
Stats::Counter& skipped_updates =
stats_.counter("overload.envoy.resource_monitors.fake_resource1.skipped_updates");
Expand Down Expand Up @@ -466,12 +443,9 @@ TEST_F(OverloadManagerImplTest, SkippedUpdates) {

TEST_F(OverloadManagerImplTest, DuplicateResourceMonitor) {
const std::string config = R"EOF(
resource_monitors {
name: "envoy.resource_monitors.fake_resource1"
}
resource_monitors {
name: "envoy.resource_monitors.fake_resource1"
}
resource_monitors:
- name: "envoy.resource_monitors.fake_resource1"
- name: "envoy.resource_monitors.fake_resource1"
)EOF";

EXPECT_THROW_WITH_REGEX(createOverloadManager(config), EnvoyException,
Expand All @@ -480,12 +454,9 @@ TEST_F(OverloadManagerImplTest, DuplicateResourceMonitor) {

TEST_F(OverloadManagerImplTest, DuplicateOverloadAction) {
const std::string config = R"EOF(
actions {
name: "envoy.overload_actions.dummy_action"
}
actions {
name: "envoy.overload_actions.dummy_action"
}
actions:
- name: "envoy.overload_actions.dummy_action"
- name: "envoy.overload_actions.dummy_action"
)EOF";

EXPECT_THROW_WITH_REGEX(createOverloadManager(config), EnvoyException,
Expand All @@ -495,19 +466,15 @@ TEST_F(OverloadManagerImplTest, DuplicateOverloadAction) {
// A scaled trigger action's thresholds must conform to scaling < saturation.
TEST_F(OverloadManagerImplTest, ScaledTriggerSaturationLessThanScalingThreshold) {
const std::string config = R"EOF(
resource_monitors {
name: "envoy.resource_monitors.fake_resource1"
}
actions {
name: "envoy.overload_actions.dummy_action"
triggers {
name: "envoy.resource_monitors.fake_resource1"
scaled {
scaling_threshold: 0.9
saturation_threshold: 0.8
}
}
}
resource_monitors:
- name: "envoy.resource_monitors.fake_resource1"
actions:
- name: "envoy.overload_actions.dummy_action"
triggers:
- name: "envoy.resource_monitors.fake_resource1"
scaled:
scaling_threshold: 0.9
saturation_threshold: 0.8
)EOF";

EXPECT_THROW_WITH_REGEX(createOverloadManager(config), EnvoyException,
Expand All @@ -517,19 +484,15 @@ TEST_F(OverloadManagerImplTest, ScaledTriggerSaturationLessThanScalingThreshold)
// A scaled trigger action can't have threshold values that are equal.
TEST_F(OverloadManagerImplTest, ScaledTriggerThresholdsEqual) {
const std::string config = R"EOF(
resource_monitors {
name: "envoy.resource_monitors.fake_resource1"
}
actions {
name: "envoy.overload_actions.dummy_action"
triggers {
name: "envoy.resource_monitors.fake_resource1"
scaled {
scaling_threshold: 0.9
saturation_threshold: 0.9
}
}
}
resource_monitors:
- name: "envoy.resource_monitors.fake_resource1"
actions:
- name: "envoy.overload_actions.dummy_action"
triggers:
- name: "envoy.resource_monitors.fake_resource1"
scaled:
scaling_threshold: 0.9
saturation_threshold: 0.9
)EOF";

EXPECT_THROW_WITH_REGEX(createOverloadManager(config), EnvoyException,
Expand All @@ -538,15 +501,12 @@ TEST_F(OverloadManagerImplTest, ScaledTriggerThresholdsEqual) {

TEST_F(OverloadManagerImplTest, UnknownTrigger) {
const std::string config = R"EOF(
actions {
name: "envoy.overload_actions.dummy_action"
triggers {
name: "envoy.resource_monitors.fake_resource1"
threshold {
value: 0.9
}
}
}
actions:
- name: "envoy.overload_actions.dummy_action"
triggers:
- name: "envoy.resource_monitors.fake_resource1"
threshold:
value: 0.9
)EOF";

EXPECT_THROW_WITH_REGEX(createOverloadManager(config), EnvoyException,
Expand All @@ -555,24 +515,17 @@ TEST_F(OverloadManagerImplTest, UnknownTrigger) {

TEST_F(OverloadManagerImplTest, DuplicateTrigger) {
const std::string config = R"EOF(
resource_monitors {
name: "envoy.resource_monitors.fake_resource1"
}
actions {
name: "envoy.overload_actions.dummy_action"
triggers {
name: "envoy.resource_monitors.fake_resource1"
threshold {
value: 0.9
}
}
triggers {
name: "envoy.resource_monitors.fake_resource1"
threshold {
value: 0.8
}
}
}
resource_monitors:
- name: "envoy.resource_monitors.fake_resource1"
actions:
- name: "envoy.overload_actions.dummy_action"
triggers:
- name: "envoy.resource_monitors.fake_resource1"
threshold:
value: 0.9
- name: "envoy.resource_monitors.fake_resource1"
threshold:
value: 0.8
)EOF";

EXPECT_THROW_WITH_REGEX(createOverloadManager(config), EnvoyException, "Duplicate trigger .*");
Expand All @@ -581,7 +534,7 @@ TEST_F(OverloadManagerImplTest, DuplicateTrigger) {
TEST_F(OverloadManagerImplTest, Shutdown) {
setDispatcherExpectation();

auto manager(createOverloadManager(getConfig()));
auto manager(createOverloadManager(kRegularStateConfig));
manager->start();

EXPECT_CALL(*timer_, disableTimer());
Expand Down

0 comments on commit 366fb79

Please sign in to comment.