-
Notifications
You must be signed in to change notification settings - Fork 207
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
Create OpenSearch source client with auth and lookup version to detect search strategy #2806
Changes from all commits
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,9 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.source.opensearch; | ||
|
||
public class OpenSearchIndexProgressState { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,59 @@ | |
*/ | ||
package org.opensearch.dataprepper.plugins.source.opensearch; | ||
|
||
import org.opensearch.dataprepper.model.buffer.Buffer; | ||
import org.opensearch.dataprepper.model.event.Event; | ||
import org.opensearch.dataprepper.model.record.Record; | ||
import org.opensearch.dataprepper.model.source.coordinator.SourceCoordinator; | ||
import org.opensearch.dataprepper.plugins.source.opensearch.worker.PitWorker; | ||
import org.opensearch.dataprepper.plugins.source.opensearch.worker.ScrollWorker; | ||
import org.opensearch.dataprepper.plugins.source.opensearch.worker.client.SearchAccessor; | ||
|
||
public class OpenSearchService { | ||
|
||
private final SearchAccessor searchAccessor; | ||
private final OpenSearchSourceConfiguration openSearchSourceConfiguration; | ||
private final SourceCoordinator<OpenSearchIndexProgressState> sourceCoordinator; | ||
private final Buffer<Record<Event>> buffer; | ||
|
||
private Thread searchWorkerThread; | ||
|
||
public static OpenSearchService createOpenSearchService(final SearchAccessor searchAccessor, | ||
final SourceCoordinator<OpenSearchIndexProgressState> sourceCoordinator, | ||
final OpenSearchSourceConfiguration openSearchSourceConfiguration, | ||
final Buffer<Record<Event>> buffer) { | ||
return new OpenSearchService(searchAccessor, sourceCoordinator, openSearchSourceConfiguration, buffer); | ||
} | ||
|
||
private OpenSearchService(final SearchAccessor searchAccessor, | ||
final SourceCoordinator<OpenSearchIndexProgressState> sourceCoordinator, | ||
final OpenSearchSourceConfiguration openSearchSourceConfiguration, | ||
final Buffer<Record<Event>> buffer) { | ||
this.searchAccessor = searchAccessor; | ||
this.openSearchSourceConfiguration = openSearchSourceConfiguration; | ||
this.buffer = buffer; | ||
this.sourceCoordinator = sourceCoordinator; | ||
this.sourceCoordinator.initialize(); | ||
} | ||
|
||
public void start() { | ||
// todo: to implement | ||
// Leverages a runnable (SearchWorker) to perform the querying on the source cluster | ||
switch(searchAccessor.getSearchContextType()) { | ||
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 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. Will do until we end up adding a search worker for this case |
||
case POINT_IN_TIME: | ||
searchWorkerThread = new Thread(new PitWorker(searchAccessor, openSearchSourceConfiguration, sourceCoordinator, buffer)); | ||
break; | ||
case SCROLL: | ||
searchWorkerThread = new Thread(new ScrollWorker(searchAccessor, openSearchSourceConfiguration, sourceCoordinator, buffer)); | ||
break; | ||
default: | ||
throw new IllegalArgumentException( | ||
String.format("Search context type must be POINT_IN_TIME or SCROLL, type %s was given instead", | ||
searchAccessor.getSearchContextType())); | ||
} | ||
|
||
searchWorkerThread.start(); | ||
} | ||
|
||
public void stop() { | ||
// todo: to implement | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,9 @@ | |
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.Size; | ||
import software.amazon.awssdk.arns.Arn; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider; | ||
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider; | ||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.services.sts.StsClient; | ||
import software.amazon.awssdk.services.sts.auth.StsAssumeRoleCredentialsProvider; | ||
import software.amazon.awssdk.services.sts.model.AssumeRoleRequest; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public class AwsAuthenticationConfiguration { | ||
private static final String AWS_IAM_ROLE = "role"; | ||
|
@@ -35,25 +27,6 @@ public class AwsAuthenticationConfiguration { | |
@Size(max = 5, message = "sts_header_overrides supports a maximum of 5 headers to override") | ||
private Map<String, String> awsStsHeaderOverrides; | ||
|
||
private void validateStsRoleArn() { | ||
final Arn arn = getArn(); | ||
if (!AWS_IAM.equals(arn.service())) { | ||
throw new IllegalArgumentException("sts_role_arn must be an IAM Role"); | ||
} | ||
final Optional<String> resourceType = arn.resource().resourceType(); | ||
if (resourceType.isEmpty() || !resourceType.get().equals(AWS_IAM_ROLE)) { | ||
throw new IllegalArgumentException("sts_role_arn must be an IAM Role"); | ||
} | ||
} | ||
|
||
private Arn getArn() { | ||
try { | ||
return Arn.fromString(awsStsRoleArn); | ||
} catch (final Exception e) { | ||
throw new IllegalArgumentException(String.format("Invalid ARN format for aws.sts_role_arn. Check the format of %s", awsStsRoleArn)); | ||
} | ||
} | ||
|
||
public String getAwsStsRoleArn() { | ||
return awsStsRoleArn; | ||
} | ||
|
@@ -62,36 +35,8 @@ public Region getAwsRegion() { | |
return awsRegion != null ? Region.of(awsRegion) : null; | ||
} | ||
|
||
public AwsCredentialsProvider authenticateAwsConfiguration() { | ||
|
||
final AwsCredentialsProvider awsCredentialsProvider; | ||
if (awsStsRoleArn != null && !awsStsRoleArn.isEmpty()) { | ||
|
||
validateStsRoleArn(); | ||
|
||
final StsClient stsClient = StsClient.builder() | ||
.region(getAwsRegion()) | ||
.build(); | ||
|
||
AssumeRoleRequest.Builder assumeRoleRequestBuilder = AssumeRoleRequest.builder() | ||
.roleSessionName("OpenSearch-Source-" + UUID.randomUUID()) | ||
.roleArn(awsStsRoleArn); | ||
if(awsStsHeaderOverrides != null && !awsStsHeaderOverrides.isEmpty()) { | ||
assumeRoleRequestBuilder = assumeRoleRequestBuilder | ||
.overrideConfiguration(configuration -> awsStsHeaderOverrides.forEach(configuration::putHeader)); | ||
} | ||
|
||
awsCredentialsProvider = StsAssumeRoleCredentialsProvider.builder() | ||
.stsClient(stsClient) | ||
.refreshRequest(assumeRoleRequestBuilder.build()) | ||
.build(); | ||
|
||
} else { | ||
// use default credential provider | ||
awsCredentialsProvider = DefaultCredentialsProvider.create(); | ||
} | ||
|
||
return awsCredentialsProvider; | ||
public Map<String, String> getAwsStsHeaderOverrides() { | ||
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. Nice, thanks for pulling this work in too. |
||
return awsStsHeaderOverrides; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.plugins.source.opensearch.worker; | ||
|
||
public interface SearchWorker extends Runnable { | ||
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. I like this change. Thanks for making this more extendable. |
||
} |
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.
Why is this file being changed here? Why are the number of threads reduced?
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.
That test runs over 50 times, and it was spawning 50 threads for each test. My build failed every time due to that with an error about being out of threads. It didn’t fail after I lowered it. Is this test really necessary for every conditional expression?