This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch branch-2.7
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit 6bafef1beb062414196dd877dadff2bc55485b03
Author: Michael Marshall <[email protected]>
AuthorDate: Mon Mar 14 19:29:58 2022 -0500

    Fail proxy startup if brokerServiceURL is missing scheme (#14682)
    
    Make Pulsar Proxy fail on start up with a helpful error message if the 
`brokerServiceURL` or the `brokerServiceURLTLS` configurations are invalid.
    
    I recently ran into an issue where the configured URL did not have the 
`pulsar://` or the `pulsar+ssl://` prefix. It would have been very helpful if 
the proxy had just failed on startup when it had an invalid config.
    
    * Update documentation
    * Add validation checks to the `ProxyServiceStarter` class.
    
    (cherry picked from commit 342a5df24ca9dcf142e471ac0aafebc253042ceb)
    (cherry picked from commit 0a169d9f7c5c646dff1c24ba81957263579dcce8)
---
 conf/proxy.conf                                                |  3 ++-
 .../org/apache/pulsar/proxy/server/ProxyConfiguration.java     |  4 ++--
 .../org/apache/pulsar/proxy/server/ProxyServiceStarter.java    | 10 ++++++++++
 site2/docs/reference-configuration.md                          |  4 ++--
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/conf/proxy.conf b/conf/proxy.conf
index 91b01965310..5ac664ef48b 100644
--- a/conf/proxy.conf
+++ b/conf/proxy.conf
@@ -25,7 +25,8 @@ zookeeperServers=
 # Configuration store connection string (as a comma-separated list)
 configurationStoreServers=
 
-# if Service Discovery is Disabled this url should point to the discovery 
service provider.
+# If Service Discovery is Disabled this url should point to the discovery 
service provider.
+# The URL must begin with pulsar:// for plaintext or with pulsar+ssl:// for 
TLS.
 brokerServiceURL=
 brokerServiceURLTLS=
 
diff --git 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConfiguration.java
 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConfiguration.java
index a5c44ee716d..a67099306a3 100644
--- 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConfiguration.java
+++ 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyConfiguration.java
@@ -105,12 +105,12 @@ public class ProxyConfiguration implements 
PulsarConfiguration {
 
     @FieldContext(
         category = CATEGORY_BROKER_DISCOVERY,
-        doc = "The service url points to the broker cluster"
+        doc = "The service url points to the broker cluster. URL must have the 
pulsar:// prefix."
     )
     private String brokerServiceURL;
     @FieldContext(
         category = CATEGORY_BROKER_DISCOVERY,
-        doc = "The tls service url points to the broker cluster"
+        doc = "The tls service url points to the broker cluster. URL must have 
the pulsar+ssl:// prefix."
     )
     private String brokerServiceURLTLS;
 
diff --git 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
index 2a01d5b6228..cf11355daad 100644
--- 
a/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
+++ 
b/pulsar-proxy/src/main/java/org/apache/pulsar/proxy/server/ProxyServiceStarter.java
@@ -136,6 +136,16 @@ public class ProxyServiceStarter {
                 config.setConfigurationStoreServers(configurationStoreServers);
             }
 
+            if (isNotBlank(config.getBrokerServiceURL())) {
+                
checkArgument(config.getBrokerServiceURL().startsWith("pulsar://"),
+                        "brokerServiceURL must start with pulsar://");
+            }
+
+            if (isNotBlank(config.getBrokerServiceURLTLS())) {
+                
checkArgument(config.getBrokerServiceURLTLS().startsWith("pulsar+ssl://"),
+                        "brokerServiceURLTLS must start with pulsar+ssl://");
+            }
+
             if ((isBlank(config.getBrokerServiceURL()) && 
isBlank(config.getBrokerServiceURLTLS()))
                     || config.isAuthorizationEnabled()) {
                 checkArgument(!isEmpty(config.getZookeeperServers()), 
"zookeeperServers must be provided");
diff --git a/site2/docs/reference-configuration.md 
b/site2/docs/reference-configuration.md
index 67ed800984d..d03cb2eae9d 100644
--- a/site2/docs/reference-configuration.md
+++ b/site2/docs/reference-configuration.md
@@ -693,8 +693,8 @@ The [Pulsar 
proxy](concepts-architecture-overview.md#pulsar-proxy) can be config
 |forwardAuthorizationCredentials| Forward client authorization credentials to 
Broker for re-authorization, and make sure authentication is enabled for this 
to take effect. |false|
 |zookeeperServers|  The ZooKeeper quorum connection string (as a 
comma-separated list)  ||
 |configurationStoreServers| Configuration store connection string (as a 
comma-separated list) ||
-| brokerServiceURL | The service URL pointing to the broker cluster. | |
-| brokerServiceURLTLS | The TLS service URL pointing to the broker cluster | |
+| brokerServiceURL | The service URL pointing to the broker cluster. Must 
begin with `pulsar://`. | |
+| brokerServiceURLTLS | The TLS service URL pointing to the broker cluster. 
Must begin with `pulsar+ssl://`. | |
 | brokerWebServiceURL | The Web service URL pointing to the broker cluster | |
 | brokerWebServiceURLTLS | The TLS Web service URL pointing to the broker 
cluster | |
 | functionWorkerWebServiceURL | The Web service URL pointing to the function 
worker cluster. It is only configured when you setup function workers in a 
separate cluster. | |

Reply via email to