-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Add system properties table #18692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add system properties table #18692
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
412eb62
Add properties table
GabrielCWT 8f87895
Fix based on feedback
GabrielCWT e3eabcc
Combine rows from servers with same hostAndPort
GabrielCWT cd005de
Update tests
GabrielCWT d4ad335
Fix tests
GabrielCWT 3de794c
Revert tableMap to use ImmutableMap.of
GabrielCWT 22e9154
Separate service_name and node_roles column
GabrielCWT a9b29a2
Add embedded test
GabrielCWT 191e4ea
Use StringUtils.replace instead
GabrielCWT 5617d72
Fix embedded test
GabrielCWT 78be93c
Fix based on feedback
GabrielCWT 3d31b1d
Refactor to use ServerProperties class
GabrielCWT 2d4ca97
Revert formatting
GabrielCWT 3eb02c5
Remove unnecessary throw Exception
GabrielCWT c01a5bf
Update test to use list for node roles
GabrielCWT ec7c943
Store nodeRole in array to match SQL return format
GabrielCWT 5055b9e
Add missing import
GabrielCWT 6eefbd0
Refactor out nodeRoles.toString
GabrielCWT c55ca1e
Refactor based on feedback
GabrielCWT 935c170
Add more test cases
GabrielCWT 698894d
Update docs
GabrielCWT 0152adc
Rename to SystemServerPropertiesTable
GabrielCWT fccb86a
Update naming
GabrielCWT c60fee3
Update test
GabrielCWT 774510c
Update docs
GabrielCWT cdc5aa1
Test hidden properties
GabrielCWT 61d5f61
Fix typo
GabrielCWT ec4d324
Update docs/querying/sql-metadata-tables.md
FrankChen021 aa10bde
Merge branch 'master' into gh-65-add-sys-properties
GabrielCWT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
179 changes: 179 additions & 0 deletions
179
...c/test/java/org/apache/druid/testing/embedded/schema/SystemServerPropertiesTableTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.druid.testing.embedded.schema; | ||
|
|
||
| import com.fasterxml.jackson.core.type.TypeReference; | ||
| import com.google.common.collect.ImmutableList; | ||
| import org.apache.druid.discovery.NodeRole; | ||
| import org.apache.druid.java.util.common.StringUtils; | ||
| import org.apache.druid.rpc.RequestBuilder; | ||
| import org.apache.druid.testing.embedded.EmbeddedBroker; | ||
| import org.apache.druid.testing.embedded.EmbeddedCoordinator; | ||
| import org.apache.druid.testing.embedded.EmbeddedDruidCluster; | ||
| import org.apache.druid.testing.embedded.EmbeddedOverlord; | ||
| import org.apache.druid.testing.embedded.junit5.EmbeddedClusterTestBase; | ||
| import org.jboss.netty.handler.codec.http.HttpMethod; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Map; | ||
|
|
||
| public class SystemServerPropertiesTableTest extends EmbeddedClusterTestBase | ||
| { | ||
| private static final String BROKER_PORT = "9082"; | ||
| private static final String BROKER_SERVICE = "test/broker"; | ||
| private static final String OVERLORD_PORT = "9090"; | ||
| private static final String OVERLORD_SERVICE = "test/overlord"; | ||
| private static final String COORDINATOR_PORT = "9081"; | ||
| private static final String COORDINATOR_SERVICE = "test/coordinator"; | ||
|
|
||
| private final EmbeddedBroker broker = new EmbeddedBroker() | ||
| .addProperty("druid.service", BROKER_SERVICE) | ||
| .addProperty("druid.plaintextPort", BROKER_PORT) | ||
| .addProperty("test.onlyBroker", "brokerValue") | ||
| .addProperty("test.nonUniqueProperty", "brokerNonUniqueValue") | ||
| .addProperty("password", "brokerPassword"); | ||
|
|
||
| private final EmbeddedOverlord overlord = new EmbeddedOverlord() | ||
| .addProperty("druid.service", OVERLORD_SERVICE) | ||
| .addProperty("druid.plaintextPort", OVERLORD_PORT) | ||
| .addProperty("test.onlyOverlord", "overlordValue") | ||
| .addProperty("test.nonUniqueProperty", "overlordNonUniqueValue"); | ||
|
|
||
| private final EmbeddedCoordinator coordinator = new EmbeddedCoordinator() | ||
| .addProperty("druid.service", COORDINATOR_SERVICE) | ||
| .addProperty("druid.plaintextPort", COORDINATOR_PORT) | ||
| .addProperty("test.onlyCoordinator", "coordinatorValue") | ||
| .addProperty("test.nonUniqueProperty", "coordinatorNonUniqueValue"); | ||
|
|
||
| @Override | ||
| protected EmbeddedDruidCluster createCluster() | ||
| { | ||
| return EmbeddedDruidCluster | ||
| .withZookeeper() | ||
| .addServer(coordinator) | ||
| .addServer(overlord) | ||
| .addServer(broker) | ||
| .addCommonProperty("commonProperty", "commonValue"); | ||
| } | ||
|
|
||
| @Test | ||
| public void test_serverPropertiesTable_brokerServer() | ||
| { | ||
| final Map<String, String> brokerProps = cluster.callApi().serviceClient().onAnyBroker( | ||
| mapper -> new RequestBuilder(HttpMethod.GET, "/status/properties"), | ||
| new TypeReference<>(){} | ||
| ); | ||
| verifyPropertiesForServer(brokerProps, BROKER_SERVICE, StringUtils.format("localhost:%s", BROKER_PORT), NodeRole.BROKER_JSON_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void test_serverPropertiesTable_overlordServer() | ||
| { | ||
| final Map<String, String> overlordProps = cluster.callApi().serviceClient().onLeaderOverlord( | ||
| mapper -> new RequestBuilder(HttpMethod.GET, "/status/properties"), | ||
| new TypeReference<>(){} | ||
| ); | ||
| verifyPropertiesForServer(overlordProps, OVERLORD_SERVICE, StringUtils.format("localhost:%s", OVERLORD_PORT), NodeRole.OVERLORD_JSON_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void test_serverPropertiesTable_coordinatorServer() | ||
| { | ||
| final Map<String, String> coordinatorProps = cluster.callApi().serviceClient().onLeaderCoordinator( | ||
| mapper -> new RequestBuilder(HttpMethod.GET, "/status/properties"), | ||
| new TypeReference<>(){} | ||
| ); | ||
| verifyPropertiesForServer(coordinatorProps, COORDINATOR_SERVICE, StringUtils.format("localhost:%s", COORDINATOR_PORT), NodeRole.COORDINATOR_JSON_NAME); | ||
| } | ||
|
|
||
| @Test | ||
| public void test_serverPropertiesTable_specificProperty() | ||
| { | ||
| Assertions.assertEquals( | ||
| "brokerValue", | ||
| cluster.runSql("SELECT \"value\" FROM sys.server_properties WHERE server = 'localhost:%s' AND property = 'test.onlyBroker'", BROKER_PORT) | ||
| ); | ||
|
|
||
| Assertions.assertEquals( | ||
| "brokerValue", | ||
| cluster.runSql("SELECT \"value\" FROM sys.server_properties WHERE service_name = '%s' AND property = 'test.onlyBroker'", BROKER_SERVICE) | ||
| ); | ||
|
|
||
| Assertions.assertEquals( | ||
| StringUtils.format("localhost:%s,%s,[%s],test.onlyBroker,brokerValue", BROKER_PORT, BROKER_SERVICE, NodeRole.BROKER_JSON_NAME), | ||
| cluster.runSql("SELECT * FROM sys.server_properties WHERE server = 'localhost:%s' AND property = 'test.onlyBroker'", BROKER_PORT) | ||
| ); | ||
|
|
||
| String[] expectedRows = new String[] { | ||
| StringUtils.format("localhost:%s,%s,[%s],test.nonUniqueProperty,brokerNonUniqueValue", BROKER_PORT, BROKER_SERVICE, NodeRole.BROKER_JSON_NAME), | ||
| StringUtils.format("localhost:%s,%s,[%s],test.nonUniqueProperty,overlordNonUniqueValue", OVERLORD_PORT, OVERLORD_SERVICE, NodeRole.OVERLORD_JSON_NAME), | ||
| StringUtils.format("localhost:%s,%s,[%s],test.nonUniqueProperty,coordinatorNonUniqueValue", COORDINATOR_PORT, COORDINATOR_SERVICE, NodeRole.COORDINATOR_JSON_NAME), | ||
| }; | ||
| Arrays.sort(expectedRows, String::compareTo); | ||
| final String result = cluster.runSql("SELECT * FROM sys.server_properties WHERE property='test.nonUniqueProperty'"); | ||
| String[] actualRows = result.split("\n"); | ||
| Arrays.sort(actualRows, String::compareTo); | ||
| Assertions.assertArrayEquals(expectedRows, actualRows); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void test_serverPropertiesTable_hiddenProperties() | ||
| { | ||
| final Map<String, String> brokerProps = cluster.callApi().serviceClient().onAnyBroker( | ||
| mapper -> new RequestBuilder(HttpMethod.GET, "/status/properties"), | ||
| new TypeReference<>(){} | ||
| ); | ||
| Assertions.assertFalse(brokerProps.containsKey("password")); | ||
| } | ||
|
|
||
| private void verifyPropertiesForServer(Map<String, String> properties, String serivceName, String hostAndPort, String nodeRole) | ||
| { | ||
| String[] expectedRows = properties.entrySet().stream().map(entry -> String.join( | ||
| ",", | ||
| escapeCsvField(hostAndPort), | ||
| escapeCsvField(serivceName), | ||
| escapeCsvField(ImmutableList.of(nodeRole).toString()), | ||
| escapeCsvField(entry.getKey()), | ||
| escapeCsvField(entry.getValue()) | ||
| )).toArray(String[]::new); | ||
| Arrays.sort(expectedRows, String::compareTo); | ||
| final String result = cluster.runSql("SELECT * FROM sys.server_properties WHERE server='%s'", hostAndPort); | ||
| String[] actualRows = result.split("\n"); | ||
| Arrays.sort(actualRows, String::compareTo); | ||
| Assertions.assertArrayEquals(expectedRows, actualRows); | ||
| } | ||
|
|
||
| /** | ||
| * Escapes a field value for CSV format. | ||
| */ | ||
| private String escapeCsvField(String field) | ||
| { | ||
| if (field == null) { | ||
| return ""; | ||
| } | ||
| if (field.contains(",") || field.contains("\"") || field.contains("\n") || field.contains("\r")) { | ||
| return "\"" + StringUtils.replace(field, "\"", "\"\"") + "\""; | ||
| } | ||
| return field; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.