From 342d88fbd44788aa6aa940e3c4d73455392afa80 Mon Sep 17 00:00:00 2001 From: Jan Grashoefer Date: Wed, 26 Apr 2023 20:00:44 +0200 Subject: [PATCH] Simplify btests using cluster_started event. --- .../manager-1..stdout | 9 --- .../proxy-1..stdout | 3 - .../proxy-2..stdout | 3 - .../worker-1..stdout | 3 - .../worker-2..stdout | 3 - .../cluster/custom_pool_exclusivity.zeek | 20 ++--- .../cluster/custom_pool_limits.zeek | 20 ++--- .../base/frameworks/cluster/forwarding.zeek | 74 +++---------------- .../frameworks/cluster/log_distribution.zeek | 19 ++--- .../cluster/topic_distribution.zeek | 20 ++--- .../cluster/topic_distribution_bifs.zeek | 19 ++--- .../base/frameworks/config/basic_cluster.zeek | 16 +--- .../cluster-transparency-with-proxy.zeek | 27 +------ .../intel/cluster-transparency.zeek | 9 +-- .../intel/read-file-dist-cluster.zeek | 22 +----- .../frameworks/intel/remove-item-cluster.zeek | 13 ++-- .../base/frameworks/notice/cluster.zeek | 26 ++----- .../notice/suppression-cluster.zeek | 11 +-- .../frameworks/sumstats/basic-cluster.zeek | 25 +------ .../sumstats/manual-epoch-cluster.zeek | 14 +--- .../sumstats/on-demand-cluster.zeek | 18 +---- .../frameworks/sumstats/sample-cluster.zeek | 24 +----- .../frameworks/sumstats/topk-cluster.zeek | 24 +----- .../base/frameworks/telemetry/cluster.zeek | 31 ++++---- .../frameworks/cluster/cluster_started.zeek | 1 - .../cluster/cluster_started_logger.zeek | 1 - .../cluster_started_restart_manager.zeek | 1 - .../cluster_started_restart_worker.zeek | 1 - .../policy/misc/weird-stats-cluster.zeek | 22 ++---- testing/btest/supervisor/config-cluster.zeek | 18 +---- 30 files changed, 92 insertions(+), 405 deletions(-) diff --git a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/manager-1..stdout b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/manager-1..stdout index 4bbd46575e..49d861c74c 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/manager-1..stdout +++ b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/manager-1..stdout @@ -1,10 +1 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -### NOTE: This file has been sorted with diff-sort. -Connected to a peer -Connected to a peer -Connected to a peer -Connected to a peer -Got fully_connected event -Got fully_connected event -Got fully_connected event -Got fully_connected event diff --git a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/proxy-1..stdout b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/proxy-1..stdout index 5093baf444..49d861c74c 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/proxy-1..stdout +++ b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/proxy-1..stdout @@ -1,4 +1 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -Connected to a peer -Connected to a peer -Connected to a peer diff --git a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/proxy-2..stdout b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/proxy-2..stdout index 5093baf444..49d861c74c 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/proxy-2..stdout +++ b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/proxy-2..stdout @@ -1,4 +1 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -Connected to a peer -Connected to a peer -Connected to a peer diff --git a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/worker-1..stdout b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/worker-1..stdout index 5093baf444..49d861c74c 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/worker-1..stdout +++ b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/worker-1..stdout @@ -1,4 +1 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -Connected to a peer -Connected to a peer -Connected to a peer diff --git a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/worker-2..stdout b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/worker-2..stdout index 9f78de549b..3a811915d4 100644 --- a/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/worker-2..stdout +++ b/testing/btest/Baseline/scripts.base.frameworks.cluster.forwarding/worker-2..stdout @@ -1,5 +1,2 @@ ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. -Connected to a peer -Connected to a peer -Connected to a peer got forwarded event diff --git a/testing/btest/scripts/base/frameworks/cluster/custom_pool_exclusivity.zeek b/testing/btest/scripts/base/frameworks/cluster/custom_pool_exclusivity.zeek index eff665fccb..d72b2f77b2 100644 --- a/testing/btest/scripts/base/frameworks/cluster/custom_pool_exclusivity.zeek +++ b/testing/btest/scripts/base/frameworks/cluster/custom_pool_exclusivity.zeek @@ -10,15 +10,13 @@ # @TEST-EXEC: btest-bg-wait 45 # @TEST-EXEC: btest-diff manager-1/.stdout -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { ["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))], ["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"], ["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"], - ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"], - ["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"], }; @TEST-END-FILE @@ -43,8 +41,6 @@ event zeek_init() my_pool = Cluster::register_pool(my_pool_spec); } -global proxy_count = 0; - event go_away() { terminate(); @@ -78,20 +74,14 @@ function print_stuff(heading: string) } } -event Cluster::node_up(name: string, id: string) +event Cluster::Experimental::cluster_started() { if ( Cluster::node != "manager-1" ) return; - if ( name == "proxy-1" || name == "proxy-2" ) - ++proxy_count; - - if ( proxy_count == 2 ) - { - print_stuff("1st stuff"); - local e = Broker::make_event(go_away); - Broker::publish(Cluster::node_topic("proxy-1"), e); - } + print_stuff("1st stuff"); + local e = Broker::make_event(go_away); + Broker::publish(Cluster::node_topic("proxy-1"), e); } event Cluster::node_down(name: string, id: string) diff --git a/testing/btest/scripts/base/frameworks/cluster/custom_pool_limits.zeek b/testing/btest/scripts/base/frameworks/cluster/custom_pool_limits.zeek index 26127dc1e2..63081e2756 100644 --- a/testing/btest/scripts/base/frameworks/cluster/custom_pool_limits.zeek +++ b/testing/btest/scripts/base/frameworks/cluster/custom_pool_limits.zeek @@ -10,15 +10,13 @@ # @TEST-EXEC: btest-bg-wait 45 # @TEST-EXEC: btest-diff manager-1/.stdout -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { ["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))], ["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"], ["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"], - ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"], - ["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"], }; @TEST-END-FILE @@ -43,8 +41,6 @@ event zeek_init() my_pool = Cluster::register_pool(my_pool_spec); } -global proxy_count = 0; - event go_away() { terminate(); @@ -78,20 +74,14 @@ function print_stuff(heading: string) } } -event Cluster::node_up(name: string, id: string) +event Cluster::Experimental::cluster_started() { if ( Cluster::node != "manager-1" ) return; - if ( name == "proxy-1" || name == "proxy-2" ) - ++proxy_count; - - if ( proxy_count == 2 ) - { - print_stuff("1st stuff"); - local e = Broker::make_event(go_away); - Broker::publish(Cluster::node_topic("proxy-1"), e); - } + print_stuff("1st stuff"); + local e = Broker::make_event(go_away); + Broker::publish(Cluster::node_topic("proxy-1"), e); } event Cluster::node_down(name: string, id: string) diff --git a/testing/btest/scripts/base/frameworks/cluster/forwarding.zeek b/testing/btest/scripts/base/frameworks/cluster/forwarding.zeek index bc696123a5..81e1e7c087 100644 --- a/testing/btest/scripts/base/frameworks/cluster/forwarding.zeek +++ b/testing/btest/scripts/base/frameworks/cluster/forwarding.zeek @@ -1,39 +1,25 @@ # @TEST-PORT: BROKER_PORT1 # @TEST-PORT: BROKER_PORT2 # @TEST-PORT: BROKER_PORT3 -# @TEST-PORT: BROKER_PORT4 -# @TEST-PORT: BROKER_PORT5 # -# @TEST-EXEC: btest-bg-run manager-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=manager-1 zeek -b %INPUT -# @TEST-EXEC: btest-bg-run proxy-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=proxy-1 zeek -b %INPUT -# @TEST-EXEC: btest-bg-run proxy-2 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=proxy-2 zeek -b %INPUT +# @TEST-EXEC: btest-bg-run manager-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=manager-1 zeek -B broker -b %INPUT # @TEST-EXEC: btest-bg-run worker-1 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-1 zeek -b %INPUT # @TEST-EXEC: btest-bg-run worker-2 ZEEKPATH=$ZEEKPATH:.. CLUSTER_NODE=worker-2 zeek -b %INPUT # @TEST-EXEC: btest-bg-wait 45 -# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff manager-1/.stdout -# @TEST-EXEC: btest-diff proxy-1/.stdout -# @TEST-EXEC: btest-diff proxy-2/.stdout +# @TEST-EXEC: btest-diff manager-1/.stdout # @TEST-EXEC: btest-diff worker-1/.stdout # @TEST-EXEC: btest-diff worker-2/.stdout -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { ["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))], - ["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"], - ["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"], - ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"], - ["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"], + ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1", $interface="eth0"], + ["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1", $interface="eth1"], }; @TEST-END-FILE -global fully_connected: event(); - -global peer_count = 0; -global peers_lost = 0; -global fully_connected_nodes = 0; - redef Broker::forward_messages = T; event forwarded_event() @@ -46,33 +32,17 @@ event forwarded_event() terminate(); } -event ready() +event Cluster::Experimental::cluster_started() { # note that the publishing node, worker-1, will not receive the forwarded # event as Broker's forwarding prevents the message going back to the # immediate sender. - Broker::publish("test_topic", forwarded_event); - } - -event fully_connected() - { - if ( ! is_remote_event() ) - return; - - print "Got fully_connected event"; - fully_connected_nodes = fully_connected_nodes + 1; - - if ( Cluster::node == "manager-1" ) - { - if ( peer_count == 4 && fully_connected_nodes == 4 ) - Broker::publish(Cluster::node_topic("worker-1"), ready); - } + if ( Cluster::node == "worker-1" ) + Broker::publish("test_topic", forwarded_event); } event zeek_init() { - Broker::auto_publish(Cluster::manager_topic, fully_connected); - if ( Cluster::node == "manager-1" ) Broker::forward("test_topic"); if ( Cluster::node == "worker-1" ) @@ -81,33 +51,7 @@ event zeek_init() Broker::subscribe("test_topic"); } -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - print "Connected to a peer"; - peer_count = peer_count + 1; - - if ( Cluster::node == "manager-1" ) - { - if ( peer_count == 4 && fully_connected_nodes == 4 ) - Broker::publish(Cluster::node_topic("worker-1"), ready); - } - else - { - if ( peer_count == 3 ) - event fully_connected(); - } - } - event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) { - ++peers_lost; - - if ( Cluster::node == "manager-1" ) - { - if ( peers_lost == 2 ) - # Both workers terminated - terminate(); - } - else - terminate(); + terminate(); } diff --git a/testing/btest/scripts/base/frameworks/cluster/log_distribution.zeek b/testing/btest/scripts/base/frameworks/cluster/log_distribution.zeek index 940707665e..abf2b5d5bf 100644 --- a/testing/btest/scripts/base/frameworks/cluster/log_distribution.zeek +++ b/testing/btest/scripts/base/frameworks/cluster/log_distribution.zeek @@ -14,7 +14,7 @@ # @TEST-EXEC: btest-diff logger-1/test.log # @TEST-EXEC: btest-diff logger-10/test.log -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::manager_is_logger = F; @@ -42,7 +42,6 @@ event zeek_init() &priority=5 Log::create_stream(Test::LOG, [$columns=Info, $path="test"]); } -global peer_count = 0; global c = 0; event go_away() @@ -63,23 +62,17 @@ event do_count() schedule 0.01sec { do_count() }; } -event Cluster::node_up(name: string, id: string) +event Cluster::Experimental::cluster_started() { - print "node_up", name; - ++peer_count; + if ( Cluster::node != "worker-1" ) + return; - if ( Cluster::node == "worker-1" && peer_count == 3 ) - { - Cluster::logger_pool$rr_key_seq["Cluster::rr_log_topic"] = 0; - schedule 0.25sec { do_count() }; - } + Cluster::logger_pool$rr_key_seq["Cluster::rr_log_topic"] = 0; + schedule 0.25sec { do_count() }; } event Cluster::node_down(name: string, id: string) { - print "node_down", name; - --peer_count; - if ( name == "worker-1" ) schedule 2sec { go_away() }; } diff --git a/testing/btest/scripts/base/frameworks/cluster/topic_distribution.zeek b/testing/btest/scripts/base/frameworks/cluster/topic_distribution.zeek index 6b7f70435f..39d83414c0 100644 --- a/testing/btest/scripts/base/frameworks/cluster/topic_distribution.zeek +++ b/testing/btest/scripts/base/frameworks/cluster/topic_distribution.zeek @@ -10,20 +10,16 @@ # @TEST-EXEC: btest-bg-wait 40 # @TEST-EXEC: btest-diff manager-1/.stdout -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { ["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))], ["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"], ["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"], - ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"], - ["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"], }; @TEST-END-FILE -global proxy_count = 0; - event go_away() { terminate(); @@ -48,20 +44,14 @@ function print_stuff(heading: string) print "hrw", v[i], Cluster::hrw_topic(Cluster::proxy_pool, v[i]); } -event Cluster::node_up(name: string, id: string) +event Cluster::Experimental::cluster_started() { if ( Cluster::node != "manager-1" ) return; - if ( name == "proxy-1" || name == "proxy-2" ) - ++proxy_count; - - if ( proxy_count == 2 ) - { - print_stuff("1st stuff"); - local e = Broker::make_event(go_away); - Broker::publish(Cluster::node_topic("proxy-1"), e); - } + print_stuff("1st stuff"); + local e = Broker::make_event(go_away); + Broker::publish(Cluster::node_topic("proxy-1"), e); } event Cluster::node_down(name: string, id: string) diff --git a/testing/btest/scripts/base/frameworks/cluster/topic_distribution_bifs.zeek b/testing/btest/scripts/base/frameworks/cluster/topic_distribution_bifs.zeek index c75ca7c368..60511faa09 100644 --- a/testing/btest/scripts/base/frameworks/cluster/topic_distribution_bifs.zeek +++ b/testing/btest/scripts/base/frameworks/cluster/topic_distribution_bifs.zeek @@ -12,19 +12,16 @@ # @TEST-EXEC: btest-diff proxy-1/.stdout # @TEST-EXEC: btest-diff proxy-2/.stdout -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { ["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))], ["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"], ["proxy-2"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"], - ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"], - ["worker-2"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT5")), $manager="manager-1", $interface="eth1"], }; @TEST-END-FILE -global proxy_count = 0; global q = 0; event go_away() @@ -59,20 +56,14 @@ function send_stuff(heading: string) distributed_event_rr, v[i]); } -event Cluster::node_up(name: string, id: string) +event Cluster::Experimental::cluster_started() { if ( Cluster::node != "manager-1" ) return; - if ( name == "proxy-1" || name == "proxy-2" ) - ++proxy_count; - - if ( proxy_count == 2 ) - { - send_stuff("1st stuff"); - local e = Broker::make_event(go_away); - Broker::publish(Cluster::node_topic("proxy-1"), e); - } + send_stuff("1st stuff"); + local e = Broker::make_event(go_away); + Broker::publish(Cluster::node_topic("proxy-1"), e); } event Cluster::node_down(name: string, id: string) diff --git a/testing/btest/scripts/base/frameworks/config/basic_cluster.zeek b/testing/btest/scripts/base/frameworks/config/basic_cluster.zeek index accbff83c2..df0b081c06 100644 --- a/testing/btest/scripts/base/frameworks/config/basic_cluster.zeek +++ b/testing/btest/scripts/base/frameworks/config/basic_cluster.zeek @@ -12,7 +12,7 @@ # @TEST-EXEC: btest-diff manager-1/config.log @load base/frameworks/config - +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { @@ -44,7 +44,7 @@ event zeek_init() } @if ( Cluster::node == "worker-1" ) -event ready_for_data() +event Cluster::Experimental::cluster_started() { Config::set_value("testport", 44/tcp); Config::set_value("teststring", "b", "comment"); @@ -68,15 +68,3 @@ event zeek_init() &priority=5 Option::set_change_handler("testport", option_changed, -100); Option::set_change_handler("teststring", option_changed, -100); } - -@if ( Cluster::local_node_type() == Cluster::MANAGER ) - -global peer_count = 0; -event Cluster::node_up(name: string, id: string) - { - ++peer_count; - if ( peer_count == 2 ) - event ready_for_data(); - } - -@endif diff --git a/testing/btest/scripts/base/frameworks/intel/cluster-transparency-with-proxy.zeek b/testing/btest/scripts/base/frameworks/intel/cluster-transparency-with-proxy.zeek index 108663bc77..7980ca47d4 100644 --- a/testing/btest/scripts/base/frameworks/intel/cluster-transparency-with-proxy.zeek +++ b/testing/btest/scripts/base/frameworks/intel/cluster-transparency-with-proxy.zeek @@ -26,7 +26,7 @@ redef Cluster::nodes = { }; @TEST-END-FILE -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @load base/frameworks/intel module Intel; @@ -41,33 +41,12 @@ redef Intel::send_store_on_node_up = F; global log_writes = 0; global worker_data = 0; -global proxy_ready = F; global sent_data = F; -event Cluster::node_up(name: string, id: string) +event Cluster::Experimental::cluster_started() { - if ( Cluster::local_node_type() == Cluster::PROXY && - Cluster::get_active_node_count(Cluster::WORKER) == 2 ) - { - # Make the proxy tell the manager explicitly when both workers - # have checked in. The cluster framework normally generates this - # event with the Broker ID as second argument. We borrow the - # event to signal readiness, using recognizable arguments. - Broker::publish(Cluster::manager_topic, Cluster::node_up, Cluster::node, Cluster::node); - return; - } - if ( Cluster::local_node_type() == Cluster::MANAGER ) - { - if ( name == "proxy-1" && id == "proxy-1" ) - proxy_ready = T; - - # Insert data once both workers and the proxy are connected, and - # the proxy has indicated that it too has both workers connected. - if ( Cluster::get_active_node_count(Cluster::WORKER) == 2 && - Cluster::proxy_pool$alive_count == 1 && proxy_ready ) - Intel::insert([$indicator="1.2.3.4", $indicator_type=Intel::ADDR, $meta=[$source="manager"]]); - } + Intel::insert([$indicator="1.2.3.4", $indicator_type=Intel::ADDR, $meta=[$source="manager"]]); } # Watch for new indicators sent to workers. diff --git a/testing/btest/scripts/base/frameworks/intel/cluster-transparency.zeek b/testing/btest/scripts/base/frameworks/intel/cluster-transparency.zeek index 38f7cb75ae..2fd2529431 100644 --- a/testing/btest/scripts/base/frameworks/intel/cluster-transparency.zeek +++ b/testing/btest/scripts/base/frameworks/intel/cluster-transparency.zeek @@ -22,21 +22,18 @@ redef Cluster::nodes = { }; @TEST-END-FILE -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @load base/frameworks/intel module Intel; redef Log::default_rotation_interval=0sec; -event Cluster::node_up(name: string, id: string) +event Cluster::Experimental::cluster_started() { # Insert the data once both workers are connected. - if ( Cluster::local_node_type() == Cluster::MANAGER && - Cluster::get_active_node_count(Cluster::WORKER) == 2 ) - { + if ( Cluster::local_node_type() == Cluster::MANAGER ) Intel::insert([$indicator="1.2.3.4", $indicator_type=Intel::ADDR, $meta=[$source="manager"]]); - } } global log_writes = 0; diff --git a/testing/btest/scripts/base/frameworks/intel/read-file-dist-cluster.zeek b/testing/btest/scripts/base/frameworks/intel/read-file-dist-cluster.zeek index 3965214db4..833214f502 100644 --- a/testing/btest/scripts/base/frameworks/intel/read-file-dist-cluster.zeek +++ b/testing/btest/scripts/base/frameworks/intel/read-file-dist-cluster.zeek @@ -28,6 +28,7 @@ e@mail.com Intel::EMAIL source1 Phishing email source http://some-data-distribut @load base/frameworks/control @load base/frameworks/intel +@load policy/frameworks/cluster/experimental redef Log::default_rotation_interval=0sec; module Intel; @@ -55,31 +56,16 @@ event do_it() Broker::publish(Cluster::node_topic("manager-1"), do_it); } -global hi_count = 0; - event start_it() { Broker::publish(Cluster::node_topic("worker-1"), do_it); } -event hi() +event Cluster::Experimental::cluster_started() { if ( Cluster::node == "manager-1" ) - { - ++hi_count; - - if ( hi_count == 2 ) - # Give more time for intel distribution. - schedule 1sec { start_it() }; - } - else - Broker::publish(Cluster::node_topic("manager-1"), hi); - } - -event Cluster::node_up(name: string, id: string) &priority=-100 - { - if ( Cluster::node == "manager-1" ) - Broker::publish(Cluster::node_topic(name), hi); + # Give more time for intel distribution. + schedule 1sec { start_it() }; } event do_terminate() diff --git a/testing/btest/scripts/base/frameworks/intel/remove-item-cluster.zeek b/testing/btest/scripts/base/frameworks/intel/remove-item-cluster.zeek index 2be763ef7d..6ec58eefe6 100644 --- a/testing/btest/scripts/base/frameworks/intel/remove-item-cluster.zeek +++ b/testing/btest/scripts/base/frameworks/intel/remove-item-cluster.zeek @@ -9,7 +9,7 @@ # @TEST-EXEC: btest-diff manager-1/intel.log @load base/frameworks/intel -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental # @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { @@ -41,8 +41,11 @@ event test_manager() Broker::publish(Cluster::worker_topic, test_worker); } -event ready() +event Cluster::Experimental::cluster_started() { + if ( Cluster::node != "manager-1" ) + return; + # Insert the data once all workers are connected. Intel::insert([$indicator="192.168.0.1", $indicator_type=Intel::ADDR, $meta=[$source="source1"]]); Intel::insert([$indicator="192.168.0.2", $indicator_type=Intel::ADDR, $meta=[$source="source1"]]); @@ -54,12 +57,6 @@ event ready() event test_manager(); } -event Cluster::node_up(name: string, id: string) - { - if ( Cluster::node == "worker-1" ) - Broker::publish(Cluster::manager_topic, ready); - } - event Intel::remove_item(item: Item, purge_indicator: bool) { print fmt("Removing %s (source: %s).", item$indicator, item$meta$source); diff --git a/testing/btest/scripts/base/frameworks/notice/cluster.zeek b/testing/btest/scripts/base/frameworks/notice/cluster.zeek index ee7bb55273..e6b2d5e0b2 100644 --- a/testing/btest/scripts/base/frameworks/notice/cluster.zeek +++ b/testing/btest/scripts/base/frameworks/notice/cluster.zeek @@ -8,7 +8,7 @@ # @TEST-EXEC: btest-bg-wait 20 # @TEST-EXEC: btest-diff manager-1/notice.log -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @load base/frameworks/notice @TEST-START-FILE cluster-layout.zeek @@ -25,11 +25,6 @@ redef enum Notice::Type += { Test_Notice, }; -event Cluster::node_down(name: string, id: string) - { - terminate(); - } - event delayed_notice() { if ( Cluster::node == "worker-1" ) @@ -41,27 +36,16 @@ event terminate_me() terminate(); } -event ready() +event Cluster::Experimental::cluster_started() { + if ( Cluster::node != "worker-1" ) + return; + schedule 1secs { delayed_notice() }; schedule 2secs { terminate_me() }; } -@if ( Cluster::local_node_type() == Cluster::MANAGER ) - -global peer_count = 0; - -event Cluster::node_up(name: string, id: string) - { - peer_count = peer_count + 1; - - if ( peer_count == 2 ) - Broker::publish(Cluster::worker_topic, ready); - } - event Cluster::node_down(name: string, id: string) { terminate(); } - -@endif diff --git a/testing/btest/scripts/base/frameworks/notice/suppression-cluster.zeek b/testing/btest/scripts/base/frameworks/notice/suppression-cluster.zeek index 68a44e3ea2..68d4407e74 100644 --- a/testing/btest/scripts/base/frameworks/notice/suppression-cluster.zeek +++ b/testing/btest/scripts/base/frameworks/notice/suppression-cluster.zeek @@ -11,7 +11,7 @@ # @TEST-EXEC: btest-diff manager-1/notice.log @load base/frameworks/notice -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { @@ -63,14 +63,9 @@ event Notice::begin_suppression(ts: time, suppress_for: interval, note: Notice:: @if ( Cluster::local_node_type() == Cluster::MANAGER ) -global peer_count = 0; - -event Cluster::node_up(name: string, id: string) +event Cluster::Experimental::cluster_started() { - peer_count = peer_count + 1; - - if ( peer_count == 3 ) - Broker::publish(Cluster::node_topic("worker-2"), do_notice); + Broker::publish(Cluster::node_topic("worker-2"), do_notice); } global proceed_count = 0; diff --git a/testing/btest/scripts/base/frameworks/sumstats/basic-cluster.zeek b/testing/btest/scripts/base/frameworks/sumstats/basic-cluster.zeek index c486149260..bfc4800f5e 100644 --- a/testing/btest/scripts/base/frameworks/sumstats/basic-cluster.zeek +++ b/testing/btest/scripts/base/frameworks/sumstats/basic-cluster.zeek @@ -10,7 +10,7 @@ # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff manager-1/.stdout @load base/frameworks/sumstats -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { @@ -49,9 +49,7 @@ event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) terminate(); } -global ready_for_data: event(); - -event ready_for_data() +event Cluster::Experimental::cluster_started() { if ( Cluster::node == "worker-1" ) { @@ -76,22 +74,3 @@ event ready_for_data() did_data = T; } - -@if ( Cluster::local_node_type() == Cluster::MANAGER ) - -event zeek_init() &priority=100 - { - Broker::auto_publish(Cluster::worker_topic, ready_for_data); - } - -global peer_count = 0; - -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - ++peer_count; - - if ( peer_count == 2 ) - event ready_for_data(); - } - -@endif diff --git a/testing/btest/scripts/base/frameworks/sumstats/manual-epoch-cluster.zeek b/testing/btest/scripts/base/frameworks/sumstats/manual-epoch-cluster.zeek index ae7e704efe..8732b2aea9 100644 --- a/testing/btest/scripts/base/frameworks/sumstats/manual-epoch-cluster.zeek +++ b/testing/btest/scripts/base/frameworks/sumstats/manual-epoch-cluster.zeek @@ -10,7 +10,7 @@ # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff manager-1/.stdout @load base/frameworks/sumstats -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { @@ -95,7 +95,7 @@ event send_ready_for_data() } -event cont_test() +event Cluster::Experimental::cluster_started() { print "Performing first epoch, no observations"; local ret = SumStats::next_epoch("test"); @@ -110,14 +110,4 @@ event zeek_init() &priority=100 Broker::auto_publish(Cluster::worker_topic, ready_for_data); } -global peer_count = 0; - -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - ++peer_count; - - if ( peer_count == 2 ) - event cont_test(); - } - @endif diff --git a/testing/btest/scripts/base/frameworks/sumstats/on-demand-cluster.zeek b/testing/btest/scripts/base/frameworks/sumstats/on-demand-cluster.zeek index 975d4faf8c..0b4b766745 100644 --- a/testing/btest/scripts/base/frameworks/sumstats/on-demand-cluster.zeek +++ b/testing/btest/scripts/base/frameworks/sumstats/on-demand-cluster.zeek @@ -10,7 +10,7 @@ # @TEST-EXEC: btest-diff manager-1/.stdout # -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @load base/frameworks/sumstats @TEST-START-FILE cluster-layout.zeek @@ -38,8 +38,6 @@ event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) terminate(); } -global ready_for_data: event(); - event on_demand() { local host = 7.2.1.5; @@ -63,7 +61,7 @@ event ready_to_demand() event on_demand(); } -event ready_for_data() +event Cluster::Experimental::cluster_started() { if ( Cluster::node == "worker-1" ) { @@ -82,15 +80,3 @@ event ready_for_data() Broker::publish(Cluster::manager_topic, ready_to_demand); } - -global peer_count = 0; -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - if ( Cluster::node != "manager-1" ) - return; - - ++peer_count; - if ( peer_count == 2 ) - Broker::publish(Cluster::worker_topic, ready_for_data); - } - diff --git a/testing/btest/scripts/base/frameworks/sumstats/sample-cluster.zeek b/testing/btest/scripts/base/frameworks/sumstats/sample-cluster.zeek index ec1524e7a5..bc5df085e1 100644 --- a/testing/btest/scripts/base/frameworks/sumstats/sample-cluster.zeek +++ b/testing/btest/scripts/base/frameworks/sumstats/sample-cluster.zeek @@ -10,7 +10,7 @@ # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff manager-1/.stdout @load base/frameworks/sumstats -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek redef Cluster::nodes = { @@ -52,15 +52,7 @@ event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) terminate(); } -global ready_for_data: event(); - -event zeek_init() - { - Broker::auto_publish(Cluster::worker_topic, ready_for_data); - - } - -event ready_for_data() +event Cluster::Experimental::cluster_started() { if ( Cluster::node == "worker-1" ) { @@ -112,15 +104,3 @@ event ready_for_data() did_data = T; } - -@if ( Cluster::local_node_type() == Cluster::MANAGER ) - -global peer_count = 0; -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - ++peer_count; - if ( peer_count == 2 ) - event ready_for_data(); - } - -@endif diff --git a/testing/btest/scripts/base/frameworks/sumstats/topk-cluster.zeek b/testing/btest/scripts/base/frameworks/sumstats/topk-cluster.zeek index 2fb675d514..f4551f9df8 100644 --- a/testing/btest/scripts/base/frameworks/sumstats/topk-cluster.zeek +++ b/testing/btest/scripts/base/frameworks/sumstats/topk-cluster.zeek @@ -18,7 +18,7 @@ redef Cluster::nodes = { @TEST-END-FILE @load base/frameworks/sumstats -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental redef Log::default_rotation_interval = 0secs; @@ -57,14 +57,7 @@ event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) terminate(); } -global ready_for_data: event(); - -event zeek_init() - { - Broker::auto_publish(Cluster::worker_topic, ready_for_data); - } - -event ready_for_data() +event Cluster::Experimental::cluster_started() { const loop_v: vector of count = {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}; @@ -105,16 +98,3 @@ event ready_for_data() did_data = T; } - -@if ( Cluster::local_node_type() == Cluster::MANAGER ) - -global peer_count = 0; -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - ++peer_count; - if ( peer_count == 2 ) - event ready_for_data(); - } - -@endif - diff --git a/testing/btest/scripts/base/frameworks/telemetry/cluster.zeek b/testing/btest/scripts/base/frameworks/telemetry/cluster.zeek index df9ae29b32..56ea828b36 100644 --- a/testing/btest/scripts/base/frameworks/telemetry/cluster.zeek +++ b/testing/btest/scripts/base/frameworks/telemetry/cluster.zeek @@ -19,7 +19,16 @@ # @TEST-EXEC: btest-bg-wait 10 # @TEST-EXEC: btest-diff manager-1/.stdout -@load base/frameworks/cluster +@TEST-START-FILE cluster-layout.zeek +redef Cluster::nodes = { + ["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))], + ["logger-1"] = [$node_type=Cluster::LOGGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"], + ["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"], + ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"], +}; +@TEST-END-FILE + +@load policy/frameworks/cluster/experimental @load base/frameworks/telemetry @load base/utils/active-http @@ -57,8 +66,6 @@ event run_test() } } -global node_count = 0; - @if ( Cluster::node == "manager-1" ) # Use a dynamic metrics port for testing to avoid colliding on 9911/tcp # when running tests in parallel. @@ -70,14 +77,11 @@ event zeek_init() print Cluster::node, "original Broker::metrics_port", orig_metrics_port; } -event Cluster::node_up(name: string, id: string) +event Cluster::Experimental::cluster_started() { - ++node_count; - # Run the test after all nodes are up and metrics_export_interval + # Run the test once all nodes are up and metrics_export_interval # has passed at least once. - if ( Cluster::node == "manager-1" ) - if ( node_count == 3 ) - schedule 2 * Broker::metrics_export_interval { run_test() }; + schedule 2 * Broker::metrics_export_interval { run_test() }; } @endif @@ -87,12 +91,3 @@ event Cluster::node_down(name: string, id: string) print fmt("node_down on %s", Cluster::node); terminate(); } - -@TEST-START-FILE cluster-layout.zeek -redef Cluster::nodes = { - ["manager-1"] = [$node_type=Cluster::MANAGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT1"))], - ["logger-1"] = [$node_type=Cluster::LOGGER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT2")), $manager="manager-1"], - ["proxy-1"] = [$node_type=Cluster::PROXY, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT3")), $manager="manager-1"], - ["worker-1"] = [$node_type=Cluster::WORKER, $ip=127.0.0.1, $p=to_port(getenv("BROKER_PORT4")), $manager="manager-1", $interface="eth0"], -}; -@TEST-END-FILE diff --git a/testing/btest/scripts/policy/frameworks/cluster/cluster_started.zeek b/testing/btest/scripts/policy/frameworks/cluster/cluster_started.zeek index 57f2671ff5..0f91d89635 100644 --- a/testing/btest/scripts/policy/frameworks/cluster/cluster_started.zeek +++ b/testing/btest/scripts/policy/frameworks/cluster/cluster_started.zeek @@ -13,7 +13,6 @@ # @TEST-EXEC: btest-bg-wait 40 # @TEST-EXEC: btest-diff manager-1/.stdout -@load base/frameworks/cluster @load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek diff --git a/testing/btest/scripts/policy/frameworks/cluster/cluster_started_logger.zeek b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_logger.zeek index 4781f3fe03..d18bf8a4a4 100644 --- a/testing/btest/scripts/policy/frameworks/cluster/cluster_started_logger.zeek +++ b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_logger.zeek @@ -15,7 +15,6 @@ # @TEST-EXEC: btest-bg-wait 40 # @TEST-EXEC: btest-diff manager-1/.stdout -@load base/frameworks/cluster @load policy/frameworks/cluster/experimental @TEST-START-FILE cluster-layout.zeek diff --git a/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_manager.zeek b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_manager.zeek index 8e5f8a2f33..1000fa5cd7 100644 --- a/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_manager.zeek +++ b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_manager.zeek @@ -11,7 +11,6 @@ # @TEST-EXEC: btest-diff zeek/worker-1/stdout # @TEST-EXEC: btest-diff zeek/proxy-1/stdout -@load base/frameworks/cluster @load policy/frameworks/cluster/experimental # So the supervised node doesn't terminate right away. diff --git a/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_worker.zeek b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_worker.zeek index c36e136234..02a4e8d923 100644 --- a/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_worker.zeek +++ b/testing/btest/scripts/policy/frameworks/cluster/cluster_started_restart_worker.zeek @@ -12,7 +12,6 @@ # @TEST-EXEC: btest-diff zeek/worker-2/stdout # @TEST-EXEC: btest-diff zeek/proxy-1/stdout -@load base/frameworks/cluster @load policy/frameworks/cluster/experimental # So the supervised node doesn't terminate right away. diff --git a/testing/btest/scripts/policy/misc/weird-stats-cluster.zeek b/testing/btest/scripts/policy/misc/weird-stats-cluster.zeek index 9b5926bc5a..b50fa720ca 100644 --- a/testing/btest/scripts/policy/misc/weird-stats-cluster.zeek +++ b/testing/btest/scripts/policy/misc/weird-stats-cluster.zeek @@ -18,7 +18,7 @@ redef Cluster::nodes = { @TEST-END-FILE @load misc/weird-stats -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental redef Cluster::retry_interval = 1sec; redef Broker::default_listen_retry = 1sec; @@ -44,8 +44,11 @@ event ready_again() schedule 5secs { terminate_me() }; } -event ready_for_data() +event Cluster::Experimental::cluster_started() { + if ( Cluster::node == "manager-1" ) + return; + local n = 0; if ( Cluster::node == "worker-1" ) @@ -70,18 +73,3 @@ event ready_for_data() schedule 5secs { ready_again() }; } - - -@if ( Cluster::local_node_type() == Cluster::MANAGER ) - -global peer_count = 0; - -event Cluster::node_up(name: string, id: string) - { - ++peer_count; - - if ( peer_count == 2 ) - Broker::publish(Cluster::worker_topic, ready_for_data); - } - -@endif diff --git a/testing/btest/supervisor/config-cluster.zeek b/testing/btest/supervisor/config-cluster.zeek index 5be2f927ae..f551ec5044 100644 --- a/testing/btest/supervisor/config-cluster.zeek +++ b/testing/btest/supervisor/config-cluster.zeek @@ -11,14 +11,13 @@ # @TEST-EXEC: btest-diff zeek/worker-1/stdout # @TEST-EXEC: btest-diff zeek/proxy-1/stdout -@load base/frameworks/cluster +@load policy/frameworks/cluster/experimental # So the supervised node doesn't terminate right away. redef exit_only_after_terminate=T; global supervisor_output_file: file; global topic = "test-topic"; -global peer_count = 0; event shutdown() { @@ -65,19 +64,10 @@ event zeek_init() } } -event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) - { - ++peer_count; - - if ( Supervisor::is_supervised() ) - { - if ( Cluster::node == "manager" && peer_count == 4 ) - Broker::publish(topic, shutdown); - } - } - -event Broker::peer_lost(endpoint: Broker::EndpointInfo, msg: string) +event Cluster::Experimental::cluster_started() { + if ( Cluster::node == "manager" ) + Broker::publish(topic, shutdown); } event zeek_done()