-
Notifications
You must be signed in to change notification settings - Fork 190
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
Kafka Source - Cleanup and Enhancements for MSK #3029
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 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 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 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 |
---|---|---|
|
@@ -18,7 +18,7 @@ public static class AwsMskConfig { | |
private String arn; | ||
|
||
@JsonProperty("broker_connection_type") | ||
private MskBrokerConnectionType brokerConnectionType; | ||
private MskBrokerConnectionType brokerConnectionType = MskBrokerConnectionType.PUBLIC; | ||
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. single VPC connection type should be default. but it can be addressed in next commit |
||
|
||
public String getArn() { | ||
return arn; | ||
|
This file contains 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 |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import org.opensearch.dataprepper.model.acknowledgements.AcknowledgementSetManager; | ||
import org.opensearch.dataprepper.plugins.kafka.configuration.KafkaSourceConfig; | ||
import org.opensearch.dataprepper.plugins.kafka.configuration.EncryptionType; | ||
import org.opensearch.dataprepper.plugins.kafka.configuration.MskBrokerConnectionType; | ||
import org.opensearch.dataprepper.plugins.kafka.configuration.AuthConfig; | ||
import org.opensearch.dataprepper.plugins.kafka.configuration.AwsConfig; | ||
import org.opensearch.dataprepper.plugins.kafka.configuration.AwsIamAuthConfig; | ||
|
@@ -33,16 +34,17 @@ | |
import org.opensearch.dataprepper.plugins.kafka.util.KafkaSourceJsonDeserializer; | ||
import org.opensearch.dataprepper.plugins.kafka.util.MessageFormat; | ||
|
||
import com.amazonaws.services.kafka.model.GetBootstrapBrokersRequest; | ||
import com.amazonaws.services.kafka.AWSKafka; | ||
import com.amazonaws.services.kafka.AWSKafkaClientBuilder; | ||
import com.amazonaws.ClientConfiguration; | ||
import com.amazonaws.services.kafka.model.GetBootstrapBrokersResult; | ||
import com.amazonaws.auth.AWSCredentialsProvider; | ||
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain; | ||
import com.amazonaws.auth.STSAssumeRoleSessionCredentialsProvider; | ||
import com.amazonaws.services.kafka.model.InternalServerErrorException; | ||
import com.amazonaws.services.kafka.model.ConflictException; | ||
import software.amazon.awssdk.services.kafka.KafkaClient; | ||
import software.amazon.awssdk.services.kafka.model.GetBootstrapBrokersRequest; | ||
import software.amazon.awssdk.services.kafka.model.GetBootstrapBrokersResponse; | ||
import software.amazon.awssdk.services.kafka.model.InternalServerErrorException; | ||
import software.amazon.awssdk.services.kafka.model.ConflictException; | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
import software.amazon.awssdk.services.sts.model.AssumeRoleRequest; | ||
import software.amazon.awssdk.services.sts.StsClient; | ||
import software.amazon.awssdk.regions.Region; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
@@ -170,27 +172,40 @@ private long calculateLongestThreadWaitingTime() { | |
} | ||
|
||
public String getBootStrapServersForMsk(final AwsIamAuthConfig awsIamAuthConfig, final AwsConfig awsConfig) { | ||
ClientConfiguration clientConfiguration = new ClientConfiguration(); | ||
AWSCredentialsProvider credentialProvider; | ||
if (awsIamAuthConfig == AwsIamAuthConfig.DEFAULT) { | ||
credentialProvider = new DefaultAWSCredentialsProviderChain(); | ||
} else if (awsIamAuthConfig == AwsIamAuthConfig.ROLE) { | ||
AwsCredentialsProvider credentialsProvider = DefaultCredentialsProvider.create(); | ||
if (awsIamAuthConfig == AwsIamAuthConfig.ROLE) { | ||
String sessionName = "data-prepper-kafka-session"+UUID.randomUUID(); | ||
credentialProvider = new STSAssumeRoleSessionCredentialsProvider.Builder(awsConfig.getStsRoleArn(), sessionName).build(); | ||
StsClient stsClient = StsClient.builder() | ||
.region(Region.of(awsConfig.getRegion())) | ||
.credentialsProvider(credentialsProvider) | ||
.build(); | ||
credentialsProvider = StsAssumeRoleCredentialsProvider | ||
.builder() | ||
.stsClient(stsClient) | ||
.refreshRequest( | ||
AssumeRoleRequest | ||
.builder() | ||
.roleArn(awsConfig.getStsRoleArn()) | ||
.roleSessionName(sessionName) | ||
.build() | ||
).build(); | ||
} else { | ||
throw new RuntimeException("Unknown AWS IAM auth mode"); | ||
} | ||
AWSKafka kafkaClient = AWSKafkaClientBuilder.standard() | ||
.withClientConfiguration(clientConfiguration) | ||
.withCredentials(credentialProvider) | ||
.withRegion(awsConfig.getRegion()) | ||
final AwsConfig.AwsMskConfig awsMskConfig = awsConfig.getAwsMskConfig(); | ||
KafkaClient kafkaClient = KafkaClient.builder() | ||
.credentialsProvider(credentialsProvider) | ||
.region(Region.of(awsConfig.getRegion())) | ||
.build(); | ||
final GetBootstrapBrokersRequest request = | ||
GetBootstrapBrokersRequest | ||
.builder() | ||
.clusterArn(awsMskConfig.getArn()) | ||
.build(); | ||
GetBootstrapBrokersRequest request = new GetBootstrapBrokersRequest(); | ||
String clusterArn = awsConfig.getAwsMskConfig().getArn(); | ||
request.setClusterArn(clusterArn); | ||
|
||
int numRetries = 0; | ||
boolean retryable; | ||
GetBootstrapBrokersResult result = null; | ||
GetBootstrapBrokersResponse result = null; | ||
do { | ||
retryable = false; | ||
try { | ||
|
@@ -205,8 +220,11 @@ public String getBootStrapServersForMsk(final AwsIamAuthConfig awsIamAuthConfig, | |
LOG.info("Failed to get bootstrap server information from MSK, using user configured bootstrap servers"); | ||
return sourceConfig.getBootStrapServers(); | ||
} | ||
// TODO return this based on the broker_connection_mode | ||
return result.getBootstrapBrokerStringSaslIam(); | ||
if (awsMskConfig.getBrokerConnectionType() == MskBrokerConnectionType.PUBLIC) { | ||
return result.bootstrapBrokerStringPublicSaslIam(); | ||
} else { | ||
return result.bootstrapBrokerStringVpcConnectivitySaslIam(); | ||
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. There are 3 connection types. single-vpc, public and multi-Vpc |
||
} | ||
} | ||
|
||
private Properties getConsumerProperties(final TopicConfig topicConfig) { | ||
|
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.
minor: it's better to not set sdk version here but you can change this later