forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ads_integration_test.cc
892 lines (746 loc) · 45.7 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
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "envoy/config/cluster/v3/cluster.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 "common/common/version.h"
#include "common/config/protobuf_link_hacks.h"
#include "common/config/resources.h"
#include "common/config/version_converter.h"
#include "common/protobuf/protobuf.h"
#include "common/protobuf/utility.h"
#include "test/common/grpc/grpc_client_integration.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/utility.h"
#include "gtest/gtest.h"
using testing::AssertionResult;
namespace Envoy {
INSTANTIATE_TEST_SUITE_P(IpVersionsClientTypeDelta, AdsIntegrationTest,
DELTA_SOTW_GRPC_CLIENT_INTEGRATION_PARAMS);
// Validate basic config delivery and upgrade.
TEST_P(AdsIntegrationTest, Basic) {
initialize();
testBasicFlow();
}
// 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, "", {}, {}, {}, true,
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"}, {}, {}, true,
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, "", {}, {}, {}, true,
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"}, {}, {}, true,
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();
}
// 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);
}
// 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();
}
// 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);
}
// Validates that removing a redis cluster does not crash Envoy.
// Regression test for issue https://github.com/envoyproxy/envoy/issues/7990.
TEST_P(AdsIntegrationTest, RedisClusterRemoval) {
initialize();
// Send initial configuration with a redis cluster and a redis proxy listener.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}, true));
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {buildRedisCluster("redis_cluster")},
{buildRedisCluster("redis_cluster")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"redis_cluster"}, {"redis_cluster"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("redis_cluster")},
{buildClusterLoadAssignment("redis_cluster")}, {}, "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, {buildRedisListener("listener_0", "redis_cluster")},
{buildRedisListener("listener_0", "redis_cluster")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"redis_cluster"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
// Validate that redis listener is successfully created.
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
// Now send a CDS update, removing redis cluster added above.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("cluster_2")}, {buildCluster("cluster_2")},
{"redis_cluster"}, "2");
// Validate that the cluster is removed successfully.
test_server_->waitForCounterGe("cluster_manager.cluster_removed", 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);
makeSingleRequest();
EXPECT_FALSE(
test_server_->server().clusterManager().adsMux()->paused(Config::TypeUrl::get().Cluster));
// Send the first warming cluster.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("warming_cluster_1")},
{buildCluster("warming_cluster_1")}, {"cluster_0"}, "2");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
EXPECT_TRUE(
test_server_->server().clusterManager().adsMux()->paused(Config::TypeUrl::get().Cluster));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"warming_cluster_1"}, {"warming_cluster_1"}, {"cluster_0"}));
// Send the second warming cluster.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("warming_cluster_2")},
{buildCluster("warming_cluster_2")}, {}, "3");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 2);
// We would've got a Cluster discovery request with version 2 here, had the CDS not been paused.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"warming_cluster_2", "warming_cluster_1"},
{"warming_cluster_2"}, {}));
EXPECT_TRUE(
test_server_->server().clusterManager().adsMux()->paused(Config::TypeUrl::get().Cluster));
// Finish warming the clusters.
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment,
{buildClusterLoadAssignment("warming_cluster_1"),
buildClusterLoadAssignment("warming_cluster_2")},
{buildClusterLoadAssignment("warming_cluster_1"),
buildClusterLoadAssignment("warming_cluster_2")},
{"cluster_0"}, "2");
// Validate that clusters are warmed.
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
EXPECT_FALSE(
test_server_->server().clusterManager().adsMux()->paused(Config::TypeUrl::get().Cluster));
// CDS is resumed and EDS response was acknowledged.
if (sotw_or_delta_ == Grpc::SotwOrDelta::Delta) {
// Envoy will ACK both Cluster messages. Since they arrived while CDS was paused, they aren't
// sent until CDS is unpaused. Since version 3 has already arrived by the time the version 2
// ACK goes out, they're both acknowledging version 3.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "3", {}, {}, {}));
}
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "3", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "2",
{"warming_cluster_2", "warming_cluster_1"}, {}, {}));
}
// Verify cluster warming is finished only on named EDS response.
TEST_P(AdsIntegrationTest, ClusterWarmingOnNamedResponse) {
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 the first warming cluster.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("warming_cluster_1")},
{buildCluster("warming_cluster_1")}, {"cluster_0"}, "2");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"warming_cluster_1"}, {"warming_cluster_1"}, {"cluster_0"}));
// Send the second warming cluster.
sendDiscoveryResponse<envoy::config::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("warming_cluster_2")},
{buildCluster("warming_cluster_2")}, {}, "3");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 2);
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"warming_cluster_2", "warming_cluster_1"},
{"warming_cluster_2"}, {}));
// Finish warming the first cluster.
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment,
{buildClusterLoadAssignment("warming_cluster_1")},
{buildClusterLoadAssignment("warming_cluster_1")}, {}, "2");
// Envoy will not finish warming of the second cluster because of the missing load assignments
// i,e. no named EDS response.
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
// Disconnect and reconnect the stream.
xds_stream_->finishGrpcStream(Grpc::Status::Internal);
AssertionResult result = xds_connection_->waitForNewStream(*dispatcher_, xds_stream_);
RELEASE_ASSERT(result, result.message());
xds_stream_->startGrpcStream();
// Envoy will not finish warming of the second cluster because of the missing load assignments
// i,e. no named EDS response even after disconnect and reconnect.
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 1);
// Finish warming the second cluster.
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment,
{buildClusterLoadAssignment("warming_cluster_2")},
{buildClusterLoadAssignment("warming_cluster_2")}, {}, "3");
test_server_->waitForGaugeEq("cluster_manager.warming_clusters", 0);
}
// Regression test for the use-after-free crash when processing RDS update (#3953).
TEST_P(AdsIntegrationTest, RdsAfterLdsWithRdsChange) {
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::cluster::v3::Cluster>(
Config::TypeUrl::get().Cluster, {buildCluster("cluster_1")}, {buildCluster("cluster_1")},
{"cluster_0"}, "2");
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("cluster_1")},
{buildClusterLoadAssignment("cluster_1")}, {"cluster_0"}, "2");
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 (migrate traffic to cluster_1).
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_0", "cluster_1")},
{buildRouteConfig("route_config_0", "cluster_1")}, {}, "2");
// Validate that we can process a request after RDS update
test_server_->waitForCounterGe("http.ads_test.rds.route_config_0.config_reload", 2);
makeSingleRequest();
}
// Regression test for the use-after-free crash when a listener awaiting an RDS update is destroyed
// (#6116).
TEST_P(AdsIntegrationTest, RdsAfterLdsInvalidated) {
initialize();
// STEP 1: Initial setup
// ---------------------
// Initial request for any cluster, respond with cluster_0 version 1
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");
// Initial request for load assignment for cluster_0, respond with version 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");
// Request for updates to cluster_0 version 1, no response
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
// Initial request for any listener, respond with listener_0 version 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");
// Request for updates to load assignment version 1, no response
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
// Initial request for route_config_0 (referenced by listener_0), respond with version 1
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");
// Wait for initial listener to be created successfully. Any subsequent listeners will then use
// the dynamic InitManager (see ListenerImpl::initManager).
test_server_->waitForCounterGe("listener_manager.listener_create_success", 1);
// STEP 2: Listener with dynamic InitManager
// -----------------------------------------
// Request for updates to listener_0 version 1, respond with version 2. Under the hood, this
// registers RdsRouteConfigSubscription's init target with the new ListenerImpl instance.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_1")},
{buildListener("listener_0", "route_config_1")}, {}, "2");
// Request for updates to route_config_0 version 1, and initial request for route_config_1
// (referenced by listener_0), don't respond yet!
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_0"}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "1",
{"route_config_1", "route_config_0"}, {"route_config_1"},
{}));
// STEP 3: "New listener, who dis?"
// --------------------------------
// Request for updates to listener_0 version 2, respond with version 3 (updated stats prefix).
// This should blow away the previous ListenerImpl instance, which is still waiting for
// route_config_1...
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "2", {}, {}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(
Config::TypeUrl::get().Listener, {buildListener("listener_0", "route_config_1", "omg")},
{buildListener("listener_0", "route_config_1", "omg")}, {}, "3");
// Respond to prior request for route_config_1. Under the hood, this invokes
// RdsRouteConfigSubscription::runInitializeCallbackIfAny, which references the defunct
// ListenerImpl instance. We should not crash in this event!
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration, {buildRouteConfig("route_config_1", "cluster_0")},
{buildRouteConfig("route_config_1", "cluster_0")}, {"route_config_0"}, "1");
test_server_->waitForCounterGe("listener_manager.listener_create_success", 2);
}
class AdsFailIntegrationTest : public Grpc::DeltaSotwIntegrationParamTest,
public HttpIntegrationTest {
public:
AdsFailIntegrationTest()
: HttpIntegrationTest(Http::CodecClient::Type::HTTP2, ipVersion(),
AdsIntegrationConfig(
sotwOrDelta() == Grpc::SotwOrDelta::Sotw ? "GRPC" : "DELTA_GRPC")) {
create_xds_upstream_ = true;
use_lds_ = false;
sotw_or_delta_ = sotwOrDelta();
}
void TearDown() override {
cleanUpXdsConnection();
test_server_.reset();
fake_upstreams_.clear();
}
void initialize() override {
config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
auto* grpc_service =
bootstrap.mutable_dynamic_resources()->mutable_ads_config()->add_grpc_services();
setGrpcService(*grpc_service, "ads_cluster", xds_upstream_->localAddress());
auto* ads_cluster = bootstrap.mutable_static_resources()->add_clusters();
ads_cluster->MergeFrom(bootstrap.static_resources().clusters()[0]);
ads_cluster->set_name("ads_cluster");
});
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
HttpIntegrationTest::initialize();
}
};
INSTANTIATE_TEST_SUITE_P(IpVersionsClientTypeDelta, AdsFailIntegrationTest,
DELTA_SOTW_GRPC_CLIENT_INTEGRATION_PARAMS);
// Validate that we don't crash on failed ADS stream.
TEST_P(AdsFailIntegrationTest, ConnectDisconnect) {
initialize();
createXdsConnection();
ASSERT_TRUE(xds_connection_->waitForNewStream(*dispatcher_, xds_stream_));
xds_stream_->startGrpcStream();
xds_stream_->finishGrpcStream(Grpc::Status::Internal);
}
class AdsConfigIntegrationTest : public Grpc::DeltaSotwIntegrationParamTest,
public HttpIntegrationTest {
public:
AdsConfigIntegrationTest()
: HttpIntegrationTest(Http::CodecClient::Type::HTTP2, ipVersion(),
AdsIntegrationConfig(
sotwOrDelta() == Grpc::SotwOrDelta::Sotw ? "GRPC" : "DELTA_GRPC")) {
create_xds_upstream_ = true;
use_lds_ = false;
sotw_or_delta_ = sotwOrDelta();
}
void TearDown() override {
cleanUpXdsConnection();
test_server_.reset();
fake_upstreams_.clear();
}
void initialize() override {
config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
auto* grpc_service =
bootstrap.mutable_dynamic_resources()->mutable_ads_config()->add_grpc_services();
setGrpcService(*grpc_service, "ads_cluster", xds_upstream_->localAddress());
auto* ads_cluster = bootstrap.mutable_static_resources()->add_clusters();
ads_cluster->MergeFrom(bootstrap.static_resources().clusters()[0]);
ads_cluster->set_name("ads_cluster");
// Add EDS static Cluster that uses ADS as config Source.
auto* ads_eds_cluster = bootstrap.mutable_static_resources()->add_clusters();
ads_eds_cluster->set_name("ads_eds_cluster");
ads_eds_cluster->set_type(envoy::config::cluster::v3::Cluster::EDS);
auto* eds_cluster_config = ads_eds_cluster->mutable_eds_cluster_config();
auto* eds_config = eds_cluster_config->mutable_eds_config();
eds_config->mutable_ads();
});
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
HttpIntegrationTest::initialize();
}
};
INSTANTIATE_TEST_SUITE_P(IpVersionsClientTypeDelta, AdsConfigIntegrationTest,
DELTA_SOTW_GRPC_CLIENT_INTEGRATION_PARAMS);
// This is s regression validating that we don't crash on EDS static Cluster that uses ADS.
TEST_P(AdsConfigIntegrationTest, EdsClusterWithAdsConfigSource) {
initialize();
createXdsConnection();
ASSERT_TRUE(xds_connection_->waitForNewStream(*dispatcher_, xds_stream_));
xds_stream_->startGrpcStream();
xds_stream_->finishGrpcStream(Grpc::Status::Ok);
}
// Validates that the initial xDS request batches all resources referred to in static config
TEST_P(AdsIntegrationTest, XdsBatching) {
config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
bootstrap.mutable_dynamic_resources()->clear_cds_config();
bootstrap.mutable_dynamic_resources()->clear_lds_config();
auto static_resources = bootstrap.mutable_static_resources();
static_resources->add_clusters()->MergeFrom(buildCluster("eds_cluster"));
static_resources->add_clusters()->MergeFrom(buildCluster("eds_cluster2"));
static_resources->add_listeners()->MergeFrom(buildListener("rds_listener", "route_config"));
static_resources->add_listeners()->MergeFrom(buildListener("rds_listener2", "route_config2"));
});
on_server_init_function_ = [this]() {
createXdsConnection();
ASSERT_TRUE(xds_connection_->waitForNewStream(*dispatcher_, xds_stream_));
xds_stream_->startGrpcStream();
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"eds_cluster2", "eds_cluster"},
{"eds_cluster2", "eds_cluster"}, {}, true));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment,
{buildClusterLoadAssignment("eds_cluster"), buildClusterLoadAssignment("eds_cluster2")},
{buildClusterLoadAssignment("eds_cluster"), buildClusterLoadAssignment("eds_cluster2")}, {},
"1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config2", "route_config"},
{"route_config2", "route_config"}, {}));
sendDiscoveryResponse<envoy::config::route::v3::RouteConfiguration>(
Config::TypeUrl::get().RouteConfiguration,
{buildRouteConfig("route_config2", "eds_cluster2"),
buildRouteConfig("route_config", "dummy_cluster")},
{buildRouteConfig("route_config2", "eds_cluster2"),
buildRouteConfig("route_config", "dummy_cluster")},
{}, "1");
};
initialize();
}
// Validates that listeners can be removed before server start.
TEST_P(AdsIntegrationTest, ListenerDrainBeforeServerStart) {
initialize();
// Initial request for cluster, response for cluster_0.
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");
// Initial request for load assignment for cluster_0, respond with version 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");
// Request for updates to cluster_0 version 1, no response
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "1", {}, {}, {}));
// Initial request for any listener, respond with listener_0 version 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");
// Request for updates to load assignment version 1, no response
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"cluster_0"}, {}, {}));
// Initial request for route_config_0 (referenced by listener_0), respond with version 1
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().RouteConfiguration, "",
{"route_config_0"}, {"route_config_0"}, {}));
test_server_->waitForGaugeGe("listener_manager.total_listeners_active", 1);
// Before server is started, even though listeners are added to active list
// we mark them as "warming" in config dump since they're not initialized yet.
ASSERT_EQ(getListenersConfigDump().dynamic_listeners().size(), 1);
EXPECT_TRUE(getListenersConfigDump().dynamic_listeners(0).has_warming_state());
// Remove listener.
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Listener, "1", {}, {}, {}));
sendDiscoveryResponse<envoy::config::listener::v3::Listener>(Config::TypeUrl::get().Listener, {},
{}, {"listener_0"}, "2");
test_server_->waitForGaugeEq("listener_manager.total_listeners_active", 0);
}
// Validate that Node message is well formed.
TEST_P(AdsIntegrationTest, NodeMessage) {
initialize();
API_NO_BOOST(envoy::api::v2::DiscoveryRequest) sotw_request;
API_NO_BOOST(envoy::api::v2::DeltaDiscoveryRequest) delta_request;
const envoy::api::v2::core::Node* node = nullptr;
if (sotw_or_delta_ == Grpc::SotwOrDelta::Sotw) {
EXPECT_TRUE(xds_stream_->waitForGrpcMessage(*dispatcher_, sotw_request));
EXPECT_TRUE(sotw_request.has_node());
node = &sotw_request.node();
} else {
EXPECT_TRUE(xds_stream_->waitForGrpcMessage(*dispatcher_, delta_request));
EXPECT_TRUE(delta_request.has_node());
node = &delta_request.node();
}
envoy::config::core::v3::BuildVersion build_version_msg;
Config::VersionConverter::upgrade(node->user_agent_build_version(), build_version_msg);
EXPECT_THAT(build_version_msg, ProtoEq(VersionInfo::buildVersion()));
EXPECT_GE(node->extensions().size(), 0);
EXPECT_EQ(0, node->client_features().size());
xds_stream_->finishGrpcStream(Grpc::Status::Ok);
}
// Check if EDS cluster defined in file is loaded before ADS request and used as xDS server
class AdsClusterFromFileIntegrationTest : public Grpc::DeltaSotwIntegrationParamTest,
public HttpIntegrationTest {
public:
AdsClusterFromFileIntegrationTest()
: HttpIntegrationTest(Http::CodecClient::Type::HTTP2, ipVersion(),
AdsIntegrationConfig(
sotwOrDelta() == Grpc::SotwOrDelta::Sotw ? "GRPC" : "DELTA_GRPC")) {
create_xds_upstream_ = true;
use_lds_ = false;
sotw_or_delta_ = sotwOrDelta();
}
void TearDown() override {
cleanUpXdsConnection();
test_server_.reset();
fake_upstreams_.clear();
}
void initialize() override {
config_helper_.addConfigModifier([this](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
auto* grpc_service =
bootstrap.mutable_dynamic_resources()->mutable_ads_config()->add_grpc_services();
setGrpcService(*grpc_service, "ads_cluster", xds_upstream_->localAddress());
// Define ADS cluster
auto* ads_cluster = bootstrap.mutable_static_resources()->add_clusters();
ads_cluster->set_name("ads_cluster");
ads_cluster->mutable_http2_protocol_options();
ads_cluster->set_type(envoy::config::cluster::v3::Cluster::EDS);
auto* ads_cluster_config = ads_cluster->mutable_eds_cluster_config();
auto* ads_cluster_eds_config = ads_cluster_config->mutable_eds_config();
// Define port of ADS cluster
TestEnvironment::PortMap port_map_;
port_map_["upstream_0"] = xds_upstream_->localAddress()->ip()->port();
// Path to EDS for ads_cluster
const std::string eds_path = TestEnvironment::temporaryFileSubstitute(
"test/config/integration/server_xds.eds.ads_cluster.yaml", port_map_, version_);
ads_cluster_eds_config->set_path(eds_path);
// Add EDS static Cluster that uses ADS as config Source.
auto* ads_eds_cluster = bootstrap.mutable_static_resources()->add_clusters();
ads_eds_cluster->set_name("ads_eds_cluster");
ads_eds_cluster->set_type(envoy::config::cluster::v3::Cluster::EDS);
auto* eds_cluster_config = ads_eds_cluster->mutable_eds_cluster_config();
auto* eds_config = eds_cluster_config->mutable_eds_config();
eds_config->mutable_ads();
});
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
HttpIntegrationTest::initialize();
}
envoy::config::endpoint::v3::ClusterLoadAssignment
buildClusterLoadAssignment(const std::string& name) {
return TestUtility::parseYaml<envoy::config::endpoint::v3::ClusterLoadAssignment>(
fmt::format(R"EOF(
cluster_name: {}
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: {}
port_value: {}
)EOF",
name, Network::Test::getLoopbackAddressString(ipVersion()),
fake_upstreams_[0]->localAddress()->ip()->port()));
}
};
INSTANTIATE_TEST_SUITE_P(IpVersionsClientTypeDelta, AdsClusterFromFileIntegrationTest,
DELTA_SOTW_GRPC_CLIENT_INTEGRATION_PARAMS);
// Validate if ADS cluster defined as EDS will be loaded from file and connection with ADS cluster
// will be established.
TEST_P(AdsClusterFromFileIntegrationTest, BasicTestWidsAdsEndpointLoadedFromFile) {
initialize();
createXdsConnection();
ASSERT_TRUE(xds_connection_->waitForNewStream(*dispatcher_, xds_stream_));
xds_stream_->startGrpcStream();
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "",
{"ads_eds_cluster"}, {"ads_eds_cluster"}, {}));
sendDiscoveryResponse<envoy::config::endpoint::v3::ClusterLoadAssignment>(
Config::TypeUrl::get().ClusterLoadAssignment, {buildClusterLoadAssignment("ads_eds_cluster")},
{buildClusterLoadAssignment("ads_eds_cluster")}, {}, "1");
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().Cluster, "", {}, {}, {}));
EXPECT_TRUE(compareDiscoveryRequest(Config::TypeUrl::get().ClusterLoadAssignment, "1",
{"ads_eds_cluster"}, {}, {}));
}
} // namespace Envoy