2525#include < boost/algorithm/string/classification.hpp>
2626#include < boost/algorithm/string/split.hpp>
2727#include < boost/algorithm/string/trim.hpp>
28+ #include < boost/algorithm/string/predicate.hpp>
2829
2930#include < ppconsul/kv.h>
3031#include < string>
@@ -54,12 +55,35 @@ class ConsulConfig : public Config {
5455 ConsulConfig (const ProcessType pProcessType, const std::string &pEndpoint, const bool pRequired = true )
5556 : Config(pProcessType), mEndpoint (pEndpoint)
5657 {
57- bool lLocalConsul = false ;
58+ const bool lEmpty = pEndpoint.empty ();
59+ const bool lNoOp = boost::starts_with (pEndpoint, " no-op" );
5860
59- if (pEndpoint.empty ()) {
60- if (pRequired) {
61+ // if not configured and not needed
62+ if (!pRequired && (lEmpty || lNoOp)) {
63+ IDDLOG (" Not connecting to a consul instance." );
64+ mConsul = nullptr ;
65+ return ;
66+ }
67+
68+ // error if not provided and required
69+ if (pRequired && lEmpty) {
70+ if (pProcessType == ProcessType::StfBuilder) {
71+ EDDLOG (" Consul endpoint is required for StfSender production use. Use 'discovery-endpoint=no-op://' for testing." );
72+ } else {
6173 EDDLOG (" Consul endpoint is mandatory for {}." , pProcessType.to_string ());
62- throw std::invalid_argument (" discovery-endpoint parameter is not provided" );
74+ }
75+ throw std::invalid_argument (" discovery-endpoint parameter is not provided" );
76+ }
77+
78+ //
79+ if (lNoOp) { // Support for CI setups without consul
80+ WDDLOG (" Consul endpoint is configured as 'no-op'. Use only for testing!" );
81+
82+ if (pRequired &&
83+ ( pProcessType == ProcessType::StfSender ||
84+ pProcessType == ProcessType::TfBuilder ||
85+ pProcessType == ProcessType::TfSchedulerInstance) ) {
86+ throw std::invalid_argument (" Error: A valid discovery-endpoint (consul) parameter must be provided." );
6387 }
6488
6589 IDDLOG (" Not connecting to a consul instance." );
@@ -75,9 +99,7 @@ class ConsulConfig : public Config {
7599 mPollThread = create_thread_member (" consul_params" , &ConsulConfig::ConsulPollingThread, this );
76100 } catch (std::exception &err) {
77101 mConsul = nullptr ;
78- if (!lLocalConsul) {
79- EDDLOG (" Error while connecting to Consul. endpoint={} what={}" , mEndpoint , err.what ());
80- }
102+ EDDLOG (" Error while connecting to Consul. endpoint={} what={}" , mEndpoint , err.what ());
81103 }
82104 }
83105
0 commit comments