@@ -529,3 +529,70 @@ describe("Plugin: prometheus (access) granular metrics switch", function()
529
529
530
530
end )
531
531
end
532
+
533
+ describe (" CP/DP connectivity state #" , function ()
534
+ local status_client
535
+
536
+ local function get_metrics ()
537
+ if not status_client then
538
+ status_client = helpers .http_client (" 127.0.0.1" , tcp_status_port , 20000 )
539
+ status_client .reopen = true -- retry on a closed connection
540
+ end
541
+
542
+ local res , err = status_client :get (" /metrics" )
543
+
544
+ assert .is_nil (err , " failed GET /metrics: " .. tostring (err ))
545
+ return assert .res_status (200 , res )
546
+ end
547
+
548
+ setup (function ()
549
+ local bp = helpers .get_db_utils ()
550
+
551
+ bp .plugins :insert {
552
+ protocols = { " http" , " https" , " grpc" , " grpcs" , " tcp" , " tls" },
553
+ name = " prometheus" ,
554
+ }
555
+
556
+ assert (helpers .start_kong ({
557
+ role = " control_plane" ,
558
+ prefix = " prom_cp" ,
559
+ cluster_cert = " spec/fixtures/kong_clustering.crt" ,
560
+ cluster_cert_key = " spec/fixtures/kong_clustering.key" ,
561
+ cluster_listen = " 127.0.0.1:9005" ,
562
+ plugins = " bundled, prometheus" ,
563
+ }))
564
+
565
+ assert (helpers .start_kong ({
566
+ role = " data_plane" ,
567
+ database = " off" ,
568
+ prefix = " prom_dp" ,
569
+ cluster_cert = " spec/fixtures/kong_clustering.crt" ,
570
+ cluster_cert_key = " spec/fixtures/kong_clustering.key" ,
571
+ cluster_control_plane = " 127.0.0.1:9005" ,
572
+ proxy_listen = " 0.0.0.0:9000" ,
573
+ worker_state_update_frequency = 1 ,
574
+ status_listen = " 0.0.0.0:" .. tcp_status_port ,
575
+ nginx_worker_processes = 1 ,
576
+ dedicated_config_processing = " on" ,
577
+ plugins = " bundled, prometheus" ,
578
+ }))
579
+ status_client = helpers .http_client (" 127.0.0.1" , tcp_status_port , 20000 )
580
+ end )
581
+
582
+ teardown (function ()
583
+ if status_client then
584
+ status_client :close ()
585
+ end
586
+
587
+ helpers .stop_kong (" prom_dp" )
588
+ end )
589
+
590
+ it (" exposes controlplane connectivity status" , function ()
591
+ local body = get_metrics ()
592
+ assert .matches (' kong_control_plane_reachable 1' , body , nil , true )
593
+
594
+ helpers .stop_kong (" prom_cp" )
595
+ local body = get_metrics ()
596
+ assert .matches (' kong_control_plane_reachable 0' , body , nil , true )
597
+ end )
598
+ end )
0 commit comments