mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Broker::publish: Warn on using Broker::publish() when inactive
This is mostly for transitioning base scripts to Cluster::publish() and avoid silent surprises why certain things don't work when using ZeroMQ.
This commit is contained in:
parent
f674fc2634
commit
0ad3210177
6 changed files with 77 additions and 1 deletions
|
@ -109,7 +109,7 @@ public:
|
|||
/**
|
||||
* Returns true if any Broker communication is currently active.
|
||||
*/
|
||||
[[deprecated("Remove with v8.1 - unused")]] bool Active();
|
||||
bool Active();
|
||||
|
||||
/**
|
||||
* Advances time. Broker data store expiration is driven by this
|
||||
|
|
|
@ -57,8 +57,14 @@ static bool publish_event_args(ArgsSpan args, const zeek::String* topic,
|
|||
zeek::detail::Frame* frame)
|
||||
{
|
||||
zeek::Broker::Manager::ScriptScopeGuard ssg;
|
||||
zeek::ScriptLocationScope scope{frame};
|
||||
|
||||
auto rval = false;
|
||||
|
||||
if ( zeek::broker_mgr != zeek::cluster::backend && ! zeek::broker_mgr->Active() )
|
||||
zeek::reporter->Warning("Non-broker cluster backend configured and Broker manager inactive. "
|
||||
"Did you mean to use Cluster::publish() instead of Broker::publish()?");
|
||||
|
||||
if ( args[0]->GetType()->Tag() == zeek::TYPE_RECORD )
|
||||
rval = zeek::broker_mgr->PublishEvent(topic->CheckString(),
|
||||
args[0]->AsRecordVal());
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
warning in ../manager.zeek, line 8: Non-broker cluster backend configured and Broker manager inactive. Did you mean to use Cluster::publish() instead of Broker::publish()?
|
||||
warning in ../manager.zeek, line 16: Non-broker cluster backend configured and Broker manager inactive. Did you mean to use Cluster::publish() instead of Broker::publish()?
|
||||
received termination signal
|
|
@ -0,0 +1,3 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
node_up, worker-1
|
||||
node_down, worker-1
|
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
node_up, manager
|
61
testing/btest/cluster/broker/publish-warning.zeek
Normal file
61
testing/btest/cluster/broker/publish-warning.zeek
Normal file
|
@ -0,0 +1,61 @@
|
|||
# @TEST-DOC: When using ZeroMQ, Broker::publish() produces a warning.
|
||||
#
|
||||
# @TEST-REQUIRES: have-zeromq
|
||||
#
|
||||
# @TEST-GROUP: cluster-zeromq
|
||||
#
|
||||
# @TEST-PORT: XPUB_PORT
|
||||
# @TEST-PORT: XSUB_PORT
|
||||
# @TEST-PORT: LOG_PULL_PORT
|
||||
#
|
||||
# @TEST-EXEC: cp $FILES/zeromq/cluster-layout-simple.zeek cluster-layout.zeek
|
||||
# @TEST-EXEC: cp $FILES/zeromq/test-bootstrap.zeek zeromq-test-bootstrap.zeek
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-run manager "ZEEKPATH=$ZEEKPATH:.. && CLUSTER_NODE=manager zeek -b ../manager.zeek >out"
|
||||
# @TEST-EXEC: btest-bg-run worker "ZEEKPATH=$ZEEKPATH:.. && CLUSTER_NODE=worker-1 zeek -b ../worker.zeek >out"
|
||||
#
|
||||
# @TEST-EXEC: btest-bg-wait 30
|
||||
# @TEST-EXEC: btest-diff ./manager/out
|
||||
# @TEST-EXEC: btest-diff ./manager/.stderr
|
||||
# @TEST-EXEC: btest-diff ./worker/out
|
||||
|
||||
|
||||
# @TEST-START-FILE common.zeek
|
||||
@load ./zeromq-test-bootstrap
|
||||
|
||||
global finish: event(name: string);
|
||||
# @TEST-END-FILE
|
||||
|
||||
# @TEST-START-FILE manager.zeek
|
||||
@load ./common.zeek
|
||||
# If a node comes up that isn't us, send it a finish event.
|
||||
event Cluster::node_up(name: string, id: string) {
|
||||
print "node_up", name;
|
||||
Cluster::publish(Cluster::nodeid_topic(id), finish, Cluster::node);
|
||||
|
||||
# Also via broker, but this produces a warning which we test for.
|
||||
Broker::publish(Cluster::nodeid_topic(id), finish, Cluster::node);
|
||||
}
|
||||
|
||||
# If the worker vanishes, finish the test.
|
||||
event Cluster::node_down(name: string, id: string) {
|
||||
print "node_down", name;
|
||||
|
||||
# Do another Broker::publish(), just for the kicks.
|
||||
Broker::publish(Cluster::nodeid_topic(id), finish, Cluster::node);
|
||||
|
||||
terminate();
|
||||
}
|
||||
# @TEST-END-FILE
|
||||
|
||||
# @TEST-START-FILE worker.zeek
|
||||
@load ./common.zeek
|
||||
|
||||
event Cluster::node_up(name: string, id: string) {
|
||||
print "node_up", name;
|
||||
}
|
||||
|
||||
event finish(name: string) &is_used {
|
||||
terminate();
|
||||
}
|
||||
# @TEST-END-FILE
|
Loading…
Add table
Add a link
Reference in a new issue