You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by "mattisonchao (via GitHub)" <gi...@apache.org> on 2023/09/12 01:18:47 UTC

[GitHub] [pulsar] mattisonchao commented on a diff in pull request #21127: [improve][pip] PIP-300: Add custom dynamic configuration for plugins

mattisonchao commented on code in PR #21127:
URL: https://github.com/apache/pulsar/pull/21127#discussion_r1322255439


##########
pip/pip-300.md:
##########
@@ -0,0 +1,67 @@
+# Motivation
+
+Dynamic configuration is an important feature in the production environment, the Pulsar supports this feature,
+see `ServiceConfiguration.java`, when the field has `@FieldContext(dynamic = true)` means it is a dynamic configuration,
+and then we can use the `pulsar-admin` to update this field.
+
+The Pulsar has multiple pluggable plugins like authentication provider, authorization provider, and so on. In the
+plugin, we can get the Pulsar configurations and customized configurations, in some scenarios, we need to use
+the `pulsar-admin` to change the values of customized configuration, but the Pulsar doesn't support this operation.
+
+# Goals
+
+## In Scope
+
+The goal of this PIP is to allow the `pulsar-admin` to update the values of customized configuration.
+
+# Detailed Design
+
+## Design & Implementation Details
+
+The `org.apache.pulsar.broker.service.BrokerService.dynamicConfigurationMap` holds the dynamic configurations, so we
+just to add the configurations that need to be dynamically configured to this map, and then we can use
+the `pulsar-admin` to update the values of these configurations.
+
+Add `void registerCustomDynamicConfiguration(String key, Predicate<String> validator)` to the `BrokerService.java`:
+
+```java
+public void registerCustomDynamicConfiguration(String key, Predicate<String> validator) {
+    if (dynamicConfigurationMap.containsKey(key)) {
+        throw new IllegalArgumentException(key + " already exists in the dynamicConfigurationMap");
+    }
+    ConfigField configField = ConfigField.newCustomConfigField(null);
+    configField.validator = validator;
+    dynamicConfigurationMap.put(key, configField);
+}
+```
+
+Example of using this feature in the plugin:
+
+```java
+@Override
+public void initialize(PulsarService pulsarService) throws Exception {
+    String myAuthIdKey = "my-auth-id";
+    myAuthIdValue = pulsarService.getConfiguration().getProperties().getProperty(myAuthIdKey);
+
+    pulsarService.getBrokerService().registerCustomDynamicConfiguration(myAuthIdKey, null);
+    pulsarService.getBrokerService().registerConfigurationListener(myAuthIdKey, (newValue) -> {
+        // The `myAuthIdKey` value has changed
+        myAuthIdValue = String.valueOf(newValue);
+    });
+}
+```
+
+
+# Backward & Forward Compatibility
+
+## Revert
+
+Pulsar 2.10 is an important version, so I suggest we need to cherry-pick this feature to the old version.

Review Comment:
   What do you mean by "important"? Could you please provide a specific case to demonstrate this feature should cherry-pick to previous branches? :) 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org