maytasm commented on code in PR #19011: URL: https://github.com/apache/druid/pull/19011#discussion_r2882869054
########## server/src/main/java/org/apache/druid/client/BrokerViewOfBrokerConfig.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.client; + +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.Inject; +import org.apache.druid.common.config.JacksonConfigManager; +import org.apache.druid.java.util.common.lifecycle.LifecycleStart; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.server.broker.BrokerDynamicConfig; + +import java.util.concurrent.atomic.AtomicReference; + +/** + * Broker view of broker dynamic configuration. + */ +public class BrokerViewOfBrokerConfig +{ + private static final Logger log = new Logger(BrokerViewOfBrokerConfig.class); + private final AtomicReference<BrokerDynamicConfig> config; + + @Inject + public BrokerViewOfBrokerConfig(JacksonConfigManager configManager) + { + this.config = configManager.watch( Review Comment: This should poll from the Coordinator. Brokers do not talk to the metadata store. This would be similar to BrokerViewOfCoordinatorConfig. Can we see if we can refactor common code into a base class and have BrokerViewOfCoordinatorConfig/BrokerViewOfBrokerConfig extends from the base class. ########## server/src/main/java/org/apache/druid/server/http/CoordinatorBrokerConfigsResource.java: ########## @@ -0,0 +1,259 @@ +/* + * 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.server.http; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.inject.Inject; +import com.sun.jersey.spi.container.ResourceFilters; +import org.apache.druid.audit.AuditManager; +import org.apache.druid.client.broker.BrokerClient; +import org.apache.druid.client.broker.BrokerClientImpl; +import org.apache.druid.common.config.ConfigManager.SetResult; +import org.apache.druid.common.config.JacksonConfigManager; +import org.apache.druid.discovery.DiscoveryDruidNode; +import org.apache.druid.discovery.DruidNodeDiscoveryProvider; +import org.apache.druid.discovery.NodeRole; +import org.apache.druid.guice.annotations.EscalatedGlobal; +import org.apache.druid.guice.annotations.Json; +import org.apache.druid.java.util.common.concurrent.Execs; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.rpc.FixedServiceLocator; +import org.apache.druid.rpc.ServiceClientFactory; +import org.apache.druid.rpc.ServiceLocation; +import org.apache.druid.rpc.StandardRetryPolicy; +import org.apache.druid.server.DruidNode; +import org.apache.druid.server.broker.BrokerDynamicConfig; +import org.apache.druid.server.http.security.ConfigResourceFilter; +import org.apache.druid.server.security.AuthorizationUtils; + +import javax.annotation.Nullable; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.Collection; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicReference; + +@Path("/druid/coordinator/v1/broker/config") +@ResourceFilters(ConfigResourceFilter.class) +public class CoordinatorBrokerConfigsResource +{ + private static final Logger log = new Logger(CoordinatorBrokerConfigsResource.class); + + private final JacksonConfigManager configManager; + private final AuditManager auditManager; + private final AtomicReference<BrokerDynamicConfig> currentConfig; + private final ServiceClientFactory clientFactory; + private final ObjectMapper jsonMapper; + private final DruidNodeDiscoveryProvider druidNodeDiscovery; + private final ExecutorService exec; + + @Inject + public CoordinatorBrokerConfigsResource( + JacksonConfigManager configManager, + AuditManager auditManager, + @EscalatedGlobal ServiceClientFactory clientFactory, + @Json ObjectMapper jsonMapper, + DruidNodeDiscoveryProvider druidNodeDiscoveryProvider + ) + { + this.configManager = configManager; + this.auditManager = auditManager; + this.currentConfig = configManager.watch( + BrokerDynamicConfig.CONFIG_KEY, + BrokerDynamicConfig.class, + new BrokerDynamicConfig(null) + ); + this.clientFactory = clientFactory; + this.jsonMapper = jsonMapper; + this.druidNodeDiscovery = druidNodeDiscoveryProvider; + this.exec = Execs.singleThreaded("CoordinatorBrokerConfigPush-%d"); Review Comment: where is this used? Should the pushConfigToBrokers be done using this exec so that it doesn't block calling thread? ########## server/src/main/java/org/apache/druid/server/http/CoordinatorBrokerConfigsResource.java: ########## @@ -0,0 +1,259 @@ +/* + * 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.server.http; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.inject.Inject; +import com.sun.jersey.spi.container.ResourceFilters; +import org.apache.druid.audit.AuditManager; +import org.apache.druid.client.broker.BrokerClient; +import org.apache.druid.client.broker.BrokerClientImpl; +import org.apache.druid.common.config.ConfigManager.SetResult; +import org.apache.druid.common.config.JacksonConfigManager; +import org.apache.druid.discovery.DiscoveryDruidNode; +import org.apache.druid.discovery.DruidNodeDiscoveryProvider; +import org.apache.druid.discovery.NodeRole; +import org.apache.druid.guice.annotations.EscalatedGlobal; +import org.apache.druid.guice.annotations.Json; +import org.apache.druid.java.util.common.concurrent.Execs; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.rpc.FixedServiceLocator; +import org.apache.druid.rpc.ServiceClientFactory; +import org.apache.druid.rpc.ServiceLocation; +import org.apache.druid.rpc.StandardRetryPolicy; +import org.apache.druid.server.DruidNode; +import org.apache.druid.server.broker.BrokerDynamicConfig; +import org.apache.druid.server.http.security.ConfigResourceFilter; +import org.apache.druid.server.security.AuthorizationUtils; + +import javax.annotation.Nullable; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.Collection; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicReference; + +@Path("/druid/coordinator/v1/broker/config") +@ResourceFilters(ConfigResourceFilter.class) +public class CoordinatorBrokerConfigsResource +{ + private static final Logger log = new Logger(CoordinatorBrokerConfigsResource.class); + + private final JacksonConfigManager configManager; + private final AuditManager auditManager; + private final AtomicReference<BrokerDynamicConfig> currentConfig; + private final ServiceClientFactory clientFactory; + private final ObjectMapper jsonMapper; + private final DruidNodeDiscoveryProvider druidNodeDiscovery; + private final ExecutorService exec; + + @Inject + public CoordinatorBrokerConfigsResource( + JacksonConfigManager configManager, + AuditManager auditManager, + @EscalatedGlobal ServiceClientFactory clientFactory, + @Json ObjectMapper jsonMapper, + DruidNodeDiscoveryProvider druidNodeDiscoveryProvider + ) + { + this.configManager = configManager; + this.auditManager = auditManager; + this.currentConfig = configManager.watch( + BrokerDynamicConfig.CONFIG_KEY, + BrokerDynamicConfig.class, + new BrokerDynamicConfig(null) + ); + this.clientFactory = clientFactory; + this.jsonMapper = jsonMapper; + this.druidNodeDiscovery = druidNodeDiscoveryProvider; + this.exec = Execs.singleThreaded("CoordinatorBrokerConfigPush-%d"); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + public Response getBrokerDynamicConfig() + { + return Response.ok(currentConfig.get()).build(); + } + + @POST + @Consumes(MediaType.APPLICATION_JSON) + public Response setBrokerDynamicConfig( + BrokerDynamicConfig newConfig, + @Context HttpServletRequest req + ) + { + try { + final SetResult setResult = configManager.set( + BrokerDynamicConfig.CONFIG_KEY, + newConfig, Review Comment: The current Coordinator dynamic config supports giving partial config (only updating the keys that is given in the payload and other keys are kept as-is unchanged). Can we do the same here too? i.e. building the newConfig from currentConfig + updating the keys/values from the request ########## server/src/main/java/org/apache/druid/server/http/CoordinatorBrokerConfigsResource.java: ########## @@ -0,0 +1,259 @@ +/* + * 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.server.http; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.inject.Inject; +import com.sun.jersey.spi.container.ResourceFilters; +import org.apache.druid.audit.AuditManager; +import org.apache.druid.client.broker.BrokerClient; +import org.apache.druid.client.broker.BrokerClientImpl; +import org.apache.druid.common.config.ConfigManager.SetResult; +import org.apache.druid.common.config.JacksonConfigManager; +import org.apache.druid.discovery.DiscoveryDruidNode; +import org.apache.druid.discovery.DruidNodeDiscoveryProvider; +import org.apache.druid.discovery.NodeRole; +import org.apache.druid.guice.annotations.EscalatedGlobal; +import org.apache.druid.guice.annotations.Json; +import org.apache.druid.java.util.common.concurrent.Execs; +import org.apache.druid.java.util.common.logger.Logger; +import org.apache.druid.rpc.FixedServiceLocator; +import org.apache.druid.rpc.ServiceClientFactory; +import org.apache.druid.rpc.ServiceLocation; +import org.apache.druid.rpc.StandardRetryPolicy; +import org.apache.druid.server.DruidNode; +import org.apache.druid.server.broker.BrokerDynamicConfig; +import org.apache.druid.server.http.security.ConfigResourceFilter; +import org.apache.druid.server.security.AuthorizationUtils; + +import javax.annotation.Nullable; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.util.Collection; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicReference; + +@Path("/druid/coordinator/v1/broker/config") +@ResourceFilters(ConfigResourceFilter.class) +public class CoordinatorBrokerConfigsResource Review Comment: There's a lot of repeated/common code here and CoordinatorDynamicConfigSyncer and a few repeated/common code here and CoordinatorConfigManager. Can we refactor the common code into a base class (i.e. BaseDynamicConfigSyncer) and then have CoordinatorDynamicConfigSyncer/BrokerDynamicConfigSyncer extends from the base class? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
