From a2249f7ecb94d22bfa4fe5dd936fca0e835911ba Mon Sep 17 00:00:00 2001 From: Arne Welzel Date: Fri, 15 Nov 2024 11:35:48 +0100 Subject: [PATCH] cluster: Add Cluster::node_id(), allow redef of node_topic(), nodeid_topic() This provides a way for non-broker cluster backends to override a node's identifier and its own topics that it listens on by default. --- scripts/base/frameworks/cluster/main.zeek | 13 ++++++++++--- .../base/frameworks/cluster/setup-connections.zeek | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/base/frameworks/cluster/main.zeek b/scripts/base/frameworks/cluster/main.zeek index 0427d6adcd..d56b4f5655 100644 --- a/scripts/base/frameworks/cluster/main.zeek +++ b/scripts/base/frameworks/cluster/main.zeek @@ -242,6 +242,13 @@ export { ## of the cluster that is started up. const node = getenv("CLUSTER_NODE") &redef; + ## Function returning this node's identifier. + ## + ## By default this is :zeek:see:`Broker::node_id`, but can be + ## redefined by other cluster backends. This identifier should be + ## a short lived identifier that resets when a node is restarted. + global node_id: function(): string = Broker::node_id &redef; + ## Interval for retrying failed connections between cluster nodes. ## If set, the ZEEK_DEFAULT_CONNECT_RETRY (given in number of seconds) ## environment variable overrides this option. @@ -270,7 +277,7 @@ export { ## ## Returns: a topic string that may used to send a message exclusively to ## a given cluster node. - global node_topic: function(name: string): string; + global node_topic: function(name: string): string &redef; ## Retrieve the topic associated with a specific node in the cluster. ## @@ -279,7 +286,7 @@ export { ## ## Returns: a topic string that may used to send a message exclusively to ## a given cluster node. - global nodeid_topic: function(id: string): string; + global nodeid_topic: function(id: string): string &redef; ## Retrieve the cluster-level naming of a node based on its node ID, ## a backend-specific identifier. @@ -446,7 +453,7 @@ event Broker::peer_added(endpoint: Broker::EndpointInfo, msg: string) &priority= if ( ! Cluster::is_enabled() ) return; - local e = Broker::make_event(Cluster::hello, node, Broker::node_id()); + local e = Broker::make_event(Cluster::hello, node, Cluster::node_id()); Broker::publish(nodeid_topic(endpoint$id), e); } diff --git a/scripts/base/frameworks/cluster/setup-connections.zeek b/scripts/base/frameworks/cluster/setup-connections.zeek index 453658067f..93d4504a6f 100644 --- a/scripts/base/frameworks/cluster/setup-connections.zeek +++ b/scripts/base/frameworks/cluster/setup-connections.zeek @@ -94,7 +94,7 @@ event zeek_init() &priority=-10 return; } - Cluster::subscribe(nodeid_topic(Broker::node_id())); + Cluster::subscribe(nodeid_topic(Cluster::node_id())); Cluster::subscribe(node_topic(node));