-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-14785: Connect offset read REST API #13434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7f2af62
KAFKA-14785: Connector offset read REST API
yashmayya 81cae66
Update trace log in MonitorableSourceConnector
yashmayya 5892ba1
Use configBackingStore instead of snapshot in AbstractHerder::connect…
yashmayya 44c0f88
Centralize exception handling in Worker::connectorOffsets instead of …
yashmayya bb68bca
Refactor HerderRequestHandler::completeOrForwardRequest to leverage H…
yashmayya 57dc764
Add fine grained error messages to partition key processing; refactor…
yashmayya 4b6c936
Run offset get requests on a worker executor thread rather than a her…
yashmayya ea01ed1
Submit request to executor only while fetching source connector offse…
yashmayya 42cd2d3
Test improvements
yashmayya 42eddd7
Minor cleanups
yashmayya 844c1fe
Override AbstractHerder::connectorOffsets in DistributedHerder and St…
yashmayya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
connect/runtime/src/test/java/org/apache/kafka/connect/storage/OffsetUtilsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /* | ||
| * 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.connect.storage; | ||
|
|
||
| import org.apache.kafka.common.utils.LogCaptureAppender; | ||
| import org.apache.kafka.connect.errors.DataException; | ||
| import org.apache.kafka.connect.json.JsonConverter; | ||
| import org.apache.kafka.connect.json.JsonConverterConfig; | ||
| import org.junit.Test; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
| import static org.hamcrest.CoreMatchers.containsString; | ||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertThrows; | ||
|
|
||
| public class OffsetUtilsTest { | ||
|
C0urante marked this conversation as resolved.
|
||
|
|
||
| private static final JsonConverter CONVERTER = new JsonConverter(); | ||
|
|
||
| static { | ||
| CONVERTER.configure(Collections.singletonMap(JsonConverterConfig.SCHEMAS_ENABLE_CONFIG, "false"), true); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValidateFormatNotMap() { | ||
| DataException e = assertThrows(DataException.class, () -> OffsetUtils.validateFormat(new Object())); | ||
| assertThat(e.getMessage(), containsString("Offsets must be specified as a Map")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValidateFormatMapWithNonStringKeys() { | ||
| Map<Object, Object> offsetData = new HashMap<>(); | ||
| offsetData.put("k1", "v1"); | ||
| offsetData.put(1, "v2"); | ||
| DataException e = assertThrows(DataException.class, () -> OffsetUtils.validateFormat(offsetData)); | ||
| assertThat(e.getMessage(), containsString("Offsets may only use String keys")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValidateFormatMapWithNonPrimitiveKeys() { | ||
| Map<Object, Object> offsetData = Collections.singletonMap("key", new Object()); | ||
| DataException e = assertThrows(DataException.class, () -> OffsetUtils.validateFormat(offsetData)); | ||
| assertThat(e.getMessage(), containsString("Offsets may only contain primitive types as values")); | ||
|
|
||
| Map<Object, Object> offsetData2 = Collections.singletonMap("key", new ArrayList<>()); | ||
| e = assertThrows(DataException.class, () -> OffsetUtils.validateFormat(offsetData2)); | ||
| assertThat(e.getMessage(), containsString("Offsets may only contain primitive types as values")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testValidateFormatWithValidFormat() { | ||
| Map<Object, Object> offsetData = Collections.singletonMap("key", 1); | ||
| // Expect no exception to be thrown | ||
| OffsetUtils.validateFormat(offsetData); | ||
| } | ||
|
|
||
| @Test | ||
| public void testProcessPartitionKeyNotList() { | ||
| try (LogCaptureAppender logCaptureAppender = LogCaptureAppender.createAndRegister(OffsetUtils.class)) { | ||
| Map<String, Set<Map<String, Object>>> connectorPartitions = new HashMap<>(); | ||
| OffsetUtils.processPartitionKey(serializePartitionKey(new HashMap<>()), new byte[0], CONVERTER, connectorPartitions); | ||
| // Expect no partition to be added to the map since the partition key is of an invalid format | ||
| assertEquals(0, connectorPartitions.size()); | ||
| assertEquals(1, logCaptureAppender.getMessages().size()); | ||
| assertThat(logCaptureAppender.getMessages().get(0), | ||
| containsString("Ignoring offset partition key with an unexpected format")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testProcessPartitionKeyListWithOneElement() { | ||
| try (LogCaptureAppender logCaptureAppender = LogCaptureAppender.createAndRegister(OffsetUtils.class)) { | ||
| Map<String, Set<Map<String, Object>>> connectorPartitions = new HashMap<>(); | ||
| OffsetUtils.processPartitionKey(serializePartitionKey(Collections.singletonList("")), new byte[0], CONVERTER, connectorPartitions); | ||
| // Expect no partition to be added to the map since the partition key is of an invalid format | ||
| assertEquals(0, connectorPartitions.size()); | ||
| assertEquals(1, logCaptureAppender.getMessages().size()); | ||
| assertThat(logCaptureAppender.getMessages().get(0), | ||
| containsString("Ignoring offset partition key with an unexpected number of elements")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testProcessPartitionKeyListWithElementsOfWrongType() { | ||
| try (LogCaptureAppender logCaptureAppender = LogCaptureAppender.createAndRegister(OffsetUtils.class)) { | ||
| Map<String, Set<Map<String, Object>>> connectorPartitions = new HashMap<>(); | ||
| OffsetUtils.processPartitionKey(serializePartitionKey(Arrays.asList(1, new HashMap<>())), new byte[0], CONVERTER, connectorPartitions); | ||
| // Expect no partition to be added to the map since the partition key is of an invalid format | ||
| assertEquals(0, connectorPartitions.size()); | ||
| assertEquals(1, logCaptureAppender.getMessages().size()); | ||
| assertThat(logCaptureAppender.getMessages().get(0), | ||
| containsString("Ignoring offset partition key with an unexpected format for the first element in the partition key list")); | ||
|
|
||
| OffsetUtils.processPartitionKey(serializePartitionKey(Arrays.asList("connector-name", new ArrayList<>())), new byte[0], CONVERTER, connectorPartitions); | ||
| // Expect no partition to be added to the map since the partition key is of an invalid format | ||
| assertEquals(0, connectorPartitions.size()); | ||
| assertEquals(2, logCaptureAppender.getMessages().size()); | ||
| assertThat(logCaptureAppender.getMessages().get(1), | ||
| containsString("Ignoring offset partition key with an unexpected format for the second element in the partition key list")); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testProcessPartitionKeyValidList() { | ||
| try (LogCaptureAppender logCaptureAppender = LogCaptureAppender.createAndRegister(OffsetUtils.class)) { | ||
| Map<String, Set<Map<String, Object>>> connectorPartitions = new HashMap<>(); | ||
| OffsetUtils.processPartitionKey(serializePartitionKey(Arrays.asList("connector-name", new HashMap<>())), new byte[0], CONVERTER, connectorPartitions); | ||
| assertEquals(1, connectorPartitions.size()); | ||
| assertEquals(0, logCaptureAppender.getMessages().size()); | ||
| } | ||
| } | ||
|
|
||
| private byte[] serializePartitionKey(Object key) { | ||
| return CONVERTER.fromConnectData("", null, key); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.