-
Notifications
You must be signed in to change notification settings - Fork 215
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
ENH: keep retrying when getSecretValue fails #4102
Closed
chenqi0805
wants to merge
6
commits into
opensearch-project:main
from
chenqi0805:enh/keep-retrying-when-getSecretValue-failure
Closed
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e3df0f3
ENH: keep retrying when getSecretValue fails
chenqi0805 7a7f525
MAINT: reset
chenqi0805 9157c3f
STY: unused import
chenqi0805 bd44678
MAINT: skip thread.sleep coverage
chenqi0805 7e90a8b
MAINT: float up infinite retry
chenqi0805 ffea654
Merge branch 'main' into enh/keep-retrying-when-getSecretValue-failure
chenqi0805 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.opensearch.dataprepper.model.annotations.SkipTestCoverageGenerated; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient; | ||
|
@@ -107,17 +108,26 @@ public void refresh(String secretConfigId) { | |
LOG.info("Finished retrieving latest secret in aws:secrets:{}.", secretConfigId); | ||
} | ||
|
||
@SkipTestCoverageGenerated | ||
private Object retrieveSecretsFromSecretManager(final AwsSecretManagerConfiguration awsSecretManagerConfiguration, | ||
final SecretsManagerClient secretsManagerClient) { | ||
final GetSecretValueRequest getSecretValueRequest = awsSecretManagerConfiguration | ||
.createGetSecretValueRequest(); | ||
final GetSecretValueResponse getSecretValueResponse; | ||
try { | ||
getSecretValueResponse = secretsManagerClient.getSecretValue(getSecretValueRequest); | ||
} catch (Exception e) { | ||
throw new RuntimeException( | ||
String.format("Unable to retrieve secret: %s", | ||
awsSecretManagerConfiguration.getAwsSecretId()), e); | ||
GetSecretValueResponse getSecretValueResponse; | ||
while (true) { | ||
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 don't think having an infinite loop this deep is a good idea. We should manage this in a thread specifically for this purpose. |
||
try { | ||
getSecretValueResponse = secretsManagerClient.getSecretValue(getSecretValueRequest); | ||
break; | ||
} catch (Exception e) { | ||
final long waitTimeInMillis = 1000L; | ||
LOG.error(String.format("Unable to retrieve secret: %s, wait for %dms to retry again.", | ||
awsSecretManagerConfiguration.getAwsSecretId(), waitTimeInMillis), e); | ||
try { | ||
Thread.sleep(waitTimeInMillis); | ||
} catch (InterruptedException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
} | ||
|
||
try { | ||
|
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
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.
This is intended for generated code and maybe boilerplate. This code is significant and should be tested.
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.
The motivation to put this is due to coverage shortage on the exception here:
but it might no avoidable with some logic improvement