This is an automated email from the ASF dual-hosted git repository. jshao pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push: new 769265419f [#6499] improvement(server): Support custom configuration options in the REST API `/configs` (#6501) 769265419f is described below commit 769265419f23de89f25f92a7aa54bbc86ba1b3df Author: roryqi <ror...@apache.org> AuthorDate: Wed Feb 26 15:23:16 2025 +0800 [#6499] improvement(server): Support custom configuration options in the REST API `/configs` (#6501) ### What changes were proposed in this pull request? Support custom configuration options in the REST API `/configs` ### Why are the changes needed? Fix: #6499 ### Does this PR introduce _any_ user-facing change? Yes. I added the document. ### How was this patch tested? Add a UT. --- .../main/java/org/apache/gravitino/Configs.java | 8 ++++++ .../apache/gravitino/config/ConfigConstants.java | 3 +++ docs/gravitino-server-config.md | 1 + .../apache/gravitino/server/web/ConfigServlet.java | 10 ++++++++ .../gravitino/server/web/TestConfigServlet.java | 30 ++++++++++++++++++++++ 5 files changed, 52 insertions(+) diff --git a/core/src/main/java/org/apache/gravitino/Configs.java b/core/src/main/java/org/apache/gravitino/Configs.java index 1a94e47e39..71a3e839e8 100644 --- a/core/src/main/java/org/apache/gravitino/Configs.java +++ b/core/src/main/java/org/apache/gravitino/Configs.java @@ -310,4 +310,12 @@ public class Configs { .version(ConfigConstants.VERSION_0_7_0) .stringConf() .createWithDefault(SimpleFormatterV2.class.getName()); + + public static final ConfigEntry<List<String>> VISIBLE_CONFIGS = + new ConfigBuilder("gravitino.server.visibleConfigs") + .doc("List of configs that are visible in the config servlet") + .version(ConfigConstants.VERSION_0_9_0) + .stringConf() + .toSequence() + .createWithDefault(Collections.emptyList()); } diff --git a/core/src/main/java/org/apache/gravitino/config/ConfigConstants.java b/core/src/main/java/org/apache/gravitino/config/ConfigConstants.java index c9be711f32..7b63b3c859 100644 --- a/core/src/main/java/org/apache/gravitino/config/ConfigConstants.java +++ b/core/src/main/java/org/apache/gravitino/config/ConfigConstants.java @@ -70,4 +70,7 @@ public final class ConfigConstants { /** The version number for the 0.8.0 release. */ public static final String VERSION_0_8_0 = "0.8.0"; + + /** The version number for the 0.9.0 release. */ + public static final String VERSION_0_9_0 = "0.9.0"; } diff --git a/docs/gravitino-server-config.md b/docs/gravitino-server-config.md index 957c3edbc3..bdcb03a939 100644 --- a/docs/gravitino-server-config.md +++ b/docs/gravitino-server-config.md @@ -37,6 +37,7 @@ The `gravitino.conf` file lists the configuration items in the following table. | `gravitino.server.shutdown.timeout` | Time in milliseconds to gracefully shut down of the Gravitino webserver. | `3000` | No | 0.2.0 | | `gravitino.server.webserver.customFilters` | Comma-separated list of filter class names to apply to the API. | (none) | No | 0.4.0 | | `gravitino.server.rest.extensionPackages` | Comma-separated list of REST API packages to expand | (none) | No | 0.6.0-incubating | +| `gravitino.server.visibleConfigs` | List of configs that are visible in the config servlet | (none) | No | 0.9.0-incubating | The filter in the customFilters should be a standard javax servlet filter. You can also specify filter parameters by setting configuration entries of the form `gravitino.server.webserver.<class name of filter>.param.<param name>=<value>`. diff --git a/server/src/main/java/org/apache/gravitino/server/web/ConfigServlet.java b/server/src/main/java/org/apache/gravitino/server/web/ConfigServlet.java index 345a555cd9..933aec3ad9 100644 --- a/server/src/main/java/org/apache/gravitino/server/web/ConfigServlet.java +++ b/server/src/main/java/org/apache/gravitino/server/web/ConfigServlet.java @@ -22,6 +22,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import java.io.IOException; import java.io.PrintWriter; +import java.util.List; import java.util.Map; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -58,6 +59,15 @@ public class ConfigServlet extends HttpServlet { configs.put(key.getKey(), serverConfig.get(key)); } } + + List<String> visibleConfigs = serverConfig.get(Configs.VISIBLE_CONFIGS); + + for (String config : visibleConfigs) { + String configValue = serverConfig.getRawString(config); + if (configValue != null) { + configs.put(config, configValue); + } + } } @Override diff --git a/server/src/test/java/org/apache/gravitino/server/web/TestConfigServlet.java b/server/src/test/java/org/apache/gravitino/server/web/TestConfigServlet.java index c76587d039..3a75185845 100644 --- a/server/src/test/java/org/apache/gravitino/server/web/TestConfigServlet.java +++ b/server/src/test/java/org/apache/gravitino/server/web/TestConfigServlet.java @@ -22,8 +22,13 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import com.google.common.collect.Lists; import java.io.PrintWriter; import javax.servlet.http.HttpServletResponse; +import org.apache.gravitino.Configs; +import org.apache.gravitino.config.ConfigBuilder; +import org.apache.gravitino.config.ConfigConstants; +import org.apache.gravitino.config.ConfigEntry; import org.apache.gravitino.server.ServerConfig; import org.junit.jupiter.api.Test; @@ -43,4 +48,29 @@ public class TestConfigServlet { "{\"gravitino.authorization.enable\":false,\"gravitino.authenticators\":[\"simple\"]}"); configServlet.destroy(); } + + @Test + public void testConfigServletWithVisibleConfigs() throws Exception { + ServerConfig serverConfig = new ServerConfig(); + + ConfigEntry<String> customConfig = + new ConfigBuilder("gravitino.extended.custom.config") + .doc("Gravitino custom config") + .version(ConfigConstants.VERSION_0_9_0) + .stringConf() + .createWithDefault("default"); + + serverConfig.set(customConfig, "test"); + serverConfig.set(Configs.VISIBLE_CONFIGS, Lists.newArrayList(customConfig.getKey())); + ConfigServlet configServlet = new ConfigServlet(serverConfig); + configServlet.init(); + HttpServletResponse res = mock(HttpServletResponse.class); + PrintWriter writer = mock(PrintWriter.class); + when(res.getWriter()).thenReturn(writer); + configServlet.doGet(null, res); + verify(writer) + .write( + "{\"gravitino.extended.custom.config\":\"test\",\"gravitino.authorization.enable\":false,\"gravitino.authenticators\":[\"simple\"]}"); + configServlet.destroy(); + } }