-
Notifications
You must be signed in to change notification settings - Fork 0
Clone kafka 18894 #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
563f347
08dff59
9e221e3
1dd8f41
204c8a9
96fd5a6
6ef4001
44ecfdb
e26a06f
27d9a55
b92a2bb
5989a26
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,58 @@ | ||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||
| * 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.kafka.common.config.provider; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.MetricName; | ||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.config.ConfigData; | ||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.metrics.Measurable; | ||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.metrics.Monitorable; | ||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.metrics.PluginMetrics; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import java.io.IOException; | ||||||||||||||||||||||||||||||||||||
| import java.util.Map; | ||||||||||||||||||||||||||||||||||||
| import java.util.Set; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| public class MonitorableConfigProvider implements ConfigProvider, Monitorable { | ||||||||||||||||||||||||||||||||||||
| public static final String NAME = "name"; | ||||||||||||||||||||||||||||||||||||
| public static final String DESCRIPTION = "description"; | ||||||||||||||||||||||||||||||||||||
| protected boolean configured = false; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||
| public void withPluginMetrics(PluginMetrics metrics) { | ||||||||||||||||||||||||||||||||||||
| MetricName metricName = metrics.metricName(NAME, DESCRIPTION, Map.of()); | ||||||||||||||||||||||||||||||||||||
| metrics.addMetric(metricName, (Measurable) (config, now) -> 123); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||
| public ConfigData get(String path) { | ||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||
| public ConfigData get(String path, Set<String> keys) { | ||||||||||||||||||||||||||||||||||||
| return null; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+41
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Return non-null ConfigData from get methods to avoid NPEs. ConfigTransformer expects a non-null ConfigData; current null return can crash tests using this provider. @Override
public ConfigData get(String path) {
- return null;
+ return new ConfigData(Map.of());
}
@Override
public ConfigData get(String path, Set<String> keys) {
- return null;
+ return new ConfigData(Map.of());
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||
| public void close() throws IOException { | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||
| public void configure(Map<String, ?> configs) { | ||||||||||||||||||||||||||||||||||||
| configured = true; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.config.ConfigDef.Type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.config.ConfigTransformer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.config.provider.ConfigProvider; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.internals.Plugin; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.security.auth.SecurityProtocol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.common.utils.Utils; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.apache.kafka.connect.runtime.WorkerConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -269,18 +270,19 @@ List<String> configProviders() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, String> transform(Map<String, String> props) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // transform worker config according to config.providers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<String> providerNames = configProviders(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, ConfigProvider> providers = new HashMap<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Plugin<ConfigProvider>> providerPlugins = new HashMap<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (String name : providerNames) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigProvider configProvider = plugins.newConfigProvider( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Plugin<ConfigProvider> configProviderPlugin = plugins.newConfigProvider( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| CONFIG_PROVIDERS_CONFIG + "." + name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Plugins.ClassLoaderUsage.PLUGINS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Plugins.ClassLoaderUsage.PLUGINS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| null | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| providers.put(name, configProvider); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| providerPlugins.put(name, configProviderPlugin); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigTransformer transformer = new ConfigTransformer(providers); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ConfigTransformer transformer = new ConfigTransformer(providerPlugins); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, String> transformed = transformer.transform(props).data(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| providers.values().forEach(x -> Utils.closeQuietly(x, "config provider")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| providerPlugins.values().forEach(x -> Utils.closeQuietly(x, "config provider plugin")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return transformed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+273
to
286
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Close provider plugins in a finally block and skip null plugins. Prevents resource leaks if transform throws and avoids null values in the map. - Map<String, Plugin<ConfigProvider>> providerPlugins = new HashMap<>();
- for (String name : providerNames) {
- Plugin<ConfigProvider> configProviderPlugin = plugins.newConfigProvider(
- this,
- name,
- Plugins.ClassLoaderUsage.PLUGINS,
- null
- );
- providerPlugins.put(name, configProviderPlugin);
- }
- ConfigTransformer transformer = new ConfigTransformer(providerPlugins);
- Map<String, String> transformed = transformer.transform(props).data();
- providerPlugins.values().forEach(x -> Utils.closeQuietly(x, "config provider plugin"));
- return transformed;
+ Map<String, Plugin<ConfigProvider>> providerPlugins = new HashMap<>();
+ try {
+ for (String name : providerNames) {
+ Plugin<ConfigProvider> configProviderPlugin = plugins.newConfigProvider(
+ this,
+ name,
+ Plugins.ClassLoaderUsage.PLUGINS,
+ null
+ );
+ if (configProviderPlugin != null) {
+ providerPlugins.put(name, configProviderPlugin);
+ }
+ }
+ ConfigTransformer transformer = new ConfigTransformer(providerPlugins);
+ return transformer.transform(props).data();
+ } finally {
+ providerPlugins.values().forEach(x -> Utils.closeQuietly(x, "config provider plugin"));
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| import org.apache.kafka.common.Configurable; | ||
| import org.apache.kafka.common.config.AbstractConfig; | ||
| import org.apache.kafka.common.config.provider.ConfigProvider; | ||
| import org.apache.kafka.common.internals.Plugin; | ||
| import org.apache.kafka.common.metrics.Metrics; | ||
| import org.apache.kafka.common.utils.Utils; | ||
| import org.apache.kafka.connect.components.Versioned; | ||
| import org.apache.kafka.connect.connector.Connector; | ||
|
|
@@ -627,7 +629,8 @@ private <U> U newVersionedPlugin( | |
| return plugin; | ||
| } | ||
|
|
||
| public ConfigProvider newConfigProvider(AbstractConfig config, String providerPrefix, ClassLoaderUsage classLoaderUsage) { | ||
| public Plugin<ConfigProvider> newConfigProvider(AbstractConfig config, String providerName, ClassLoaderUsage classLoaderUsage, Metrics metrics) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainAPI change: verify all call sites and document behavior Method now returns Run to find call sites and check that metrics are threaded through: 🏁 Script executed: #!/bin/bash
set -euo pipefail
# All invocations of newConfigProvider
rg -nP --type=java -C2 '\bnewConfigProvider\s*\('
# Quick sanity: confirm files calling it also reference Metrics
rg -nP --type=java -C2 '\bnewConfigProvider\s*\(' \
| sed -n 's/^\([^:]*\):.*/\1/p' | sort -u \
| xargs -I{} rg -nP --type=java -H '\bMetrics\b|\bmetrics\b' {}Length of output: 17259 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
# List all non-test Java files invoking newConfigProvider
files=$(rg -lP --type=java 'newConfigProvider\s*\(' | grep -v '/src/test/' || true)
for file in $files; do
echo "=== $file ==="
rg -nP --type=java -C3 'newConfigProvider' "$file"
echo
doneLength of output: 1541 🏁 Script executed: #!/usr/bin/env bash
set -euo pipefail
echo "MirrorMakerConfig.java (lines 270–285):"
sed -n '270,285p' connect/mirror/src/main/java/org/apache/kafka/connect/mirror/MirrorMakerConfig.java
echo
echo "Worker.java (lines 210–225):"
sed -n '210,225p' connect/runtime/src/main/java/org/apache/kafka/connect/runtime/Worker.javaLength of output: 1669 Pass a real Metrics to
🤖 Prompt for AI Agents |
||
| String providerPrefix = WorkerConfig.CONFIG_PROVIDERS_CONFIG + "." + providerName; | ||
| String classPropertyName = providerPrefix + ".class"; | ||
| Map<String, String> originalConfig = config.originalsStrings(); | ||
| if (!originalConfig.containsKey(classPropertyName)) { | ||
|
|
@@ -643,7 +646,7 @@ public ConfigProvider newConfigProvider(AbstractConfig config, String providerPr | |
| try (LoaderSwap loaderSwap = safeLoaderSwapper().apply(plugin.getClass().getClassLoader())) { | ||
| plugin.configure(configProviderConfig); | ||
| } | ||
| return plugin; | ||
| return Plugin.wrapInstance(plugin, metrics, WorkerConfig.CONFIG_PROVIDERS_CONFIG, Map.of("provider", providerName)); | ||
| } | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Always close provider plugins on failure (use finally) to avoid leaks
If ConfigTransformer construction or transform throws, provider plugins aren’t closed. Wrap with try/finally and include provider name in close logs.
Apply this diff:
If ConfigTransformer implements AutoCloseable, we should also close it. Check with:
🏁 Script executed:
Length of output: 42678
🏁 Script executed:
find . -type f -name ConfigTransformer.javaLength of output: 77
🏁 Script executed:
Length of output: 8388
Always close provider plugins on failure (use try/finally)
Wrap instantiation and transformation in a try/finally to guarantee plugins are closed on any exception—include the provider name in the close log. ConfigTransformer does not implement AutoCloseable, so it need not be closed.
📝 Committable suggestion
🤖 Prompt for AI Agents