You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by "mshahid6 (via GitHub)" <gi...@apache.org> on 2026/02/11 06:00:00 UTC
[PR] Broker Dynamic Config and Query Blocklist (druid)
mshahid6 opened a new pull request, #19011:
URL: https://github.com/apache/druid/pull/19011
Fixes #18964
### Description
Added a broker level dynamic config and query blocklist for dynamically blocking queries in the situation there is a rogue app/user spamming the cluster without relying on static configs/restarts.
#### BrokerDynamicConfig
Followed a similar pattern to CoordinatorDynamicConfig. REST APIs:
- GET /druid/broker/v1/config: get current config
- POST /druid/broker/v1/config: set config
Can also be used for features like query blocklist enforcement, data aliases, routing rules, feature flags etc.
#### QueryBlocklistRule
Enforced early in QueryLifecycle (after init) and throws DruidException when a query matches a rule i.e. if ALL specified criteria match (AND logic). Null or empty criteria act as wildcards (match everything):
- `dataSources`: Matches if ANY datasource in the query intersects with the rule's datasources
- `queryTypes`: Matches if the query type is in the rule's query types
- `contextMatches`: Matches if ALL key-value pairs in the rule match the query context (exact string match)
Reusing coordinator dynamic config for query blocklisting was considered but it is not the appropriate enforcement point and would require broker to pull coordinator config. Moreover, broker config can be used for other future features such as datasource aliasing, routing rules or feature flags.
#### Release note
Added broker-level query blocklist feature for dynamically blocking queries without restarts. Operators can block queries by datasource, query type, or query context using the new /druid/broker/v1/config API. Rules use AND logic (all criteria must match) and are stored in the metadata database.
##### Key changed/added classes in this PR
- BrokerDynamicConfig - Dynamic configuration class with query blocklist
- QueryBlocklistRule - Rule-based query matching with validation
- BrokerConfigManager - Manager for getting/setting broker config from metadata database
- BrokerDynamicConfigsResource - REST endpoints for config management
- QueryLifecycle - Added blocklist enforcement before authorization
- QueryLifecycleFactory - Added BrokerConfigManager injection
- QueryBlocklistRuleTest
- QueryLifecycleTest
This PR has:
- [ ] been self-reviewed.
- [ ] using the [concurrency checklist](https://github.com/apache/druid/blob/master/dev/code-review/concurrency.md) (Remove this item if the PR doesn't have any relation to concurrency.)
- [ ] added documentation for new or modified features or behaviors.
- [ ] a release note entry in the PR description.
- [ ] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
- [ ] added or updated version, license, or notice information in [licenses.yaml](https://github.com/apache/druid/blob/master/dev/license.md)
- [ ] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
- [ ] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for [code coverage](https://github.com/apache/druid/blob/master/dev/code-review/code-coverage.md) is met.
- [ ] added integration tests.
- [ ] been tested in a test Druid cluster.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "maytasm (via GitHub)" <gi...@apache.org>.
maytasm commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2902600094
##########
server/src/main/java/org/apache/druid/server/http/BrokerDynamicConfigSyncer.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.common.config.JacksonConfigManager;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+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.emitter.service.ServiceEmitter;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.broker.BrokerDynamicConfig;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Syncs broker dynamic configuration to all brokers.
+ */
+public class BrokerDynamicConfigSyncer extends BaseDynamicConfigSyncer<BrokerDynamicConfig>
+{
+ private final AtomicReference<BrokerDynamicConfig> currentConfig;
+
+ @Inject
+ public BrokerDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final JacksonConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider,
+ final ServiceEmitter emitter
+ )
+ {
+ super(
+ clientFactory,
+ jsonMapper,
+ druidNodeDiscoveryProvider,
+ emitter,
+ Execs.scheduledSingleThreaded("BrokerDynamicConfigSyncer-%d")
+ );
+ this.currentConfig = configManager.watch(
+ BrokerDynamicConfig.CONFIG_KEY,
+ BrokerDynamicConfig.class,
+ new BrokerDynamicConfig(null)
Review Comment:
nit: use Builder
##########
server/src/main/java/org/apache/druid/server/http/BrokerDynamicConfigSyncer.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.common.config.JacksonConfigManager;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+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.emitter.service.ServiceEmitter;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.broker.BrokerDynamicConfig;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Syncs broker dynamic configuration to all brokers.
+ */
+public class BrokerDynamicConfigSyncer extends BaseDynamicConfigSyncer<BrokerDynamicConfig>
+{
+ private final AtomicReference<BrokerDynamicConfig> currentConfig;
+
+ @Inject
+ public BrokerDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final JacksonConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider,
+ final ServiceEmitter emitter
+ )
+ {
+ super(
+ clientFactory,
+ jsonMapper,
+ druidNodeDiscoveryProvider,
+ emitter,
+ Execs.scheduledSingleThreaded("BrokerDynamicConfigSyncer-%d")
+ );
+ this.currentConfig = configManager.watch(
+ BrokerDynamicConfig.CONFIG_KEY,
+ BrokerDynamicConfig.class,
+ new BrokerDynamicConfig(null)
Review Comment:
nit: use Builder
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2880245177
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorBrokerConfigsResource.java:
##########
@@ -0,0 +1,252 @@
+/*
+ * 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.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 {
+ configManager.set(
+ BrokerDynamicConfig.CONFIG_KEY,
+ newConfig,
+ AuthorizationUtils.buildAuditInfo(req)
+ );
+
+ // Push config to all brokers synchronously (with short timeout) for immediate effect
+ pushConfigToBrokers(newConfig);
+
+ return Response.ok().build();
+ }
+ catch (Exception e) {
+ log.error(e, "Failed to set broker dynamic config");
+ return Response.serverError().entity(e.getMessage()).build();
Review Comment:
## Information exposure through an error message
[Error information](1) can be exposed to an external user.
[Error information](2) can be exposed to an external user.
[Error information](3) can be exposed to an external user.
[Show more details](https://github.com/apache/druid/security/code-scanning/10855)
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2801425048
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
Review Comment:
~~I think we should negate this. Queries matching all criteria in the `QueryBlocklistRule` are blocked, and those that do not match are not blocked.~~
Ah – NVM, this is an AND. Ignore
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2843484142
##########
server/src/main/java/org/apache/druid/server/QueryLifecycle.java:
##########
@@ -134,6 +138,7 @@ public QueryLifecycle(
this.defaultQueryConfig = defaultQueryConfig;
this.authConfig = authConfig;
this.policyEnforcer = policyEnforcer;
+ this.brokerViewOfCoordinatorConfig = brokerViewOfCoordinatorConfig;
Review Comment:
nit: maybe add small comment saying this can only be `null` if not running on the broker
##########
server/src/test/java/org/apache/druid/segment/metadata/SegmentMetadataCacheTestBase.java:
##########
@@ -292,7 +292,8 @@ public QueryLifecycleFactory getQueryLifecycleFactory(QuerySegmentWalker walker)
new AuthConfig(),
NoopPolicyEnforcer.instance(),
AuthTestUtils.TEST_AUTHORIZER_MAPPER,
- Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of()))
+ Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of())),
Review Comment:
one more 😅 ImmutableMap -> Map.of()
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2834796586
##########
server/src/test/java/org/apache/druid/server/QueryBlocklistRuleTest.java:
##########
@@ -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.server;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.apache.druid.query.Druids;
+import org.apache.druid.query.timeseries.TimeseriesQuery;
+import org.junit.Assert;
+import org.junit.Test;
+import java.util.Map;
+import java.util.Set;
+
+public class QueryBlocklistRuleTest
+{
+ @Test
+ public void testMatchAllCriteria_rejectsNullCriteria()
+ {
+ // Rule with all null criteria would block ALL queries - this should be rejected
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> new QueryBlocklistRule("match-all", null, null, null)
+ );
+ }
+
+ @Test
+ public void testMatchAllCriteria_rejectsEmptyCollections()
+ {
+ // Rule with all empty collections should also be rejected (same as null)
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> new QueryBlocklistRule("match-all", ImmutableSet.of(), ImmutableSet.of(), ImmutableMap.of())
+ );
+ }
+
+ @Test
+ public void testMatchByDataSource()
+ {
+ Set<String> dataSources = ImmutableSet.of("sensitive_data", "pii_table");
+ QueryBlocklistRule rule = new QueryBlocklistRule("block-sensitive", dataSources, null, null);
+
+ // Should match when datasource is in the list
+ TimeseriesQuery matchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("sensitive_data")
+ .intervals("2020-01-01/2020-01-02")
+ .build();
+ Assert.assertTrue(rule.matches(matchingQuery));
+
+ // Should not match when datasource is not in the list
+ TimeseriesQuery nonMatchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("safe_data")
+ .intervals("2020-01-01/2020-01-02")
+ .build();
+ Assert.assertFalse(rule.matches(nonMatchingQuery));
+ }
+
+ @Test
+ public void testMatchByContext()
+ {
+ Map<String, String> contextMatches = ImmutableMap.of("priority", "0", "application", "rogue-app");
+ QueryBlocklistRule rule = new QueryBlocklistRule("block-rogue-app", null, null, contextMatches);
+
+ // Should match when all context values match
+ TimeseriesQuery matchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("test")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "0", "application", "rogue-app"))
+ .build();
+ Assert.assertTrue(rule.matches(matchingQuery));
+
+ // Should not match when context values don't match
+ TimeseriesQuery nonMatchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("test")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "1", "application", "rogue-app"))
+ .build();
+ Assert.assertFalse(rule.matches(nonMatchingQuery));
+
+ // Should not match when context is missing
+ TimeseriesQuery noContextQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("test")
+ .intervals("2020-01-01/2020-01-02")
+ .build();
+ Assert.assertFalse(rule.matches(noContextQuery));
+ }
+
+ @Test
+ public void testMatchByMultipleCriteria()
+ {
+ // Rule with multiple criteria - all must match (AND logic)
+ Set<String> dataSources = ImmutableSet.of("large_table");
+ Map<String, String> contextMatches = ImmutableMap.of("priority", "0");
+ QueryBlocklistRule rule = new QueryBlocklistRule(
+ "block-low-priority-large-table",
+ dataSources,
+ null,
+ contextMatches
+ );
+
+ // Should match when both datasource AND context match
+ TimeseriesQuery matchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("large_table")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "0"))
+ .build();
+ Assert.assertTrue(rule.matches(matchingQuery));
+
+ // Should not match when only datasource matches
+ TimeseriesQuery onlyDataSourceMatches = Druids.newTimeseriesQueryBuilder()
+ .dataSource("large_table")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "1"))
+ .build();
+ Assert.assertFalse(rule.matches(onlyDataSourceMatches));
+
+ // Should not match when only context matches
+ TimeseriesQuery onlyContextMatches = Druids.newTimeseriesQueryBuilder()
+ .dataSource("small_table")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "0"))
+ .build();
+ Assert.assertFalse(rule.matches(onlyContextMatches));
+ }
+
+ @Test
+ public void testWildcardBehavior_nullQueryTypes()
+ {
+ QueryBlocklistRule rule = new QueryBlocklistRule(
+ "block-datasource-all-types",
+ ImmutableSet.of("blocked_ds"),
+ null, // null means match all query types
Review Comment:
It might be worth specifying in the docs that `null` values in the other 2 parameters will default to match all (`*`) behavior when evaluating.
##########
sql/src/test/java/org/apache/druid/sql/calcite/util/QueryFrameworkUtils.java:
##########
@@ -102,7 +102,8 @@ public static QueryLifecycleFactory createMockQueryLifecycleFactory(
new AuthConfig(),
NoopPolicyEnforcer.instance(),
authorizerMapper,
- Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of()))
+ Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of())),
Review Comment:
nit: `ImmutableMap.of() -> Map.of()`
##########
server/src/test/java/org/apache/druid/server/QueryResourceTest.java:
##########
@@ -1400,7 +1411,8 @@ public Access authorize(AuthenticationResult authenticationResult, Resource reso
new AuthConfig(),
NoopPolicyEnforcer.instance(),
authMapper,
- Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of()))
+ Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of())),
Review Comment:
same
##########
server/src/test/java/org/apache/druid/server/QueryResourceTest.java:
##########
@@ -1789,7 +1801,8 @@ public <T> QueryRunner<T> getQueryRunnerForSegments(Query<T> query, Iterable<Seg
new AuthConfig(),
NoopPolicyEnforcer.instance(),
AuthTestUtils.TEST_AUTHORIZER_MAPPER,
- Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of()))
+ Suppliers.ofInstance(new DefaultQueryConfig(ImmutableMap.of())),
Review Comment:
same as below
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ private final boolean hasDataSourceCriteria;
+ private final boolean hasQueryTypeCriteria;
+ private final boolean hasContextCriteria;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
+ this.hasDataSourceCriteria = dataSources != null && !dataSources.isEmpty();
+ this.hasQueryTypeCriteria = queryTypes != null && !queryTypes.isEmpty();
+ this.hasContextCriteria = contextMatches != null && !contextMatches.isEmpty();
+
+ Preconditions.checkArgument(
+ hasDataSourceCriteria || hasQueryTypeCriteria || hasContextCriteria,
+ "At least one criterion (dataSources, queryTypes, or contextMatches) must be specified. "
+ + "A rule with all null/empty criteria would block ALL queries."
+ );
+
+ this.ruleName = ruleName;
+ this.dataSources = dataSources;
+ this.queryTypes = queryTypes;
+ this.contextMatches = contextMatches;
+ }
+
+ @JsonProperty
+ public String getRuleName()
+ {
+ return ruleName;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getDataSources()
+ {
+ return dataSources;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getQueryTypes()
+ {
+ return queryTypes;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Map<String, String> getContextMatches()
+ {
+ return contextMatches;
+ }
+
+ /**
+ * Returns true if the query matches ALL specified criteria (AND logic).
+ * Null or empty criteria match everything.
+ *
+ * @param query the query to check
+ * @return true if the query matches this rule, false otherwise
+ */
+ public boolean matches(Query<?> query)
+ {
+ if (hasDataSourceCriteria) {
+ Set<String> queryDatasources = query.getDataSource().getTableNames();
+ if (Sets.intersection(dataSources, queryDatasources).isEmpty()) {
+ return false;
+ }
+ }
+
+ if (hasQueryTypeCriteria) {
+ if (!queryTypes.contains(query.getType())) {
+ return false;
+ }
+ }
+
+ if (hasContextCriteria) {
+ for (Map.Entry<String, String> entry : contextMatches.entrySet()) {
+ Object contextValue = query.getContext().get(entry.getKey());
+ if (!entry.getValue().equals(String.valueOf(contextValue))) {
Review Comment:
Unless we're restricting the possible value set, this will NPE if the `contextValue` is `null`. While this isn't a typical context value, it's still valid context. I think we should be a bit more graceful and return a 200 or 403 depending on how we want to handle the `null` in contextValue(in other fields, we do as match-all for example).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2801523931
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
Review Comment:
Ah – NVM, this is an AND. Ignore
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
+ boolean hasDataSources = dataSources != null && !dataSources.isEmpty();
+ boolean hasQueryTypes = queryTypes != null && !queryTypes.isEmpty();
+ boolean hasContextMatches = contextMatches != null && !contextMatches.isEmpty();
+
+ Preconditions.checkArgument(
+ hasDataSources || hasQueryTypes || hasContextMatches,
+ "At least one criterion (dataSources, queryTypes, or contextMatches) must be specified. "
+ + "A rule with all null/empty criteria would block ALL queries."
+ );
+
+ this.ruleName = ruleName;
+ this.dataSources = dataSources;
+ this.queryTypes = queryTypes;
+ this.contextMatches = contextMatches;
+ }
+
+ @JsonProperty
+ public String getRuleName()
+ {
+ return ruleName;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getDataSources()
+ {
+ return dataSources;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getQueryTypes()
+ {
+ return queryTypes;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Map<String, String> getContextMatches()
+ {
+ return contextMatches;
+ }
+
+ /**
+ * Returns true if the query matches ALL specified criteria (AND logic).
+ * Null or empty criteria match everything.
+ *
+ * @param query the query to check
+ * @return true if the query matches this rule, false otherwise
+ */
+ public boolean matches(Query<?> query)
+ {
+ if (!isNullOrEmpty(dataSources)) {
+ Set<String> queryDatasources = query.getDataSource().getTableNames();
+ if (Sets.intersection(dataSources, queryDatasources).isEmpty()) {
+ return false;
+ }
+ }
+
+ if (!isNullOrEmpty(queryTypes)) {
+ if (!queryTypes.contains(query.getType())) {
+ return false;
+ }
+ }
+
+ if (contextMatches != null && !contextMatches.isEmpty()) {
+ for (Map.Entry<String, String> entry : contextMatches.entrySet()) {
+ Object contextValue = query.getContext().get(entry.getKey());
+ if (!entry.getValue().equals(String.valueOf(contextValue))) {
+ return false;
+ }
+ }
+ }
+
+ return true;
Review Comment:
I think we should invert this. Ideally, a rule matching a query <==> that query is blocked. i.e matches should return `false` by default.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on PR #19011:
URL: https://github.com/apache/druid/pull/19011#issuecomment-3894903744
Another thing I forgot to mention is let's add some docs for this, namely:
1. Add the root field to the coordinator dynamic config description, explaining what it does.
2. Separate documentation section for the rulesets. What the rule format looks like (description of each field, its default, etc.). The AND logic between the fields' predicates.
3. For completeness since coordinator config already in UI, do we want to add this as a field? Should be pretty simple to do with an AI tool.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2801526380
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
Review Comment:
I think this is moot given the above
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
Review Comment:
I think this is moot given the above, ignore.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 merged PR #19011:
URL: https://github.com/apache/druid/pull/19011
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "gianm (via GitHub)" <gi...@apache.org>.
gianm commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2876782438
##########
server/src/main/java/org/apache/druid/server/QueryLifecycle.java:
##########
@@ -159,6 +164,8 @@ public <T> QueryResponse<T> runSimple(
{
initialize(query);
+ checkQueryBlocklist();
Review Comment:
`runSimple` is not always used, which means the blocklist won't always be checked if the call is put here. Some usages of `QueryLifecycle` call the methods individually.
IMO best to put it in `doAuthorize`. This method is always called-- it's the only place the state can transition to `AUTHORIZED`.
It would also work to put it in `execute`.
##########
server/src/main/java/org/apache/druid/server/coordinator/CoordinatorDynamicConfig.java:
##########
@@ -351,6 +360,17 @@ public Set<String> getTurboLoadingNodes()
return turboLoadingNodes;
}
+ /**
+ * List of query blocklist rules for dynamically blocking queries on brokers.
+ *
+ * @return List of query blocklist rules
+ */
+ @JsonProperty
+ public List<QueryBlocklistRule> getQueryBlocklist()
Review Comment:
Please make this `@JsonInclude(NON_EMPTY)` so it is skipped from the serialized form of config if not present. Keeps things cleaner.
##########
docs/configuration/index.md:
##########
@@ -838,6 +838,73 @@ The following table shows the dynamic configuration properties for the Coordinat
|`replicateAfterLoadTimeout`|Boolean flag for whether or not additional replication is needed for segments that have failed to load due to the expiry of `druid.coordinator.load.timeout`. If this is set to true, the Coordinator will attempt to replicate the failed segment on a different historical server. This helps improve the segment availability if there are a few slow Historicals in the cluster. However, the slow Historical may still load the segment later and the Coordinator may issue drop requests if the segment is over-replicated.|false|
|`turboLoadingNodes`| Experimental. List of Historical servers to place in turbo loading mode. These servers use a larger thread-pool to load segments faster but at the cost of query performance. For servers specified in `turboLoadingNodes`, `druid.coordinator.loadqueuepeon.http.batchSize` is ignored and the coordinator uses the value of the respective `numLoadingThreads` instead.<br/>Please use this config with caution. All servers should eventually be removed from this list once the segment loading on the respective historicals is finished. |none|
|`cloneServers`| Experimental. Map from target Historical server to source Historical server which should be cloned by the target. The target Historical does not participate in regular segment assignment or balancing. Instead, the Coordinator mirrors any segment assignment made to the source Historical onto the target Historical, so that the target becomes an exact copy of the source. Segments on the target Historical do not count towards replica counts either. If the source disappears, the target remains in the last known state of the source server until removed from the configuration. <br/>Use this config with caution. All servers should eventually be removed from this list once the desired state on the respective Historicals is achieved. |none|
+|`queryBlocklist`| List of rules to block queries based on datasource, query type, and/or query context parameters. Each rule defines criteria that are combined with AND logic. Blocked queries return an HTTP 403 error. See [Query blocklist rules](#query-blocklist-rules) for details.|none|
+
+##### Query blocklist rules
+
+Query blocklist rules allow you to block specific queries based on datasource, query type, and/or query context parameters. This feature is useful for preventing expensive or problematic queries from impacting cluster performance.
Review Comment:
The documentation should mention that blocking is best-effort, and may not be applied in certain cases (such as if the Broker has recently started up, can't contact the Coordinator, etc).
##########
docs/configuration/index.md:
##########
@@ -838,6 +838,73 @@ The following table shows the dynamic configuration properties for the Coordinat
|`replicateAfterLoadTimeout`|Boolean flag for whether or not additional replication is needed for segments that have failed to load due to the expiry of `druid.coordinator.load.timeout`. If this is set to true, the Coordinator will attempt to replicate the failed segment on a different historical server. This helps improve the segment availability if there are a few slow Historicals in the cluster. However, the slow Historical may still load the segment later and the Coordinator may issue drop requests if the segment is over-replicated.|false|
|`turboLoadingNodes`| Experimental. List of Historical servers to place in turbo loading mode. These servers use a larger thread-pool to load segments faster but at the cost of query performance. For servers specified in `turboLoadingNodes`, `druid.coordinator.loadqueuepeon.http.batchSize` is ignored and the coordinator uses the value of the respective `numLoadingThreads` instead.<br/>Please use this config with caution. All servers should eventually be removed from this list once the segment loading on the respective historicals is finished. |none|
|`cloneServers`| Experimental. Map from target Historical server to source Historical server which should be cloned by the target. The target Historical does not participate in regular segment assignment or balancing. Instead, the Coordinator mirrors any segment assignment made to the source Historical onto the target Historical, so that the target becomes an exact copy of the source. Segments on the target Historical do not count towards replica counts either. If the source disappears, the target remains in the last known state of the source server until removed from the configuration. <br/>Use this config with caution. All servers should eventually be removed from this list once the desired state on the respective Historicals is achieved. |none|
+|`queryBlocklist`| List of rules to block queries based on datasource, query type, and/or query context parameters. Each rule defines criteria that are combined with AND logic. Blocked queries return an HTTP 403 error. See [Query blocklist rules](#query-blocklist-rules) for details.|none|
+
+##### Query blocklist rules
+
+Query blocklist rules allow you to block specific queries based on datasource, query type, and/or query context parameters. This feature is useful for preventing expensive or problematic queries from impacting cluster performance.
+
+Each rule in the `queryBlocklist` array is a JSON object with the following properties:
+
+|Property|Description|Required|Default|
+|--------|-----------|--------|-------|
+|`ruleName`|Unique name identifying this blocklist rule. Used in error messages when queries are blocked.|Yes|N/A|
+|`dataSources`|List of datasource names to match. A query matches if it references any datasource in this list.|No|Matches all datasources|
+|`queryTypes`|List of query types to match (e.g., `scan`, `timeseries`, `groupBy`, `topN`). A query matches if its type is in this list.|No|Matches all query types|
Review Comment:
I don't see a test for this `queryTypes` feature. Please add one.
##########
server/src/main/java/org/apache/druid/server/QueryLifecycle.java:
##########
@@ -121,6 +124,7 @@ public QueryLifecycle(
final DefaultQueryConfig defaultQueryConfig,
final AuthConfig authConfig,
final PolicyEnforcer policyEnforcer,
+ @Nullable final BrokerViewOfCoordinatorConfig brokerViewOfCoordinatorConfig,
Review Comment:
Better to keep things targeted and only pass in the `List<QueryBlocklistRule>`. It makes usage and testing easier.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2801433893
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
Review Comment:
~~This seems backwards to me. In my mind, passing all nulls should result in the default behavior. In other words, I need to "opt-in" to the blocking behavior.~~
~~IMO, we should make it easier for users to do the "default" thing which is allowing the query through. A rule matching a query <===> that query is blocked. Right now, it's the other way around.~~
NVM.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "maytasm (via GitHub)" <gi...@apache.org>.
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: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2909658206
##########
server/src/main/java/org/apache/druid/client/coordinator/CoordinatorClientImpl.java:
##########
@@ -253,6 +254,22 @@ public ListenableFuture<CoordinatorDynamicConfig> getCoordinatorDynamicConfig()
);
}
+ @Override
+ public ListenableFuture<BrokerDynamicConfig> getBrokerDynamicConfig()
+ {
+ return FutureUtils.transform(
+ client.asyncRequest(
+ new RequestBuilder(HttpMethod.GET, "/druid/coordinator/v1/broker/config"),
+ new BytesFullResponseHandler()
+ ),
+ holder -> JacksonUtils.readValue(
Review Comment:
Looks like this change is causing `org.apache.druid.testing.embedded.docker.IngestionBackwardCompatibilityDockerTest` to fail consistently (which seems like it would be a legit issue during rolling upgrades since the Coordinators are typically upgraded in the end).
I haven't looked at the surrounding code here, but either this code here or the caller needs to account for `/druid/coordinator/v1/broker/config` endpoint not yet available on the Coordinators yet during rolling upgrades in a backward compatible manner.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on PR #19011:
URL: https://github.com/apache/druid/pull/19011#issuecomment-4029052713
Yes, I think `getBrokerDynamicConfig()` needs to [account](https://github.com/apache/druid/blob/master/server/src/main/java/org/apache/druid/client/coordinator/CoordinatorClientImpl.java#L262) for `/druid/coordinator/v1/broker/config` endpoint not available on the Coordinator yet during rolling upgrades.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2898545575
##########
server/src/main/java/org/apache/druid/server/http/BaseDynamicConfigSyncer.java:
##########
@@ -0,0 +1,275 @@
+/*
+ * 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.common.annotations.VisibleForTesting;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.client.broker.BrokerClientImpl;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.java.util.common.Stopwatch;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStop;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
+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.coordinator.stats.CoordinatorStat;
+import org.apache.druid.server.coordinator.stats.Dimension;
+import org.apache.druid.server.coordinator.stats.RowKey;
+import org.apache.druid.server.coordinator.stats.Stats;
+
+import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Base class for syncing dynamic configuration to all brokers.
+ * Subclasses must implement:
+ * - {@link #getCurrentConfig()} to provide the latest config
+ * - {@link #pushConfigToBroker(BrokerClient, Object)} to push config via the appropriate BrokerClient method
+ * - {@link #getConfigTypeName()} for logging
+ *
+ * @param <T> the type of dynamic configuration (e.g., CoordinatorDynamicConfig, BrokerDynamicConfig)
+ */
+public abstract class BaseDynamicConfigSyncer<T>
+{
+ private static final Logger log = new Logger(BaseDynamicConfigSyncer.class);
+
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+ private final ServiceClientFactory clientFactory;
+ private final ScheduledExecutorService exec;
+ private final ServiceEmitter emitter;
+ private @Nullable Future<?> syncFuture = null;
+
+ @GuardedBy("this")
+ private final Set<BrokerSyncStatus> inSyncBrokers;
+ private final AtomicReference<T> lastKnownConfig = new AtomicReference<>();
+
+ protected BaseDynamicConfigSyncer(
+ final ServiceClientFactory clientFactory,
+ final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider,
+ final ServiceEmitter emitter,
+ final ScheduledExecutorService exec
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.emitter = emitter;
+ this.exec = exec;
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ /**
+ * Get the current configuration to broadcast to brokers.
+ */
+ protected abstract T getCurrentConfig();
+
+ /**
+ * Push the config to a broker using the appropriate BrokerClient method.
+ * @return true if the push was successful
+ */
+ protected abstract boolean pushConfigToBroker(BrokerClient brokerClient, T config) throws Exception;
+
+ /**
+ * Get the name of this config type for logging (e.g., "coordinator dynamic configuration", "broker dynamic configuration").
+ */
+ protected abstract String getConfigTypeName();
+
+ /**
+ * Queues the configuration sync to the brokers without blocking the calling thread.
+ */
+ public void queueBroadcastConfigToBrokers()
+ {
+ exec.submit(this::broadcastConfigToBrokers);
+ }
+
+ /**
+ * Push the latest dynamic config to all currently known Brokers. Also
+ * invalidates the set of inSyncBrokers if the config has changed.
+ */
+ @VisibleForTesting
+ public void broadcastConfigToBrokers()
+ {
+ invalidateInSyncBrokersIfNeeded();
+ final Stopwatch stopwatch = Stopwatch.createStarted();
+ for (DiscoveryDruidNode broker : getKnownBrokers()) {
+ pushConfigToBrokerNode(broker);
+ }
+ emitStat(
+ Stats.Configuration.TOTAL_SYNC_TIME,
+ RowKey.empty(),
+ stopwatch.millisElapsed()
+ );
+ }
+
+ /**
+ * Returns the set of Brokers which have been updated with the latest config.
+ */
+ public synchronized Set<BrokerSyncStatus> getInSyncBrokers()
+ {
+ return Set.copyOf(inSyncBrokers);
+ }
+
+ /**
+ * Schedules a periodic sync with brokers when the coordinator becomes the leader.
+ */
+ public void onLeaderStart()
+ {
+ log.info("Starting %s syncing to brokers on leader node.", getConfigTypeName());
Review Comment:
nit: `Starting syncing config [%s] to brokers on leader node`
##########
docs/configuration/index.md:
##########
@@ -1862,6 +1862,89 @@ queries in order to avoid running as a default priority of 0.
|--------|-----------|-------|
|`druid.broker.internal.query.config.context`|A string formatted `key:value` map of a query context to add to internally generated broker queries.|null|
+#### Dynamic configuration
Review Comment:
let's move this section to `docs/api-reference/dynamic-configuration-api.md`.
##########
server/src/main/java/org/apache/druid/server/http/BrokerDynamicConfigSyncer.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.common.config.JacksonConfigManager;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+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.emitter.service.ServiceEmitter;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.broker.BrokerDynamicConfig;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Syncs broker dynamic configuration to all brokers.
+ */
+public class BrokerDynamicConfigSyncer extends BaseDynamicConfigSyncer<BrokerDynamicConfig>
+{
+ private final AtomicReference<BrokerDynamicConfig> currentConfig;
+
+ @Inject
+ public BrokerDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final JacksonConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider,
+ final ServiceEmitter emitter
+ )
+ {
+ super(
+ clientFactory,
+ jsonMapper,
+ druidNodeDiscoveryProvider,
+ emitter,
+ Execs.scheduledSingleThreaded("BrokerDynamicConfigSyncer-%d")
+ );
+ this.currentConfig = configManager.watch(
+ BrokerDynamicConfig.CONFIG_KEY,
+ BrokerDynamicConfig.class,
+ new BrokerDynamicConfig(null)
+ );
+ }
+
+ @Override
+ protected BrokerDynamicConfig getCurrentConfig()
+ {
+ return currentConfig.get();
+ }
+
+ @Override
+ protected boolean pushConfigToBroker(BrokerClient brokerClient, BrokerDynamicConfig config) throws Exception
+ {
+ return brokerClient.updateBrokerDynamicConfig(config).get();
+ }
+
+ @Override
+ protected String getConfigTypeName()
+ {
+ return "broker dynamic configuration";
Review Comment:
same thing here about type name
##########
server/src/main/java/org/apache/druid/server/http/CoordinatorDynamicConfigSyncer.java:
##########
@@ -86,179 +47,31 @@ public CoordinatorDynamicConfigSyncer(
final ServiceEmitter emitter
)
{
- this.clientFactory = clientFactory;
- this.configManager = configManager;
- this.jsonMapper = jsonMapper;
- this.druidNodeDiscovery = druidNodeDiscoveryProvider;
- this.exec = Execs.scheduledSingleThreaded("CoordinatorDynamicConfigSyncer-%d");
- this.inSyncBrokers = ConcurrentHashMap.newKeySet();
- this.emitter = emitter;
- }
-
- /**
- * Queues the configuration sync to the brokers without blocking the calling thread.
- */
- public void queueBroadcastConfigToBrokers()
- {
- exec.submit(this::broadcastConfigToBrokers);
- }
-
- /**
- * Push the latest coordinator dynamic config, provided by the configManager to all currently known Brokers. Also
- * invalidates the set of inSyncBrokers if the config has changed.
- */
- @VisibleForTesting
- void broadcastConfigToBrokers()
- {
- invalidateInSyncBrokersIfNeeded();
- final Stopwatch stopwatch = Stopwatch.createStarted();
- for (DiscoveryDruidNode broker : getKnownBrokers()) {
- pushConfigToBroker(broker);
- }
- emitStat(
- Stats.Configuration.TOTAL_SYNC_TIME,
- RowKey.empty(),
- stopwatch.millisElapsed()
- );
- }
-
- /**
- * Returns the set of Brokers which have been updated with the latest {@link CoordinatorDynamicConfig}.
- */
- public synchronized Set<BrokerSyncStatus> getInSyncBrokers()
- {
- return Set.copyOf(inSyncBrokers);
- }
-
- /**
- * Schedules a periodic sync with brokers when the coordinator becomes the leader.
- */
- public void onLeaderStart()
- {
- log.info("Starting coordinator config syncing to brokers on leader node.");
- syncFuture = exec.scheduleAtFixedRate(
- this::broadcastConfigToBrokers,
- 30L,
- 60L,
- TimeUnit.SECONDS
- );
- }
-
- /**
- * Stops the sync when coordinator stops being the leader.
- */
- public void onLeaderStop()
- {
- log.info("Not leader, stopping coordinator config syncing to brokers.");
- if (syncFuture != null) {
- syncFuture.cancel(true);
- }
- }
-
- @LifecycleStop
- public void stop()
- {
- exec.shutdownNow();
- }
-
- /**
- * Push the latest coordinator dynamic config, provided by the configManager to the Broker at the brokerLocation
- * param.
- */
- private void pushConfigToBroker(DiscoveryDruidNode broker)
- {
- final Stopwatch stopwatch = Stopwatch.createStarted();
- final ServiceLocation brokerLocation = CoordinatorDynamicConfigSyncer.convertDiscoveryNodeToServiceLocation(broker);
- final BrokerClient brokerClient = new BrokerClientImpl(
- clientFactory.makeClient(
- NodeRole.BROKER.getJsonName(),
- new FixedServiceLocator(brokerLocation),
- StandardRetryPolicy.builder().maxAttempts(6).build()
- ),
- jsonMapper
- );
-
- try {
- CoordinatorDynamicConfig currentDynamicConfig = configManager.getCurrentDynamicConfig();
- boolean success = brokerClient.updateCoordinatorDynamicConfig(currentDynamicConfig).get();
- if (success) {
- markBrokerAsSynced(currentDynamicConfig, brokerLocation);
- }
- }
- catch (Exception e) {
- // Catch and ignore the exception, wait for the next sync.
- log.error(e, "Exception while syncing dynamic configuration to broker[%s]", brokerLocation);
- emitStat(
- Stats.Configuration.BROKER_SYNC_ERROR,
- RowKey.with(Dimension.SERVER, broker.getDruidNode().getHostAndPortToUse()).build(),
- 1
- );
- }
- emitStat(
- Stats.Configuration.BROKER_SYNC_TIME,
- RowKey.with(Dimension.SERVER, broker.getDruidNode().getHostAndPortToUse()).build(),
- stopwatch.millisElapsed()
+ super(
+ clientFactory,
+ jsonMapper,
+ druidNodeDiscoveryProvider,
+ emitter,
+ Execs.scheduledSingleThreaded("CoordinatorDynamicConfigSyncer-%d")
);
+ this.configManager = configManager;
}
- /**
- * Returns a collection of {@link DiscoveryDruidNode} for all brokers currently known to the druidNodeDiscovery.
- */
- private Collection<DiscoveryDruidNode> getKnownBrokers()
- {
- return druidNodeDiscovery.getForNodeRole(NodeRole.BROKER)
- .getAllNodes();
- }
-
- /**
- * Clears the set of inSyncBrokers and updates the lastKnownConfig if the latest coordinator dynamic config is
- * different from the config tracked by this class.
- */
- private synchronized void invalidateInSyncBrokersIfNeeded()
- {
- final CoordinatorDynamicConfig currentDynamicConfig = configManager.getCurrentDynamicConfig();
- if (!currentDynamicConfig.equals(lastKnownConfig.get())) {
- // Config has changed, clear the inSync list.
- inSyncBrokers.clear();
- lastKnownConfig.set(currentDynamicConfig);
- }
- }
-
- /**
- * Adds a broker to the set of inSyncBrokers if the coordinator dynamic config has not changed.
- */
- private synchronized void markBrokerAsSynced(CoordinatorDynamicConfig config, ServiceLocation broker)
+ @Override
+ protected CoordinatorDynamicConfig getCurrentConfig()
{
- if (config.equals(lastKnownConfig.get())) {
- inSyncBrokers.add(new BrokerSyncStatus(broker, System.currentTimeMillis()));
- }
+ return configManager.getCurrentDynamicConfig();
}
- /**
- * Utility method to convert {@link DiscoveryDruidNode} to a {@link ServiceLocation}
- */
- @Nullable
- private static ServiceLocation convertDiscoveryNodeToServiceLocation(DiscoveryDruidNode discoveryDruidNode)
+ @Override
+ protected boolean pushConfigToBroker(BrokerClient brokerClient, CoordinatorDynamicConfig config) throws Exception
{
- final DruidNode druidNode = discoveryDruidNode.getDruidNode();
- if (druidNode == null) {
- return null;
- }
-
- return new ServiceLocation(
- druidNode.getHost(),
- druidNode.getPlaintextPort(),
- druidNode.getTlsPort(),
- ""
- );
+ return brokerClient.updateCoordinatorDynamicConfig(config).get();
}
- private void emitStat(CoordinatorStat stat, RowKey rowKey, long value)
+ @Override
+ protected String getConfigTypeName()
{
- ServiceMetricEvent.Builder eventBuilder = new ServiceMetricEvent.Builder();
- rowKey.getValues().forEach(
- (dim, dimValue) -> eventBuilder.setDimension(dim.reportedName(), dimValue)
- );
- emitter.emit(eventBuilder.setMetric(stat.getMetricName(), value));
+ return "coordinator dynamic configuration";
Review Comment:
maybe make this a single phrase? `coordinator` or `broker` would show up better in logs/metric dimensions.
##########
server/src/main/java/org/apache/druid/server/broker/BrokerDynamicConfig.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.broker;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.server.QueryBlocklistRule;
+
+import javax.annotation.Nullable;
+import javax.validation.constraints.NotNull;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Dynamic configuration for brokers that can be changed at runtime.
+ * This configuration is stored in the metadata store and managed through the coordinator,
+ * but is consumed by brokers.
+ *
+ * @see org.apache.druid.common.config.JacksonConfigManager
+ */
+public class BrokerDynamicConfig
+{
+ public static final String CONFIG_KEY = "broker.config";
+
+ /**
+ * List of query blocklist rules for blocking queries on brokers dynamically.
+ */
+ private final List<QueryBlocklistRule> queryBlocklist;
+
+ @JsonCreator
+ public BrokerDynamicConfig(
+ @JsonProperty("queryBlocklist") @Nullable List<QueryBlocklistRule> queryBlocklist
+ )
+ {
+ this.queryBlocklist = Builder.valueOrDefault(queryBlocklist, Collections.emptyList());
+ }
+
+ @JsonProperty
+ @JsonInclude(JsonInclude.Include.NON_EMPTY)
+ public List<QueryBlocklistRule> getQueryBlocklist()
+ {
+ return queryBlocklist;
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ BrokerDynamicConfig that = (BrokerDynamicConfig) o;
+ return Objects.equals(queryBlocklist, that.queryBlocklist);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return Objects.hash(queryBlocklist);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "BrokerDynamicConfig{" +
+ "queryBlocklist=" + queryBlocklist +
+ '}';
+ }
+
+ public static Builder builder()
+ {
+ return new Builder();
+ }
+
+ public static class Builder
+ {
+ private List<QueryBlocklistRule> queryBlocklist;
+
+ public Builder()
+ {
+ }
+
+ @JsonCreator
+ public Builder(
+ @JsonProperty("queryBlocklist") @Nullable List<QueryBlocklistRule> queryBlocklist
+ )
+ {
+ this.queryBlocklist = queryBlocklist;
+ }
+
+ public Builder withQueryBlocklist(List<QueryBlocklistRule> queryBlocklist)
+ {
+ this.queryBlocklist = queryBlocklist;
+ return this;
+ }
+
+ public BrokerDynamicConfig build()
+ {
+ return new BrokerDynamicConfig(queryBlocklist);
+ }
+
+ /**
+ * Builds a BrokerDynamicConfig using either the configured values, or
+ * the default value if not configured.
+ */
+ public BrokerDynamicConfig build(@Nullable BrokerDynamicConfig defaults)
+ {
+ return new BrokerDynamicConfig(
+ valueOrDefault(queryBlocklist, defaults != null ? defaults.getQueryBlocklist() : null)
+ );
+ }
+
+ private static <T> T valueOrDefault(@Nullable T value, @NotNull T defaultValue)
Review Comment:
nit: let's use `Configs.valueOrDefault`
##########
server/src/main/java/org/apache/druid/server/http/BaseDynamicConfigSyncer.java:
##########
@@ -0,0 +1,275 @@
+/*
+ * 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.common.annotations.VisibleForTesting;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.client.broker.BrokerClientImpl;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.java.util.common.Stopwatch;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStop;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.java.util.emitter.service.ServiceEmitter;
+import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
+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.coordinator.stats.CoordinatorStat;
+import org.apache.druid.server.coordinator.stats.Dimension;
+import org.apache.druid.server.coordinator.stats.RowKey;
+import org.apache.druid.server.coordinator.stats.Stats;
+
+import javax.annotation.Nullable;
+import java.util.Collection;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Base class for syncing dynamic configuration to all brokers.
+ * Subclasses must implement:
+ * - {@link #getCurrentConfig()} to provide the latest config
+ * - {@link #pushConfigToBroker(BrokerClient, Object)} to push config via the appropriate BrokerClient method
+ * - {@link #getConfigTypeName()} for logging
+ *
+ * @param <T> the type of dynamic configuration (e.g., CoordinatorDynamicConfig, BrokerDynamicConfig)
+ */
+public abstract class BaseDynamicConfigSyncer<T>
+{
+ private static final Logger log = new Logger(BaseDynamicConfigSyncer.class);
+
+ private final ObjectMapper jsonMapper;
+ private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+ private final ServiceClientFactory clientFactory;
+ private final ScheduledExecutorService exec;
+ private final ServiceEmitter emitter;
+ private @Nullable Future<?> syncFuture = null;
+
+ @GuardedBy("this")
+ private final Set<BrokerSyncStatus> inSyncBrokers;
+ private final AtomicReference<T> lastKnownConfig = new AtomicReference<>();
+
+ protected BaseDynamicConfigSyncer(
+ final ServiceClientFactory clientFactory,
+ final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider,
+ final ServiceEmitter emitter,
+ final ScheduledExecutorService exec
+ )
+ {
+ this.clientFactory = clientFactory;
+ this.jsonMapper = jsonMapper;
+ this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+ this.emitter = emitter;
+ this.exec = exec;
+ this.inSyncBrokers = ConcurrentHashMap.newKeySet();
+ }
+
+ /**
+ * Get the current configuration to broadcast to brokers.
+ */
+ protected abstract T getCurrentConfig();
+
+ /**
+ * Push the config to a broker using the appropriate BrokerClient method.
+ * @return true if the push was successful
+ */
+ protected abstract boolean pushConfigToBroker(BrokerClient brokerClient, T config) throws Exception;
+
+ /**
+ * Get the name of this config type for logging (e.g., "coordinator dynamic configuration", "broker dynamic configuration").
+ */
+ protected abstract String getConfigTypeName();
+
+ /**
+ * Queues the configuration sync to the brokers without blocking the calling thread.
+ */
+ public void queueBroadcastConfigToBrokers()
+ {
+ exec.submit(this::broadcastConfigToBrokers);
+ }
+
+ /**
+ * Push the latest dynamic config to all currently known Brokers. Also
+ * invalidates the set of inSyncBrokers if the config has changed.
+ */
+ @VisibleForTesting
+ public void broadcastConfigToBrokers()
+ {
+ invalidateInSyncBrokersIfNeeded();
+ final Stopwatch stopwatch = Stopwatch.createStarted();
+ for (DiscoveryDruidNode broker : getKnownBrokers()) {
+ pushConfigToBrokerNode(broker);
+ }
+ emitStat(
+ Stats.Configuration.TOTAL_SYNC_TIME,
Review Comment:
maybe now that we are syncing 2 types of configs to brokers, we should make the metric distinguish which config type is being pushed? I'm leaning more towards a dimension rather than a separate metric.
##########
server/src/test/java/org/apache/druid/server/BrokerDynamicConfigResourceTest.java:
##########
@@ -0,0 +1,97 @@
+/*
+ * 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;
+
+import org.apache.druid.client.BrokerViewOfBrokerConfig;
+import org.apache.druid.client.BrokerViewOfCoordinatorConfig;
+import org.apache.druid.server.broker.BrokerDynamicConfig;
+import org.apache.druid.server.coordinator.CoordinatorDynamicConfig;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import javax.ws.rs.core.Response;
+
+public class BrokerDynamicConfigResourceTest
+{
+ private BrokerViewOfCoordinatorConfig brokerViewOfCoordinatorConfig;
+ private BrokerViewOfBrokerConfig brokerViewOfBrokerConfig;
+ private BrokerDynamicConfigResource resource;
+
+ @Before
+ public void setUp()
+ {
+ brokerViewOfCoordinatorConfig = Mockito.mock(BrokerViewOfCoordinatorConfig.class);
+ brokerViewOfBrokerConfig = Mockito.mock(BrokerViewOfBrokerConfig.class);
+ resource = new BrokerDynamicConfigResource(
+ brokerViewOfCoordinatorConfig,
+ brokerViewOfBrokerConfig
+ );
+ }
+
+ @Test
+ public void testGetBrokerDynamicConfig()
+ {
+ BrokerDynamicConfig config = new BrokerDynamicConfig(null);
+ Mockito.when(brokerViewOfBrokerConfig.getDynamicConfig()).thenReturn(config);
+
+ Response response = resource.getBrokerDynamicConfig();
+
+ Assert.assertEquals(200, response.getStatus());
+ Assert.assertEquals(config, response.getEntity());
+ Mockito.verify(brokerViewOfBrokerConfig, Mockito.times(1)).getDynamicConfig();
+ }
+
+ @Test
+ public void testSetBrokerDynamicConfig()
+ {
+ BrokerDynamicConfig config = new BrokerDynamicConfig(null);
+
+ Response response = resource.setBrokerDynamicConfig(config);
+
+ Assert.assertEquals(200, response.getStatus());
+ Mockito.verify(brokerViewOfBrokerConfig, Mockito.times(1)).setDynamicConfig(config);
+ }
+
+ @Test
+ public void testGetDynamicConfig()
Review Comment:
let's maybe rename these get/set to have coordinator dynamic in them (distinguish from broker dynamic).
##########
server/src/main/java/org/apache/druid/client/BaseBrokerViewOfConfig.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.errorprone.annotations.concurrent.GuardedBy;
+import org.apache.druid.java.util.common.lifecycle.LifecycleStart;
+import org.apache.druid.java.util.common.logger.Logger;
+
+import javax.validation.constraints.NotNull;
+
+/**
+ * Base class for broker's view of dynamic configuration fetched from the Coordinator.
+ * Subclasses must implement:
+ * {@link #fetchConfigFromClient()} to fetch configuration from their specific client</li>
+ * {@link #getConfigTypeName()} for logging purposes</li>
+ *
+ * @param <T> the type of dynamic configuration (e.g., CoordinatorDynamicConfig, BrokerDynamicConfig)
+ */
+public abstract class BaseBrokerViewOfConfig<T>
Review Comment:
could we make this template parameter's name more match what it is? e.g. `DynamicConfig`
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on PR #19011:
URL: https://github.com/apache/druid/pull/19011#issuecomment-4029014933
Just downloaded the test-report artifacts from GitHub and I see `org.apache.druid.testing.embedded.docker.IngestionBackwardCompatibilityDockerTest` was the last embedded test and the test JVM crashes.
Since the test [uses](https://github.com/apache/druid/blob/master/embedded-tests/src/test/java/org/apache/druid/testing/embedded/docker/IngestionBackwardCompatibilityDockerTest.java#L42) an old Coordinator from 31.0.0, would some of the changes here be compatible with that? I’m wondering if the test might actually be uncovering a legitimate backwards compatibility issue with an old Coordinator + new Brokers.
cc: @mshahid6 @jtuglu1
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Dynamic Config and Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2801462144
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
+ boolean hasDataSources = dataSources != null && !dataSources.isEmpty();
+ boolean hasQueryTypes = queryTypes != null && !queryTypes.isEmpty();
+ boolean hasContextMatches = contextMatches != null && !contextMatches.isEmpty();
+
+ Preconditions.checkArgument(
+ hasDataSources || hasQueryTypes || hasContextMatches,
+ "At least one criterion (dataSources, queryTypes, or contextMatches) must be specified. "
+ + "A rule with all null/empty criteria would block ALL queries."
+ );
+
+ this.ruleName = ruleName;
+ this.dataSources = dataSources;
+ this.queryTypes = queryTypes;
+ this.contextMatches = contextMatches;
+ }
+
+ @JsonProperty
+ public String getRuleName()
+ {
+ return ruleName;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getDataSources()
+ {
+ return dataSources;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getQueryTypes()
+ {
+ return queryTypes;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Map<String, String> getContextMatches()
+ {
+ return contextMatches;
+ }
+
+ /**
+ * Returns true if the query matches ALL specified criteria (AND logic).
+ * Null or empty criteria match everything.
+ *
+ * @param query the query to check
+ * @return true if the query matches this rule, false otherwise
+ */
+ public boolean matches(Query<?> query)
Review Comment:
It might be worth caching this result for all 3 types. JVM might be smart and branch predict this every time but since this is called per-query on constant fields, it might be worth explicitly doing this to save ≥ 2 comparisons per query.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2834817464
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ private final boolean hasDataSourceCriteria;
+ private final boolean hasQueryTypeCriteria;
+ private final boolean hasContextCriteria;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
+ this.hasDataSourceCriteria = dataSources != null && !dataSources.isEmpty();
+ this.hasQueryTypeCriteria = queryTypes != null && !queryTypes.isEmpty();
+ this.hasContextCriteria = contextMatches != null && !contextMatches.isEmpty();
+
+ Preconditions.checkArgument(
+ hasDataSourceCriteria || hasQueryTypeCriteria || hasContextCriteria,
+ "At least one criterion (dataSources, queryTypes, or contextMatches) must be specified. "
+ + "A rule with all null/empty criteria would block ALL queries."
+ );
+
+ this.ruleName = ruleName;
+ this.dataSources = dataSources;
+ this.queryTypes = queryTypes;
+ this.contextMatches = contextMatches;
+ }
+
+ @JsonProperty
+ public String getRuleName()
+ {
+ return ruleName;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getDataSources()
+ {
+ return dataSources;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getQueryTypes()
+ {
+ return queryTypes;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Map<String, String> getContextMatches()
+ {
+ return contextMatches;
+ }
+
+ /**
+ * Returns true if the query matches ALL specified criteria (AND logic).
+ * Null or empty criteria match everything.
+ *
+ * @param query the query to check
+ * @return true if the query matches this rule, false otherwise
+ */
+ public boolean matches(Query<?> query)
+ {
+ if (hasDataSourceCriteria) {
+ Set<String> queryDatasources = query.getDataSource().getTableNames();
+ if (Sets.intersection(dataSources, queryDatasources).isEmpty()) {
+ return false;
+ }
+ }
+
+ if (hasQueryTypeCriteria) {
+ if (!queryTypes.contains(query.getType())) {
+ return false;
+ }
+ }
+
+ if (hasContextCriteria) {
+ for (Map.Entry<String, String> entry : contextMatches.entrySet()) {
+ Object contextValue = query.getContext().get(entry.getKey());
+ if (!entry.getValue().equals(String.valueOf(contextValue))) {
Review Comment:
Unless we're restricting the possible value set, this String.valueOf() will NPE if the `contextValue` is `null`. While this isn't a typical context value, it's still valid context. I think we should be a bit more graceful and allow the query or 403 depending on how we want to handle the `null` in contextValue(in other fields, we do as match-all for example).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "mshahid6 (via GitHub)" <gi...@apache.org>.
mshahid6 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2885295591
##########
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:
would only BrokerViewOfCoordinatorConfig implement HistoricalFilter and have the queryable server logic?
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2912642187
##########
server/src/main/java/org/apache/druid/client/coordinator/CoordinatorClientImpl.java:
##########
@@ -253,6 +254,22 @@ public ListenableFuture<CoordinatorDynamicConfig> getCoordinatorDynamicConfig()
);
}
+ @Override
+ public ListenableFuture<BrokerDynamicConfig> getBrokerDynamicConfig()
+ {
+ return FutureUtils.transform(
+ client.asyncRequest(
+ new RequestBuilder(HttpMethod.GET, "/druid/coordinator/v1/broker/config"),
+ new BytesFullResponseHandler()
+ ),
+ holder -> JacksonUtils.readValue(
Review Comment:
Thanks for the [fix](https://github.com/apache/druid/pull/19120), @jtuglu1! (And to @kfaraz for adding the backward compatibility embedded test 🙂)
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on PR #19011:
URL: https://github.com/apache/druid/pull/19011#issuecomment-4029034531
> IngestionBackwardCompatibilityDockerTest.java
Yes, I saw that too – looking. My guess is brokers are calling coordinator config endpoint (which doesn't exist)
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2909679411
##########
server/src/main/java/org/apache/druid/client/coordinator/CoordinatorClientImpl.java:
##########
@@ -253,6 +254,22 @@ public ListenableFuture<CoordinatorDynamicConfig> getCoordinatorDynamicConfig()
);
}
+ @Override
+ public ListenableFuture<BrokerDynamicConfig> getBrokerDynamicConfig()
+ {
+ return FutureUtils.transform(
+ client.asyncRequest(
+ new RequestBuilder(HttpMethod.GET, "/druid/coordinator/v1/broker/config"),
+ new BytesFullResponseHandler()
+ ),
+ holder -> JacksonUtils.readValue(
Review Comment:
Yeah – I have a test branch that I'll raise in a bit to fix this
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "mshahid6 (via GitHub)" <gi...@apache.org>.
mshahid6 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2835056433
##########
server/src/test/java/org/apache/druid/server/QueryBlocklistRuleTest.java:
##########
@@ -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.server;
+
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import org.apache.druid.query.Druids;
+import org.apache.druid.query.timeseries.TimeseriesQuery;
+import org.junit.Assert;
+import org.junit.Test;
+import java.util.Map;
+import java.util.Set;
+
+public class QueryBlocklistRuleTest
+{
+ @Test
+ public void testMatchAllCriteria_rejectsNullCriteria()
+ {
+ // Rule with all null criteria would block ALL queries - this should be rejected
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> new QueryBlocklistRule("match-all", null, null, null)
+ );
+ }
+
+ @Test
+ public void testMatchAllCriteria_rejectsEmptyCollections()
+ {
+ // Rule with all empty collections should also be rejected (same as null)
+ Assert.assertThrows(
+ IllegalArgumentException.class,
+ () -> new QueryBlocklistRule("match-all", ImmutableSet.of(), ImmutableSet.of(), ImmutableMap.of())
+ );
+ }
+
+ @Test
+ public void testMatchByDataSource()
+ {
+ Set<String> dataSources = ImmutableSet.of("sensitive_data", "pii_table");
+ QueryBlocklistRule rule = new QueryBlocklistRule("block-sensitive", dataSources, null, null);
+
+ // Should match when datasource is in the list
+ TimeseriesQuery matchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("sensitive_data")
+ .intervals("2020-01-01/2020-01-02")
+ .build();
+ Assert.assertTrue(rule.matches(matchingQuery));
+
+ // Should not match when datasource is not in the list
+ TimeseriesQuery nonMatchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("safe_data")
+ .intervals("2020-01-01/2020-01-02")
+ .build();
+ Assert.assertFalse(rule.matches(nonMatchingQuery));
+ }
+
+ @Test
+ public void testMatchByContext()
+ {
+ Map<String, String> contextMatches = ImmutableMap.of("priority", "0", "application", "rogue-app");
+ QueryBlocklistRule rule = new QueryBlocklistRule("block-rogue-app", null, null, contextMatches);
+
+ // Should match when all context values match
+ TimeseriesQuery matchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("test")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "0", "application", "rogue-app"))
+ .build();
+ Assert.assertTrue(rule.matches(matchingQuery));
+
+ // Should not match when context values don't match
+ TimeseriesQuery nonMatchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("test")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "1", "application", "rogue-app"))
+ .build();
+ Assert.assertFalse(rule.matches(nonMatchingQuery));
+
+ // Should not match when context is missing
+ TimeseriesQuery noContextQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("test")
+ .intervals("2020-01-01/2020-01-02")
+ .build();
+ Assert.assertFalse(rule.matches(noContextQuery));
+ }
+
+ @Test
+ public void testMatchByMultipleCriteria()
+ {
+ // Rule with multiple criteria - all must match (AND logic)
+ Set<String> dataSources = ImmutableSet.of("large_table");
+ Map<String, String> contextMatches = ImmutableMap.of("priority", "0");
+ QueryBlocklistRule rule = new QueryBlocklistRule(
+ "block-low-priority-large-table",
+ dataSources,
+ null,
+ contextMatches
+ );
+
+ // Should match when both datasource AND context match
+ TimeseriesQuery matchingQuery = Druids.newTimeseriesQueryBuilder()
+ .dataSource("large_table")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "0"))
+ .build();
+ Assert.assertTrue(rule.matches(matchingQuery));
+
+ // Should not match when only datasource matches
+ TimeseriesQuery onlyDataSourceMatches = Druids.newTimeseriesQueryBuilder()
+ .dataSource("large_table")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "1"))
+ .build();
+ Assert.assertFalse(rule.matches(onlyDataSourceMatches));
+
+ // Should not match when only context matches
+ TimeseriesQuery onlyContextMatches = Druids.newTimeseriesQueryBuilder()
+ .dataSource("small_table")
+ .intervals("2020-01-01/2020-01-02")
+ .context(ImmutableMap.of("priority", "0"))
+ .build();
+ Assert.assertFalse(rule.matches(onlyContextMatches));
+ }
+
+ @Test
+ public void testWildcardBehavior_nullQueryTypes()
+ {
+ QueryBlocklistRule rule = new QueryBlocklistRule(
+ "block-datasource-all-types",
+ ImmutableSet.of("blocked_ds"),
+ null, // null means match all query types
Review Comment:
https://github.com/apache/druid/pull/19011/changes/BASE..ab49ff09e6954ca00d9485650a55ce1b395dcfb6#diff-23b572e1c4ec981b4ca8ebdac28e9bb94dc71bb29c8342a68bd483c39f362ffeR857
i can add to this?
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2801433893
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
Review Comment:
~~This seems backwards to me. In my mind, passing all nulls should result in the default behavior. In other words, I need to "opt-in" to the blocking behavior.
IMO, we should make it easier for users to do the "default" thing which is allowing the query through. A rule matching a query <===> that query is blocked. Right now, it's the other way around.~~
NVM.
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
Review Comment:
~~This seems backwards to me. In my mind, passing all nulls should result in the default behavior. In other words, I need to "opt-in" to the blocking behavior. ~~
~~IMO, we should make it easier for users to do the "default" thing which is allowing the query through. A rule matching a query <===> that query is blocked. Right now, it's the other way around.~~
NVM.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2909680451
##########
server/src/main/java/org/apache/druid/client/coordinator/CoordinatorClientImpl.java:
##########
@@ -253,6 +254,22 @@ public ListenableFuture<CoordinatorDynamicConfig> getCoordinatorDynamicConfig()
);
}
+ @Override
+ public ListenableFuture<BrokerDynamicConfig> getBrokerDynamicConfig()
+ {
+ return FutureUtils.transform(
+ client.asyncRequest(
+ new RequestBuilder(HttpMethod.GET, "/druid/coordinator/v1/broker/config"),
+ new BytesFullResponseHandler()
+ ),
+ holder -> JacksonUtils.readValue(
Review Comment:
Will summarize the changes there
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2909658206
##########
server/src/main/java/org/apache/druid/client/coordinator/CoordinatorClientImpl.java:
##########
@@ -253,6 +254,22 @@ public ListenableFuture<CoordinatorDynamicConfig> getCoordinatorDynamicConfig()
);
}
+ @Override
+ public ListenableFuture<BrokerDynamicConfig> getBrokerDynamicConfig()
+ {
+ return FutureUtils.transform(
+ client.asyncRequest(
+ new RequestBuilder(HttpMethod.GET, "/druid/coordinator/v1/broker/config"),
+ new BytesFullResponseHandler()
+ ),
+ holder -> JacksonUtils.readValue(
Review Comment:
Looks like this change is causing `org.apache.druid.testing.embedded.docker.IngestionBackwardCompatibilityDockerTest` to fail consistently (which seems like it would be a legit issue during rolling upgrades since the Coordinators are typically upgraded in the end).
I haven’t looked closely at the surrounding code yet, but either this code or the caller likely needs to account for the new `/druid/coordinator/v1/broker/config` endpoint not being available on Coordinators during rolling upgrades in a backward compatible manner.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "kfaraz (via GitHub)" <gi...@apache.org>.
kfaraz commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2909679042
##########
server/src/main/java/org/apache/druid/client/coordinator/CoordinatorClientImpl.java:
##########
@@ -253,6 +254,22 @@ public ListenableFuture<CoordinatorDynamicConfig> getCoordinatorDynamicConfig()
);
}
+ @Override
+ public ListenableFuture<BrokerDynamicConfig> getBrokerDynamicConfig()
+ {
+ return FutureUtils.transform(
+ client.asyncRequest(
+ new RequestBuilder(HttpMethod.GET, "/druid/coordinator/v1/broker/config"),
+ new BytesFullResponseHandler()
+ ),
+ holder -> JacksonUtils.readValue(
Review Comment:
Yes, that must be the reason.
Probably just catching the not found exception and continuing with the Broker start up should suffice.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Dynamic Config and Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2801431173
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
+ boolean hasDataSources = dataSources != null && !dataSources.isEmpty();
+ boolean hasQueryTypes = queryTypes != null && !queryTypes.isEmpty();
+ boolean hasContextMatches = contextMatches != null && !contextMatches.isEmpty();
+
+ Preconditions.checkArgument(
+ hasDataSources || hasQueryTypes || hasContextMatches,
+ "At least one criterion (dataSources, queryTypes, or contextMatches) must be specified. "
+ + "A rule with all null/empty criteria would block ALL queries."
+ );
+
+ this.ruleName = ruleName;
+ this.dataSources = dataSources;
+ this.queryTypes = queryTypes;
+ this.contextMatches = contextMatches;
+ }
+
+ @JsonProperty
+ public String getRuleName()
+ {
+ return ruleName;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getDataSources()
+ {
+ return dataSources;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getQueryTypes()
+ {
+ return queryTypes;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Map<String, String> getContextMatches()
+ {
+ return contextMatches;
+ }
+
+ /**
+ * Returns true if the query matches ALL specified criteria (AND logic).
+ * Null or empty criteria match everything.
+ *
+ * @param query the query to check
+ * @return true if the query matches this rule, false otherwise
+ */
+ public boolean matches(Query<?> query)
+ {
+ if (!isNullOrEmpty(dataSources)) {
+ Set<String> queryDatasources = query.getDataSource().getTableNames();
+ if (Sets.intersection(dataSources, queryDatasources).isEmpty()) {
+ return false;
+ }
+ }
+
+ if (!isNullOrEmpty(queryTypes)) {
+ if (!queryTypes.contains(query.getType())) {
+ return false;
+ }
+ }
+
+ if (contextMatches != null && !contextMatches.isEmpty()) {
+ for (Map.Entry<String, String> entry : contextMatches.entrySet()) {
+ Object contextValue = query.getContext().get(entry.getKey());
+ if (!entry.getValue().equals(String.valueOf(contextValue))) {
+ return false;
+ }
+ }
+ }
+
+ return true;
Review Comment:
I think we should invert this. Ideally, a rule matching a query <==> that query is blocked. i.e matches should return `false` by default.
##########
server/src/main/java/org/apache/druid/server/coordinator/CoordinatorDynamicConfig.java:
##########
@@ -454,6 +478,7 @@ public static int getDefaultBalancerComputeThreads()
private static class Defaults
{
+ static final List<QueryBlocklistRule> QUERY_BLOCKLIST = ImmutableList.of();
Review Comment:
nit: `List.of()`
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
Review Comment:
I think we should negate this. Queries matching all criteria in the `QueryBlocklistRule` are blocked, and those that do not match are not blocked.
##########
server/src/main/java/org/apache/druid/server/coordinator/CoordinatorDynamicConfig.java:
##########
@@ -172,6 +181,7 @@ public CoordinatorDynamicConfig(
this.validDebugDimensions = validateDebugDimensions(debugDimensions);
this.turboLoadingNodes = Configs.valueOrDefault(turboLoadingNodes, Set.of());
this.cloneServers = Configs.valueOrDefault(cloneServers, Map.of());
+ this.queryBlocklist = queryBlocklist != null ? ImmutableList.copyOf(queryBlocklist) : Defaults.QUERY_BLOCKLIST;
Review Comment:
Is there a reason we are creating an immutable copy of this? Maybe let's use `Configs.valueOrDefault` to follow convention here with the rest of the containers being serde'd.
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,176 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
Review Comment:
This seems backwards to me. In my mind, passing all nulls should result in the default behavior. In other words, I need to "opt-in" to the blocking behavior.
IMO, we should make it easier for users to do the "default" thing which is allowing the query through. A rule matching a query <===> that query is blocked. Right now, it's the other way around.
##########
server/src/main/java/org/apache/druid/server/QueryLifecycle.java:
##########
@@ -310,6 +317,35 @@ private void preAuthorized(
}
}
+ /**
+ * Checks if the query matches any blocklist rules. If a rule matches, throws a DruidException.
+ * Rules are evaluated in order, and the first match wins.
+ *
+ * @throws DruidException if the query is blocklisted
+ */
+ private void checkQueryBlocklist()
+ {
+ if (brokerViewOfCoordinatorConfig == null) {
+ return; // Not running on broker, skip blocklist check
+ }
+
+ CoordinatorDynamicConfig config = brokerViewOfCoordinatorConfig.getDynamicConfig();
+ if (config == null) {
+ return; // Config not loaded yet, allow query (best effort)
+ }
+
+ for (QueryBlocklistRule rule : config.getQueryBlocklist()) {
+ if (rule.matches(this.baseQuery)) {
+ throw DruidException.forPersona(DruidException.Persona.USER)
+ .ofCategory(DruidException.Category.FORBIDDEN)
+ .build(
+ "Query blocked by rule[%s]",
Review Comment:
Does this log the query ID? It'd be nice to co-locate the query ID and the rule name in a log so users/operators don't need to grep that separately.
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "abhishekrb19 (via GitHub)" <gi...@apache.org>.
abhishekrb19 commented on PR #19011:
URL: https://github.com/apache/druid/pull/19011#issuecomment-4028745869
I think something from this PR is causing one of the embedded tests to consistently fail in master and on all recent PRs:
```
[Execute: .github/scripts/run_unit-tests -Dtest=!QTest,'I*,A*,U*' -Dmaven.test.failure.ignore=true](https://github.com/apache/druid/actions/runs/22832980666/job/66354459774#annotation:6:8087)
Process completed with exit code 1.
```
https://github.com/apache/druid/actions/runs/22832980666/job/66354459774
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "maytasm (via GitHub)" <gi...@apache.org>.
maytasm commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2885745352
##########
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:
Since those configs are already in Coordinator Dynamic configs, we can leave it in BrokerViewOfCoordinatorConfig. So BrokerViewOfCoordinatorConfig can extends BaseBrokerViewConfig and extends HistoricalFilter while BrokerViewOfBrokerConfig can just extends BaseBrokerViewConfig
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Query Blocklist (druid)
Posted by "jtuglu1 (via GitHub)" <gi...@apache.org>.
jtuglu1 commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2834817464
##########
server/src/main/java/org/apache/druid/server/QueryBlocklistRule.java:
##########
@@ -0,0 +1,175 @@
+/*
+ * 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;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.collect.Sets;
+import org.apache.druid.query.Query;
+
+import javax.annotation.Nullable;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * A rule for matching queries against blocklist criteria. A query matches this rule if ALL
+ * specified criteria match (AND logic). Null or empty criteria match everything.
+ */
+public class QueryBlocklistRule
+{
+ private final String ruleName;
+ @Nullable
+ private final Set<String> dataSources;
+ @Nullable
+ private final Set<String> queryTypes;
+ @Nullable
+ private final Map<String, String> contextMatches;
+
+ private final boolean hasDataSourceCriteria;
+ private final boolean hasQueryTypeCriteria;
+ private final boolean hasContextCriteria;
+
+ @JsonCreator
+ public QueryBlocklistRule(
+ @JsonProperty("ruleName") String ruleName,
+ @JsonProperty("dataSources") @Nullable Set<String> dataSources,
+ @JsonProperty("queryTypes") @Nullable Set<String> queryTypes,
+ @JsonProperty("contextMatches") @Nullable Map<String, String> contextMatches
+ )
+ {
+ Preconditions.checkArgument(
+ !Strings.isNullOrEmpty(ruleName),
+ "ruleName must not be null or empty"
+ );
+
+ // At least one criterion must be specified to prevent accidentally blocking all queries
+ this.hasDataSourceCriteria = dataSources != null && !dataSources.isEmpty();
+ this.hasQueryTypeCriteria = queryTypes != null && !queryTypes.isEmpty();
+ this.hasContextCriteria = contextMatches != null && !contextMatches.isEmpty();
+
+ Preconditions.checkArgument(
+ hasDataSourceCriteria || hasQueryTypeCriteria || hasContextCriteria,
+ "At least one criterion (dataSources, queryTypes, or contextMatches) must be specified. "
+ + "A rule with all null/empty criteria would block ALL queries."
+ );
+
+ this.ruleName = ruleName;
+ this.dataSources = dataSources;
+ this.queryTypes = queryTypes;
+ this.contextMatches = contextMatches;
+ }
+
+ @JsonProperty
+ public String getRuleName()
+ {
+ return ruleName;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getDataSources()
+ {
+ return dataSources;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Set<String> getQueryTypes()
+ {
+ return queryTypes;
+ }
+
+ @JsonProperty
+ @Nullable
+ public Map<String, String> getContextMatches()
+ {
+ return contextMatches;
+ }
+
+ /**
+ * Returns true if the query matches ALL specified criteria (AND logic).
+ * Null or empty criteria match everything.
+ *
+ * @param query the query to check
+ * @return true if the query matches this rule, false otherwise
+ */
+ public boolean matches(Query<?> query)
+ {
+ if (hasDataSourceCriteria) {
+ Set<String> queryDatasources = query.getDataSource().getTableNames();
+ if (Sets.intersection(dataSources, queryDatasources).isEmpty()) {
+ return false;
+ }
+ }
+
+ if (hasQueryTypeCriteria) {
+ if (!queryTypes.contains(query.getType())) {
+ return false;
+ }
+ }
+
+ if (hasContextCriteria) {
+ for (Map.Entry<String, String> entry : contextMatches.entrySet()) {
+ Object contextValue = query.getContext().get(entry.getKey());
+ if (!entry.getValue().equals(String.valueOf(contextValue))) {
Review Comment:
Unless we're restricting the possible value set, this String.valueOf() will NPE if the `contextValue` is `null`. While this isn't a typical context value, it's still valid context. I think we should be a bit more graceful and return a 200 or 403 depending on how we want to handle the `null` in contextValue(in other fields, we do as match-all for example).
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org
Re: [PR] Broker Config and Query Blocklist (druid)
Posted by "maytasm (via GitHub)" <gi...@apache.org>.
maytasm commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2902600360
##########
server/src/main/java/org/apache/druid/server/http/BrokerDynamicConfigSyncer.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * 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 org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.common.config.JacksonConfigManager;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+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.emitter.service.ServiceEmitter;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.server.broker.BrokerDynamicConfig;
+
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Syncs broker dynamic configuration to all brokers.
+ */
+public class BrokerDynamicConfigSyncer extends BaseDynamicConfigSyncer<BrokerDynamicConfig>
+{
+ private final AtomicReference<BrokerDynamicConfig> currentConfig;
+
+ @Inject
+ public BrokerDynamicConfigSyncer(
+ @EscalatedGlobal final ServiceClientFactory clientFactory,
+ final JacksonConfigManager configManager,
+ @Json final ObjectMapper jsonMapper,
+ final DruidNodeDiscoveryProvider druidNodeDiscoveryProvider,
+ final ServiceEmitter emitter
+ )
+ {
+ super(
+ clientFactory,
+ jsonMapper,
+ druidNodeDiscoveryProvider,
+ emitter,
+ Execs.scheduledSingleThreaded("BrokerDynamicConfigSyncer-%d")
+ );
+ this.currentConfig = configManager.watch(
+ BrokerDynamicConfig.CONFIG_KEY,
+ BrokerDynamicConfig.class,
+ new BrokerDynamicConfig(null)
Review Comment:
nit: use Builder
--
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@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org