forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ads_integration_test.cc
2757 lines (2347 loc) · 143 KB
/
ads_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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "envoy/config/cluster/v3/cluster.pb.h"
#include "envoy/config/core/v3/base.pb.h"
#include "envoy/config/endpoint/v3/endpoint.pb.h"
#include "envoy/config/listener/v3/listener.pb.h"
#include "envoy/config/route/v3/route.pb.h"
#include "envoy/grpc/status.h"
#include "source/common/config/protobuf_link_hacks.h"
#include "source/common/protobuf/protobuf.h"
#include "source/common/protobuf/utility.h"
#include "source/common/version/version.h"
#include "test/common/grpc/grpc_client_integration.h"
#include "test/config/v2_link_hacks.h"
#include "test/integration/ads_integration.h"
#include "test/integration/http_integration.h"
#include "test/integration/utility.h"
#include "test/test_common/network_utility.h"
#include "test/test_common/resources.h"
#include "test/test_common/utility.h"
#include "gtest/gtest.h"
using testing::AssertionResult;
namespace Envoy {
INSTANTIATE_TEST_SUITE_P(IpVersionsClientTypeDeltaWildcard, AdsIntegrationTest,
ADS_INTEGRATION_PARAMS);
// Validate basic config delivery and upgrade.
TEST_P(AdsIntegrationTest, Basic) {
initialize();
testBasicFlow();
}
// Basic CDS/EDS update that warms and makes active a single cluster.
TEST_P(AdsIntegrationTest, BasicClusterInitialWarming) {
initialize();
const auto cds_type_url = Config::getTypeUrl<envoy::config::cluster::v3::Cluster>();
const auto eds_type_url =
Config::getTypeUrl<envoy::config::endpoint::v3::ClusterLoadAssignment>();
EXPECT_TRUE(compareDiscoveryRequest(cds_type_url, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
cds_type_url, {buildCluster("cluster_0")}, {buildCluster("cluster_0")}, {}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 1);
EXPECT_TRUE(compareDiscoveryRequest(eds_type_url, "", {"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
eds_type_url, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
test_server_->waitForGaugeGe("cluster_manager.active_clusters", 2);
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 0);
}
// Basic CDS/EDS update that warms and makes active a single cluster.
TEST_P(AdsIntegrationTest, BasicClusterInitialWarmingWithResourceWrapper) {
initialize();
const auto cds_type_url = Config::getTypeUrl<envoy::config::cluster::v3::Cluster>();
const auto eds_type_url =
Config::getTypeUrl<envoy::config::endpoint::v3::ClusterLoadAssignment>();
EXPECT_TRUE(compareDiscoveryRequest(cds_type_url, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
cds_type_url, {buildCluster("cluster_0")}, {buildCluster("cluster_0")}, {}, "1",
{{"test", ProtobufWkt::Any()}});
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 1);
EXPECT_TRUE(compareDiscoveryRequest(eds_type_url, "", {"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
eds_type_url, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1", {{"test", ProtobufWkt::Any()}});
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
test_server_->waitForGaugeGe("cluster_manager.active_clusters", 2);
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 0);
}
// Tests that the Envoy xDS client can handle updates to a subset of the subscribed resources from
// an xDS server without removing the resources not included in the DiscoveryResponse from the xDS
// server.
TEST_P(AdsIntegrationTest, UpdateToSubsetOfResources) {
initialize();
registerTestServerPorts({});
const auto cds_type_url = Config::getTypeUrl<envoy::config::cluster::v3::Cluster>();
const auto eds_type_url =
Config::getTypeUrl<envoy::config::endpoint::v3::ClusterLoadAssignment>();
auto cluster_0 = buildCluster("cluster_0");
auto cluster_1 = buildCluster("cluster_1");
EXPECT_TRUE(compareDiscoveryRequest(cds_type_url, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(cds_type_url, {cluster_0, cluster_1},
{cluster_0, cluster_1}, {}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 2);
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 1);
test_server_->waitForGaugeEq("cluster.cluster_1.warming_state", 1);
EXPECT_TRUE(compareDiscoveryRequest(eds_type_url, "", {cluster_0.name(), cluster_1.name()},
{cluster_0.name(), cluster_1.name()}, {}));
auto cla_0 = buildClusterLoadAssignment(cluster_0.name());
auto cla_1 = buildClusterLoadAssignment(cluster_1.name());
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
eds_type_url, {cla_0, cla_1}, {cla_0, cla_1}, {}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
test_server_->waitForGaugeGe("cluster_manager.active_clusters", 4);
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 0);
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 0);
// Send an update for one of the ClusterLoadAssignments only.
cla_0.mutable_endpoints(0)->mutable_lb_endpoints(0)->mutable_load_balancing_weight()->set_value(
2);
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(eds_type_url, {cla_0},
{cla_0}, {}, "2");
// Verify that getting an update for only one of the ClusterLoadAssignment resources does not
// delete the other. We use cluster membership health as a proxy for this.
test_server_->waitForCounterEq("cluster.cluster_0.update_success", 2);
test_server_->waitForCounterEq("cluster.cluster_1.update_success", 1);
test_server_->waitForGaugeEq("cluster.cluster_0.membership_healthy", 1);
test_server_->waitForGaugeEq("cluster.cluster_1.membership_healthy", 1);
}
// Update the only warming cluster. Verify that the new cluster is still warming and the cluster
// manager as a whole is not initialized.
TEST_P(AdsIntegrationTest, ClusterInitializationUpdateTheOnlyWarmingCluster) {
initialize();
const auto cds_type_url = Config::getTypeUrl<envoy::config::cluster::v3::Cluster>();
const auto eds_type_url =
Config::getTypeUrl<envoy::config::endpoint::v3::ClusterLoadAssignment>();
EXPECT_TRUE(compareDiscoveryRequest(cds_type_url, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
cds_type_url, {buildCluster("cluster_0")}, {buildCluster("cluster_0")}, {}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
// Update lb policy to MAGLEV so that cluster update is not skipped due to the same hash.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
cds_type_url, {buildCluster("cluster_0", envoy::config::cluster::v3::Cluster::MAGLEV)},
{buildCluster("cluster_0", envoy::config::cluster::v3::Cluster::MAGLEV)}, {}, "2");
EXPECT_TRUE(compareDiscoveryRequest(eds_type_url, "", {"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
eds_type_url, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
test_server_->waitForGaugeGe("cluster_manager.active_clusters", 2);
}
// Primary cluster is warming during cluster initialization. Update the cluster with immediate ready
// config and verify that all the clusters are initialized.
TEST_P(AdsIntegrationTest, TestPrimaryClusterWarmClusterInitialization) {
initialize();
const auto cds_type_url = Config::getTypeUrl<envoy::config::cluster::v3::Cluster>();
auto loopback = Network::Test::getLoopbackAddressString(ipVersion());
addFakeUpstream(Http::CodecType::HTTP2);
auto port = fake_upstreams_.back()->localAddress()->ip()->port();
// This cluster will be blocked since endpoint name cannot be resolved.
auto warming_cluster = ConfigHelper::buildStaticCluster("fake_cluster", port, loopback);
// Below endpoint accepts request but never return. The health check hangs 1 hour which covers the
// test running.
auto blocking_health_check = TestUtility::parseYaml<envoy::config::core::v3::HealthCheck>(R"EOF(
timeout: 3600s
interval: 3600s
unhealthy_threshold: 2
healthy_threshold: 2
tcp_health_check:
send:
text: '01'
receive:
- text: '02'
)EOF");
*warming_cluster.add_health_checks() = blocking_health_check;
// Active cluster has the same name with warming cluster but has no blocking health check.
auto active_cluster = ConfigHelper::buildStaticCluster("fake_cluster", port, loopback);
EXPECT_TRUE(compareDiscoveryRequest(cds_type_url, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(cds_type_url, {warming_cluster},
{warming_cluster}, {}, "1");
FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_.back()->waitForRawConnection(fake_upstream_connection));
// fake_cluster is in warming.
test_server_->waitForGaugeGe("cluster_manager.warming_clusters", 1);
// Now replace the warming cluster by the config which will turn ready immediately.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(cds_type_url, {active_cluster},
{active_cluster}, {}, "2");
// All clusters are ready.
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
test_server_->waitForGaugeGe("cluster_manager.active_clusters", 2);
}
// Two cluster warming, update one of them. Verify that the clusters are eventually initialized.
TEST_P(AdsIntegrationTest, ClusterInitializationUpdateOneOfThe2Warming) {
initialize();
const auto cds_type_url = Config::getTypeUrl<envoy::config::cluster::v3::Cluster>();
const auto eds_type_url =
Config::getTypeUrl<envoy::config::endpoint::v3::ClusterLoadAssignment>();
EXPECT_TRUE(compareDiscoveryRequest(cds_type_url, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
cds_type_url,
{ConfigHelper::buildStaticCluster("primary_cluster", 8000, "127.0.0.1"),
buildCluster("cluster_0"), buildCluster("cluster_1")},
{ConfigHelper::buildStaticCluster("primary_cluster", 8000, "127.0.0.1"),
buildCluster("cluster_0"), buildCluster("cluster_1")},
{}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 2);
// Update lb policy to MAGLEV so that cluster update is not skipped due to the same hash.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
cds_type_url,
{ConfigHelper::buildStaticCluster("primary_cluster", 8000, "127.0.0.1"),
buildCluster("cluster_0", envoy::config::cluster::v3::Cluster::MAGLEV),
buildCluster("cluster_1")},
{ConfigHelper::buildStaticCluster("primary_cluster", 8000, "127.0.0.1"),
buildCluster("cluster_0", envoy::config::cluster::v3::Cluster::MAGLEV),
buildCluster("cluster_1")},
{}, "2");
EXPECT_TRUE(compareDiscoveryRequest(eds_type_url, "", {"cluster_0", "cluster_1"},
{"cluster_0", "cluster_1"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
eds_type_url,
{buildClusterLoadAssignment("cluster_0"), buildClusterLoadAssignment("cluster_1")},
{buildClusterLoadAssignment("cluster_0"), buildClusterLoadAssignment("cluster_1")}, {}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
test_server_->waitForGaugeGe("cluster_manager.active_clusters", 4);
}
// Verify that Delta SDS Removals don't result in a NACK.
TEST_P(AdsIntegrationTest, DeltaSdsRemovals) {
// SOTW delivery doesn't track individual resources, so only
// run this test for delta xDS.
if (sotw_or_delta_ != Grpc::SotwOrDelta::Delta &&
sotw_or_delta_ != Grpc::SotwOrDelta::UnifiedDelta) {
GTEST_SKIP_("This test is for delta only");
}
initialize();
const auto cds_type_url = Config::getTypeUrl<envoy::config::cluster::v3::Cluster>();
const auto sds_type_url =
Config::getTypeUrl<envoy::extensions::transport_sockets::tls::v3::Secret>();
const auto lds_type_url = Config::getTypeUrl<envoy::config::listener::v3::Listener>();
// First get the cluster sent to the test proxy
envoy::config::core::v3::TransportSocket sds_transport_socket;
TestUtility::loadFromYaml(R"EOF(
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
validation_context_sds_secret_config:
name: validation_context
sds_config:
initial_fetch_timeout: 5s
ads: {}
)EOF",
sds_transport_socket);
auto cluster = ConfigHelper::buildStaticCluster("cluster", 8000, "127.0.0.1");
*cluster.mutable_transport_socket() = sds_transport_socket;
cluster.set_name("cluster_0");
// Initial * Delta ADS subscription.
EXPECT_TRUE(compareDeltaDiscoveryRequest(cds_type_url, {}, {}));
sendDeltaDiscoveryResponse<envoy::config::cluster::v3::Cluster>(cds_type_url, {cluster}, {}, "1");
// The cluster needs this secret, so it's going to request it.
EXPECT_TRUE(compareDeltaDiscoveryRequest(sds_type_url, {"validation_context"}, {}));
// Cluster should start off warming as the secret is being requested.
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 1);
// Ack the original CDS sub.
EXPECT_TRUE(compareDeltaDiscoveryRequest(cds_type_url, {}, {}));
// Before we send the secret, we'll send a delta removal to make sure we don't get a NACK.
sendDeltaDiscoveryResponse<envoy::extensions::transport_sockets::tls::v3::Secret>(
sds_type_url, {}, {"validation_context"}, "1");
// The cluster shouldn't be warming anymore since the server signaled
// that the requested resource doesn't exist.
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 0);
// Ack the original LDS subscription.
EXPECT_TRUE(compareDeltaDiscoveryRequest(lds_type_url, {}, {}));
// Ack the removal itself.
EXPECT_TRUE(compareDeltaDiscoveryRequest(sds_type_url, {}, {}));
envoy::extensions::transport_sockets::tls::v3::Secret validation_context;
TestUtility::loadFromYaml(fmt::format(R"EOF(
name: validation_context
validation_context:
trusted_ca:
filename: {}
)EOF",
TestEnvironment::runfilesPath(
"test/config/integration/certs/upstreamcacert.pem")),
validation_context);
// Now actually send the secret.
sendDeltaDiscoveryResponse<envoy::extensions::transport_sockets::tls::v3::Secret>(
sds_type_url, {validation_context}, {}, "2");
// Ack the secret we just sent.
EXPECT_TRUE(compareDeltaDiscoveryRequest(sds_type_url, {}, {}));
// Remove the cluster that owns the secret.
sendDeltaDiscoveryResponse<envoy::config::cluster::v3::Cluster>(cds_type_url, {}, {"cluster_0"},
"1");
// Follow that up with a secret removal.
sendDeltaDiscoveryResponse<envoy::extensions::transport_sockets::tls::v3::Secret>(
sds_type_url, {}, {"validation_context"}, "3");
test_server_->waitForCounterEq("cluster_manager.cluster_removed", 1);
// Ack the CDS removal.
EXPECT_TRUE(compareDeltaDiscoveryRequest(cds_type_url, {}, {}));
// Should be an ACK, not a NACK since the SDS removal is ignored.
EXPECT_TRUE(compareDeltaDiscoveryRequest(sds_type_url, {}, {}));
}
// Make sure two clusters sharing same secret are both kept warming before secret
// arrives. Verify that the clusters are eventually initialized.
// This is a regression test of #11120.
TEST_P(AdsIntegrationTest, ClusterSharingSecretWarming) {
initialize();
const auto cds_type_url = Config::getTypeUrl<envoy::config::cluster::v3::Cluster>();
const auto sds_type_url =
Config::getTypeUrl<envoy::extensions::transport_sockets::tls::v3::Secret>();
envoy::config::core::v3::TransportSocket sds_transport_socket;
TestUtility::loadFromYaml(R"EOF(
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
validation_context_sds_secret_config:
name: validation_context
sds_config:
ads: {}
)EOF",
sds_transport_socket);
auto cluster_template = ConfigHelper::buildStaticCluster("cluster", 8000, "127.0.0.1");
*cluster_template.mutable_transport_socket() = sds_transport_socket;
auto cluster_0 = cluster_template;
cluster_0.set_name("cluster_0");
auto cluster_1 = cluster_template;
cluster_1.set_name("cluster_1");
EXPECT_TRUE(compareDiscoveryRequest(cds_type_url, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(cds_type_url, {cluster_0, cluster_1},
{cluster_0, cluster_1}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(sds_type_url, "", {"validation_context"},
{"validation_context"}, {}));
test_server_->waitForGaugeGe("cluster_manager.warming_clusters", 2);
test_server_->waitForGaugeEq("cluster.cluster_0.warming_state", 1);
test_server_->waitForGaugeEq("cluster.cluster_1.warming_state", 1);
envoy::extensions::transport_sockets::tls::v3::Secret validation_context;
TestUtility::loadFromYaml(fmt::format(R"EOF(
name: validation_context
validation_context:
trusted_ca:
filename: {}
)EOF",
TestEnvironment::runfilesPath(
"test/config/integration/certs/upstreamcacert.pem")),
validation_context);
sendDiscoveryResponse<envoy::extensions::transport_sockets::tls::v3::Secret>(
sds_type_url, {validation_context}, {validation_context}, {}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
}
// Make sure two clusters with different secrets send only a single SDS request.
// This is a regression test of #21518.
TEST_P(AdsIntegrationTest, SecretsPausedDuringCDS) {
initialize();
const auto cds_type_url = Config::getTypeUrl<envoy::config::cluster::v3::Cluster>();
const auto sds_type_url =
Config::getTypeUrl<envoy::extensions::transport_sockets::tls::v3::Secret>();
std::vector<envoy::config::cluster::v3::Cluster> clusters;
for (int i = 0; i < 2; ++i) {
envoy::config::core::v3::TransportSocket sds_transport_socket;
TestUtility::loadFromYaml(fmt::format(R"EOF(
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
common_tls_context:
validation_context_sds_secret_config:
name: validation_context_{}
sds_config:
ads: {{}}
)EOF",
i),
sds_transport_socket);
auto cluster = ConfigHelper::buildStaticCluster("cluster", 8000, "127.0.0.1");
cluster.set_name(absl::StrCat("cluster_", i));
*cluster.mutable_transport_socket() = sds_transport_socket;
clusters.push_back(std::move(cluster));
}
EXPECT_TRUE(compareDiscoveryRequest(cds_type_url, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(cds_type_url, clusters, clusters, {},
"1");
// Expect a single request containing the 2 SDS resources.
EXPECT_TRUE(compareDiscoveryRequest(sds_type_url, "",
{"validation_context_0", "validation_context_1"},
{"validation_context_0", "validation_context_1"}, {}));
test_server_->waitForGaugeGe("cluster_manager.warming_clusters", 2);
std::vector<envoy::extensions::transport_sockets::tls::v3::Secret> validation_contexts;
for (int i = 0; i < 2; ++i) {
envoy::extensions::transport_sockets::tls::v3::Secret validation_context;
TestUtility::loadFromYaml(
fmt::format(
R"EOF(
name: validation_context_{}
validation_context:
trusted_ca:
filename: {}
)EOF",
i, TestEnvironment::runfilesPath("test/config/integration/certs/upstreamcacert.pem")),
validation_context);
validation_contexts.push_back(std::move(validation_context));
}
sendDiscoveryResponse<envoy::extensions::transport_sockets::tls::v3::Secret>(
sds_type_url, validation_contexts, validation_contexts, {}, "1");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
}
// Validate basic config delivery and upgrade with RateLimiting.
TEST_P(AdsIntegrationTest, BasicWithRateLimiting) {
initializeAds(true);
testBasicFlow();
}
// Validate that we can recover from failures.
TEST_P(AdsIntegrationTest, Failure) {
initialize();
// Send initial configuration, failing each xDS once (via a type mismatch), validate we can
// process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().Cluster, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(
Config::TypeUrl::get().Cluster, "", {}, {}, {}, false,
Grpc::Status::WellKnownGrpcStatus::Internal,
fmt::format("does not match the message-wide type URL {}", Config::TypeUrl::get().Cluster)));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {}, {}, false,
Grpc::Status::WellKnownGrpcStatus::Internal,
fmt::format("does not match the message-wide type URL {}",
Config::TypeUrl::get().ClusterLoadAssignment)));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().Listener, {buildRouteConfig("listener_0", "route_config_0")},
{buildRouteConfig("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(
Config::TypeUrl::get().Listener, "", {}, {}, {}, false,
Grpc::Status::WellKnownGrpcStatus::Internal,
fmt::format("does not match the message-wide type URL {}", Config::TypeUrl::get().Listener)));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().RouteConfiguration, {buildListener("route_config_0", "cluster_0")},
{buildListener("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {}, {}, false,
Grpc::Status::WellKnownGrpcStatus::Internal,
fmt::format("does not match the message-wide type URL {}",
Config::TypeUrl::get().RouteConfiguration)));
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
}
// Regression test for https://github.com/envoyproxy/envoy/issues/9682.
TEST_P(AdsIntegrationTest, ResendNodeOnStreamReset) {
initialize();
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
// A second CDS request should be sent so that the node is cleared in the cached request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
xds_stream_->finishGrpcStream(Grpc::Status::Internal);
AssertionResult result = xds_connection_->waitForNewStream(*dispatcher_, xds_stream_);
RELEASE_ASSERT(result, result.message());
xds_stream_->startGrpcStream();
// In SotW cluster_0 will be in the resource_names, but in delta-xDS
// resource_names_subscribe and resource_names_unsubscribe must be empty for
// a wildcard request (cluster_0 will appear in initial_resource_versions).
EXPECT_TRUE(
compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {"cluster_0"}, {}, {}, true));
}
// Verifies that upon stream reconnection:
// - Non-wildcard requests contain all known resources.
// - Wildcard requests contain all known resources in SotW, but no resources in delta-xDS.
// Regression test for https://github.com/envoyproxy/envoy/issues/16063.
TEST_P(AdsIntegrationTest, ResourceNamesOnStreamReset) {
initialize();
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
// A second CDS request should be sent so that the node is cleared in the cached request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
// The LDS request, which returns no resources in the DiscoveryResponse.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(Config::TypeUrl::get().Listener, {},
{}, {}, "1");
xds_stream_->finishGrpcStream(Grpc::Status::Internal);
AssertionResult result = xds_connection_->waitForNewStream(*dispatcher_, xds_stream_);
RELEASE_ASSERT(result, result.message());
xds_stream_->startGrpcStream();
// Each of these DiscoveryRequests after the stream reset should include the last version number
// received from the DiscoveryResponses.
// In SotW cluster_0 will be in the resource_names, but in delta-xDS
// resource_names_subscribe and resource_names_unsubscribe must be empty for
// a wildcard request (cluster_0 will appear in initial_resource_versions).
EXPECT_TRUE(
compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {"cluster_0"}, {}, {}, true));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {"cluster_0"}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
}
// Validate that the request with duplicate listeners is rejected.
TEST_P(AdsIntegrationTest, DuplicateWarmingListeners) {
initialize();
// Send initial configuration, validate we can process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
// Send duplicate listeners and validate that the update is rejected.
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener,
{buildListener("duplicae_listener", "route_config_0"),
buildListener("duplicae_listener", "route_config_0")},
{buildListener("duplicae_listener", "route_config_0"),
buildListener("duplicae_listener", "route_config_0")},
{}, "1");
test_server_->waitForCounterGe("listener_manager.lds.update_rejected", 1);
}
// Validate that the use of V2 transport version is rejected by default.
TEST_P(AdsIntegrationTest, DEPRECATED_FEATURE_TEST(RejectV2TransportConfigByDefault)) {
initialize();
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
auto cluster = buildCluster("cluster_0");
auto* api_config_source =
cluster.mutable_eds_cluster_config()->mutable_eds_config()->mutable_api_config_source();
api_config_source->set_api_type(envoy::config::core::v3::ApiConfigSource::GRPC);
api_config_source->set_transport_api_version(envoy::config::core::v3::V2);
envoy::config::core::v3::GrpcService* grpc_service = api_config_source->add_grpc_services();
setGrpcService(*grpc_service, "ads_cluster", xds_upstream_->localAddress());
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{cluster}, {cluster}, {}, "1");
test_server_->waitForCounterGe("cluster_manager.cds.update_rejected", 1);
}
// Regression test for the use-after-free crash when processing RDS update (#3953).
TEST_P(AdsIntegrationTest, RdsAfterLdsWithNoRdsChanges) {
initialize();
// Send initial configuration.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
// Validate that we can process a request.
makeSingleRequest();
// Update existing LDS (change stat_prefix).
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0", "rds_crash")},
{buildListener("listener_0", "route_config_0", "rds_crash")}, {}, "2");
test_server_->waitForCounterGe("listener_manager.listener_create_success", 2);
// Update existing RDS (no changes).
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "2");
// Validate that we can process a request again
makeSingleRequest();
}
// Regression test for #11877, validate behavior of EDS updates when a cluster is updated and
// an active cluster is replaced by a newer cluster undergoing warming.
TEST_P(AdsIntegrationTest, CdsEdsReplacementWarming) {
initialize();
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {buildTlsCluster("cluster_0")},
{buildTlsCluster("cluster_0")}, {}, "2");
// Inconsistent SotW and delta behaviors for warming, see
// https://github.com/envoyproxy/envoy/issues/11477#issuecomment-657855029.
// TODO (dmitri-d) this should be remove when legacy mux implementations have been removed.
if (sotw_or_delta_ == Grpc::SotwOrDelta::Sotw) {
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
}
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildTlsClusterLoadAssignment("cluster_0")},
{buildTlsClusterLoadAssignment("cluster_0")}, {}, "2");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "2", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "2",
{"cluster_0"}, {}, {}));
}
// Validate that an update to a Cluster that doesn't receive updated ClusterLoadAssignment
// uses the previous (cached) cluster load assignment.
TEST_P(AdsIntegrationTest, CdsKeepEdsAfterWarmingFailure) {
// TODO(adisuissa): this test should be kept after the runtime guard is deprecated
// (only the runtime guard should be removed).
config_helper_.addRuntimeOverride("envoy.restart_features.use_eds_cache_for_ads", "true");
initialize();
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
envoy::config::cluster::v3::Cluster cluster = buildCluster("cluster_0");
// Set a small EDS subscription expiration.
cluster.mutable_eds_cluster_config()
->mutable_eds_config()
->mutable_initial_fetch_timeout()
->set_nanos(100 * 1000 * 1000);
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{cluster}, {cluster}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
// Update a cluster's field (connect_timeout) so the cluster in Envoy will be explicitly updated.
cluster.mutable_connect_timeout()->set_seconds(7);
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{cluster}, {cluster}, {}, "2");
// Inconsistent SotW and delta behaviors for warming, see
// https://github.com/envoyproxy/envoy/issues/11477#issuecomment-657855029.
// TODO (dmitri-d) this should be remove when legacy mux implementations have been removed.
if (sotw_or_delta_ == Grpc::SotwOrDelta::Sotw) {
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
}
// Avoid sending an EDS update, and wait for EDS update timeout (that results in
// a cluster update without resources).
test_server_->waitForCounterGe("cluster.cluster_0.init_fetch_timeout", 1);
if (sotw_or_delta_ == Grpc::SotwOrDelta::Sotw) {
// Expect another EDS request after the previous one wasn't answered and timed out.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
}
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "2", {}, {}, {}));
// Envoy uses the cached resource.
EXPECT_EQ(1, test_server_->counter("cluster.cluster_0.assignment_use_cached")->value());
// A single message should be successfully sent to the upstream.
makeSingleRequest();
}
// Validate that an update to 2 Clusters that have the same ClusterLoadAssignment, and
// that don't receive updated ClusterLoadAssignment use the previous (cached) cluster
// load assignment.
TEST_P(AdsIntegrationTest, DoubleClustersCachedLoadAssignment) {
// TODO(adisuissa): this test should be kept after the runtime guard is deprecated
// (only the runtime guard should be removed).
config_helper_.addRuntimeOverride("envoy.restart_features.use_eds_cache_for_ads", "true");
initialize();
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
envoy::config::cluster::v3::Cluster cluster0 = buildCluster("cluster_0");
envoy::config::cluster::v3::Cluster cluster1 = buildCluster("cluster_1");
// Set a small EDS subscription expiration.
cluster0.mutable_eds_cluster_config()
->mutable_eds_config()
->mutable_initial_fetch_timeout()
->set_nanos(100 * 1000 * 1000);
cluster1.mutable_eds_cluster_config()
->mutable_eds_config()
->mutable_initial_fetch_timeout()
->set_nanos(100 * 1000 * 1000);
// Set the EDS service of cluster0 and cluster1 to be the same.
cluster0.mutable_eds_cluster_config()->set_service_name("same_eds");
cluster1.mutable_eds_cluster_config()->set_service_name("same_eds");
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {cluster0, cluster1}, {cluster0, cluster1}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"same_eds"}, {"same_eds"}, {}));
auto cla_0 = buildClusterLoadAssignment("same_eds");
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {cla_0}, {cla_0}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"same_eds"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
// Update a field of the clusters (connect_timeout) so the clusters in Envoy will be explicitly
// updated.
cluster0.mutable_connect_timeout()->set_seconds(7);
cluster1.mutable_connect_timeout()->set_seconds(7);
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {cluster0, cluster1}, {cluster0, cluster1}, {}, "2");
// Inconsistent SotW and delta behaviors for warming, see
// https://github.com/envoyproxy/envoy/issues/11477#issuecomment-657855029.
// TODO (dmitri-d) this should be remove when legacy mux implementations have been removed.
if (sotw_or_delta_ == Grpc::SotwOrDelta::Sotw) {
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"same_eds"}, {}, {}));
}
// Avoid sending an EDS update, and wait for EDS update timeout (that results in
// a cluster update without resources).
test_server_->waitForCounterGe("cluster.cluster_0.init_fetch_timeout", 1);
if (sotw_or_delta_ == Grpc::SotwOrDelta::Sotw) {
// Expect another EDS request after the previous one wasn't answered and timed out.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"same_eds"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"same_eds"}, {}, {}));
}
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "2", {}, {}, {}));
// Envoy uses the cached resource.
EXPECT_EQ(1, test_server_->counter("cluster.cluster_0.assignment_use_cached")->value());
// A single message should be successfully sent to the upstream.
makeSingleRequest();
// Now send an EDS update.
cla_0.mutable_policy()->mutable_overprovisioning_factor()->set_value(141);
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {cla_0}, {cla_0}, {}, "2");
// Wait for ingesting the update.
test_server_->waitForCounterEq("cluster.cluster_0.update_success", 2);
// A single message should be successfully sent to the upstream.
makeSingleRequest();
}
// Validate that the request with duplicate clusters in the initial request during server init is
// rejected.
TEST_P(AdsIntegrationTest, DuplicateInitialClusters) {
initialize();
// Send initial configuration, failing each xDS once (via a type mismatch), validate we can
// process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster,
{buildCluster("duplicate_cluster"), buildCluster("duplicate_cluster")},
{buildCluster("duplicate_cluster"), buildCluster("duplicate_cluster")}, {}, "1");
test_server_->waitForCounterGe("cluster_manager.cds.update_rejected", 1);
}
// Validate that the request with duplicate clusters in the subsequent requests (warming clusters)
// is rejected.
TEST_P(AdsIntegrationTest, DuplicateWarmingClusters) {
initialize();
// Send initial configuration, validate we can process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
makeSingleRequest();
// Send duplicate warming clusters and validate that the update is rejected.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster,
{buildCluster("duplicate_cluster"), buildCluster("duplicate_cluster")},
{buildCluster("duplicate_cluster"), buildCluster("duplicate_cluster")}, {}, "2");
test_server_->waitForCounterGe("cluster_manager.cds.update_rejected", 1);
}
// Verify CDS is paused during cluster warming.
TEST_P(AdsIntegrationTest, CdsPausedDuringWarming) {
initialize();
// Send initial configuration, validate we can process a request.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(Config::TypeUrl::get().Cluster,
{buildCluster("cluster_0")},
{buildCluster("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"cluster_0"}, {"cluster_0"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_0")},
{buildClusterLoadAssignment("cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "", {}, {}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_0")},
{buildListener("listener_0", "route_config_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_0")},
{buildRouteConfig("route_config_0", "cluster_0")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);