-
Notifications
You must be signed in to change notification settings - Fork 644
Ensure Executor tests use up-to-date cluster metadata #2338
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
Open
kyguy
wants to merge
3
commits into
linkedin:main
Choose a base branch
from
kyguy:fix-flaky-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
|
kyguy marked this conversation as resolved.
|
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
96 changes: 96 additions & 0 deletions
96
...se-control/src/main/java/com/linkedin/kafka/cruisecontrol/common/MetadataAdminClient.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,96 @@ | ||
| /* | ||
| * Copyright 2017 LinkedIn Corp. Licensed under the BSD 2-Clause License (the "License"). See License in the project root for license information. | ||
| */ | ||
|
|
||
| package com.linkedin.kafka.cruisecontrol.common; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ExecutionException; | ||
| import org.apache.kafka.clients.admin.Admin; | ||
| import org.apache.kafka.clients.admin.DescribeClusterResult; | ||
| import org.apache.kafka.clients.admin.TopicDescription; | ||
| import org.apache.kafka.common.Cluster; | ||
| import org.apache.kafka.common.Node; | ||
| import org.apache.kafka.common.PartitionInfo; | ||
| import org.apache.kafka.common.TopicPartitionInfo; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| /** | ||
| * Client for fetching Kafka cluster metadata using Kafka Admin APIs. | ||
| * | ||
| * This replaces the use of MetadataClient which relies on internal Kafka APIs. | ||
| */ | ||
| public class MetadataAdminClient { | ||
| private static final Logger LOG = LoggerFactory.getLogger(MetadataAdminClient.class); | ||
|
|
||
| private final Admin _adminClient; | ||
|
|
||
| /** | ||
| * Creates a new MetadataAdminClient. | ||
| * | ||
| * @param adminClient The AdminClient to use for fetching cluster metadata. | ||
| */ | ||
| public MetadataAdminClient(Admin adminClient) { | ||
| _adminClient = adminClient; | ||
| } | ||
|
|
||
| /** | ||
| * Close adminClient | ||
| */ | ||
| public void close() { | ||
|
kyguy marked this conversation as resolved.
Outdated
|
||
| if (_adminClient != null) { | ||
| try { | ||
| _adminClient.close(); | ||
| } catch (Exception e) { | ||
| LOG.warn("Failed to close AdminClient", e); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Fetches the current metadata for the Kafka cluster. | ||
| * | ||
| * @return a {@link Cluster} containing the cluster ID, broker nodes, and partition information for all topics | ||
| */ | ||
| public Cluster cluster() { | ||
| try { | ||
| Set<String> topicNames = _adminClient.listTopics().names().get(); | ||
|
|
||
| Map<String, TopicDescription> topicDescriptions = _adminClient.describeTopics(topicNames).allTopicNames().get(); | ||
|
|
||
| DescribeClusterResult describeResult = _adminClient.describeCluster(); | ||
| Collection<Node> nodes = describeResult.nodes().get(); | ||
| String clusterId = describeResult.clusterId().get(); | ||
|
|
||
| List<PartitionInfo> partitionInfos = new ArrayList<>(); | ||
|
|
||
| for (TopicDescription desc : topicDescriptions.values()) { | ||
| for (TopicPartitionInfo partInfo : desc.partitions()) { | ||
|
|
||
| Node leader = partInfo.leader(); | ||
| Node[] replicas = partInfo.replicas().toArray(Node[]::new); | ||
| Node[] isr = partInfo.isr().toArray(Node[]::new); | ||
|
|
||
| partitionInfos.add(new PartitionInfo(desc.name(), partInfo.partition(), leader, replicas, isr)); | ||
| } | ||
| } | ||
|
|
||
| return new Cluster(clusterId, nodes, partitionInfos, Collections.emptySet(), Collections.emptySet()); | ||
| } catch (InterruptedException e) { | ||
| Thread.currentThread().interrupt(); | ||
| LOG.error("Interrupted while fetching cluster metadata", e); | ||
| throw new RuntimeException("Interrupted while fetching cluster metadata", e); | ||
|
|
||
| } catch (ExecutionException e) { | ||
| LOG.error("ExecutionException while fetching cluster metadata", e); | ||
| // Could inspect e.getCause() and retry if RetriableException, but fail fast for now | ||
| throw new RuntimeException("Failed to fetch cluster metadata", e); | ||
| } | ||
| } | ||
| } | ||
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
|
kyguy marked this conversation as resolved.
|
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
|
kyguy marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
How is this related to fixing the Executor tests?
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.
Due to breaking changes in recent Docker Engine updates we need to upgrade Testcontainers to a version that adds compatibility fixes, either 1.21.4 or 2.0.3.
That being said, we could avoid this specific artifact name change by sticking with the 1.x versions instead or jumping to 2.x versions as I have done as part of my commit.
Let me update the version to 1.21.4 in my next commit to avoid this artifact name change.