This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
circuit_breakers_integration_test.cc
199 lines (148 loc) · 8.62 KB
/
circuit_breakers_integration_test.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "test/integration/http_protocol_integration.h"
namespace Envoy {
namespace {
class CircuitBreakersIntegrationTest : public HttpProtocolIntegrationTest {
public:
void initialize() override { HttpProtocolIntegrationTest::initialize(); }
};
// TODO(#26236): Fix test suite for HTTP/3.
INSTANTIATE_TEST_SUITE_P(
Protocols, CircuitBreakersIntegrationTest,
testing::ValuesIn(HttpProtocolIntegrationTest::getProtocolTestParamsWithoutHTTP3()),
HttpProtocolIntegrationTest::protocolTestParamsToString);
// This test checks that triggered max requests circuit breaker
// doesn't force outlier detectors to eject an upstream host.
// See https://github.com/envoyproxy/envoy/issues/25487
TEST_P(CircuitBreakersIntegrationTest, CircuitBreakersWithOutlierDetection) {
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
auto* static_resources = bootstrap.mutable_static_resources();
auto* cluster = static_resources->mutable_clusters(0);
// Somewhat contrived with 0, but this is the simplest way to test right now.
auto* circuit_breakers = cluster->mutable_circuit_breakers();
circuit_breakers->add_thresholds()->mutable_max_requests()->set_value(0);
auto* outlier_detection = cluster->mutable_outlier_detection();
outlier_detection->mutable_consecutive_gateway_failure()->set_value(1);
outlier_detection->mutable_consecutive_5xx()->set_value(1);
outlier_detection->mutable_consecutive_local_origin_failure()->set_value(1);
outlier_detection->mutable_enforcing_consecutive_gateway_failure()->set_value(100);
outlier_detection->mutable_enforcing_consecutive_5xx()->set_value(100);
outlier_detection->mutable_enforcing_consecutive_local_origin_failure()->set_value(100);
outlier_detection->set_split_external_local_origin_errors(true);
outlier_detection->mutable_max_ejection_percent()->set_value(100);
outlier_detection->mutable_interval()->set_nanos(1);
outlier_detection->mutable_base_ejection_time()->set_seconds(3600);
outlier_detection->mutable_max_ejection_time()->set_seconds(3600);
});
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeRequestWithBody(default_request_headers_, 1024);
test_server_->waitForGaugeEq("cluster.cluster_0.upstream_rq_active", 0);
test_server_->waitForGaugeEq("cluster.cluster_0.upstream_rq_pending_active", 0);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_EQ("503", response->headers().getStatusValue());
test_server_->waitForCounterGe("cluster.cluster_0.upstream_rq_503", 1);
EXPECT_EQ(test_server_->counter("cluster.cluster_0.upstream_rq_pending_overflow")->value(), 1);
EXPECT_EQ(test_server_->counter("cluster.cluster_0.outlier_detection.ejections_enforced_total")
->value(),
0);
}
TEST_P(CircuitBreakersIntegrationTest, CircuitBreakerRuntime) {
config_helper_.addRuntimeOverride("circuit_breakers.cluster_0.default.max_requests", "0");
config_helper_.addRuntimeOverride("circuit_breakers.cluster_0.default.max_retries", "1024");
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
auto* static_resources = bootstrap.mutable_static_resources();
auto* cluster = static_resources->mutable_clusters(0);
auto* outlier_detection = cluster->mutable_outlier_detection();
outlier_detection->mutable_consecutive_gateway_failure()->set_value(1);
outlier_detection->mutable_consecutive_5xx()->set_value(1);
outlier_detection->mutable_consecutive_local_origin_failure()->set_value(1);
outlier_detection->mutable_enforcing_consecutive_gateway_failure()->set_value(100);
outlier_detection->mutable_enforcing_consecutive_5xx()->set_value(100);
outlier_detection->mutable_enforcing_consecutive_local_origin_failure()->set_value(100);
outlier_detection->set_split_external_local_origin_errors(true);
outlier_detection->mutable_max_ejection_percent()->set_value(100);
outlier_detection->mutable_interval()->set_nanos(1);
outlier_detection->mutable_base_ejection_time()->set_seconds(3600);
outlier_detection->mutable_max_ejection_time()->set_seconds(3600);
});
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeRequestWithBody(default_request_headers_, 1024);
test_server_->waitForGaugeEq("cluster.cluster_0.upstream_rq_active", 0);
test_server_->waitForGaugeEq("cluster.cluster_0.upstream_rq_pending_active", 0);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_EQ("503", response->headers().getStatusValue());
test_server_->waitForCounterGe("cluster.cluster_0.upstream_rq_503", 1);
EXPECT_EQ(test_server_->counter("cluster.cluster_0.upstream_rq_pending_overflow")->value(), 1);
EXPECT_EQ(test_server_->counter("cluster.cluster_0.outlier_detection.ejections_enforced_total")
->value(),
0);
#ifdef ENVOY_ADMIN_FUNCTIONALITY
auto codec_client2 = makeHttpConnection(lookupPort("admin"));
default_request_headers_.setPath("/runtime");
response = codec_client2->makeHeaderOnlyRequest(default_request_headers_);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_EQ("200", response->headers().getStatusValue());
codec_client2->close();
const std::string expected_json1 = R"EOF(
"circuit_breakers.cluster_0.default.max_retries": {
)EOF";
EXPECT_TRUE(absl::StrContains(response->body(), expected_json1)) << response->body();
const std::string expected_json2 = R"EOF("final_value": "1024")EOF";
EXPECT_TRUE(absl::StrContains(response->body(), expected_json2)) << response->body();
#endif
}
TEST_P(CircuitBreakersIntegrationTest, CircuitBreakerRuntimeProto) {
config_helper_.addConfigModifier([](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
auto* static_resources = bootstrap.mutable_static_resources();
auto* cluster = static_resources->mutable_clusters(0);
auto* outlier_detection = cluster->mutable_outlier_detection();
outlier_detection->mutable_consecutive_gateway_failure()->set_value(1);
outlier_detection->mutable_consecutive_5xx()->set_value(1);
outlier_detection->mutable_consecutive_local_origin_failure()->set_value(1);
outlier_detection->mutable_enforcing_consecutive_gateway_failure()->set_value(100);
outlier_detection->mutable_enforcing_consecutive_5xx()->set_value(100);
outlier_detection->mutable_enforcing_consecutive_local_origin_failure()->set_value(100);
outlier_detection->set_split_external_local_origin_errors(true);
outlier_detection->mutable_max_ejection_percent()->set_value(100);
outlier_detection->mutable_interval()->set_nanos(1);
outlier_detection->mutable_base_ejection_time()->set_seconds(3600);
outlier_detection->mutable_max_ejection_time()->set_seconds(3600);
auto* layer = bootstrap.mutable_layered_runtime()->add_layers();
layer->set_name("enable layer");
ProtobufWkt::Struct& runtime = *layer->mutable_static_layer();
(*runtime.mutable_fields())["circuit_breakers.cluster_0.default.max_requests"].set_number_value(
0);
(*runtime.mutable_fields())["circuit_breakers.cluster_0.default.max_retries"].set_number_value(
1024);
});
initialize();
codec_client_ = makeHttpConnection(lookupPort("http"));
auto response = codec_client_->makeRequestWithBody(default_request_headers_, 1024);
test_server_->waitForGaugeEq("cluster.cluster_0.upstream_rq_active", 0);
test_server_->waitForGaugeEq("cluster.cluster_0.upstream_rq_pending_active", 0);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_EQ("503", response->headers().getStatusValue());
test_server_->waitForCounterGe("cluster.cluster_0.upstream_rq_503", 1);
EXPECT_EQ(test_server_->counter("cluster.cluster_0.upstream_rq_pending_overflow")->value(), 1);
EXPECT_EQ(test_server_->counter("cluster.cluster_0.outlier_detection.ejections_enforced_total")
->value(),
0);
#ifdef ENVOY_ADMIN_FUNCTIONALITY
auto codec_client2 = makeHttpConnection(lookupPort("admin"));
default_request_headers_.setPath("/runtime");
response = codec_client2->makeHeaderOnlyRequest(default_request_headers_);
ASSERT_TRUE(response->waitForEndStream());
EXPECT_EQ("200", response->headers().getStatusValue());
codec_client2->close();
const std::string expected_json1 = R"EOF(
"circuit_breakers.cluster_0.default.max_retries": {
)EOF";
EXPECT_TRUE(absl::StrContains(response->body(), expected_json1)) << response->body();
const std::string expected_json2 = R"EOF("final_value": "1024")EOF";
EXPECT_TRUE(absl::StrContains(response->body(), expected_json2)) << response->body();
#endif
}
} // namespace
} // namespace Envoy