-
Notifications
You must be signed in to change notification settings - Fork 274
fix(amazonq): retry S3 upload #5208
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
Changes from 9 commits
f18e5a9
85b0901
5182c60
71f09d8
4e70278
51aeedf
4de333b
c2a824a
3a53721
8767d37
f566e6e
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,4 @@ | ||
| { | ||
| "type" : "bugfix", | ||
| "description" : "Amazon Q Code Transformation: retry initial project upload" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import com.intellij.openapi.application.runInEdt | |
| import com.intellij.serviceContainer.AlreadyDisposedException | ||
| import com.intellij.util.io.HttpRequests | ||
| import kotlinx.coroutines.delay | ||
| import kotlinx.coroutines.withContext | ||
| import org.apache.commons.codec.digest.DigestUtils | ||
| import software.amazon.awssdk.core.exception.SdkClientException | ||
| import software.amazon.awssdk.services.codewhispererruntime.model.ResumeTransformationResponse | ||
|
|
@@ -20,11 +21,13 @@ import software.amazon.awssdk.services.codewhispererruntime.model.Transformation | |
| import software.amazon.awssdk.services.codewhispererruntime.model.TransformationUserActionStatus | ||
| import software.amazon.awssdk.services.codewhispererstreaming.model.TransformationDownloadArtifactType | ||
| import software.amazon.awssdk.services.ssooidc.model.SsoOidcException | ||
| import software.aws.toolkits.core.utils.Waiters.waitUntil | ||
| import software.aws.toolkits.core.utils.error | ||
| import software.aws.toolkits.core.utils.exists | ||
| import software.aws.toolkits.core.utils.getLogger | ||
| import software.aws.toolkits.core.utils.info | ||
| import software.aws.toolkits.core.utils.warn | ||
| import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineBgContext | ||
| import software.aws.toolkits.jetbrains.services.codemodernizer.client.GumbyClient | ||
| import software.aws.toolkits.jetbrains.services.codemodernizer.commands.CodeTransformMessageListener | ||
| import software.aws.toolkits.jetbrains.services.codemodernizer.model.CodeModernizerException | ||
|
|
@@ -55,6 +58,8 @@ import java.io.File | |
| import java.io.FileInputStream | ||
| import java.io.IOException | ||
| import java.net.ConnectException | ||
| import java.net.SocketTimeoutException | ||
| import java.net.UnknownHostException | ||
| import java.nio.file.Path | ||
| import java.time.Instant | ||
| import java.util.Base64 | ||
|
|
@@ -142,7 +147,7 @@ class CodeModernizerSession( | |
| * | ||
| * Based on [CodeWhispererCodeScanSession] | ||
| */ | ||
| fun createModernizationJob(copyResult: MavenCopyCommandsResult?): CodeModernizerStartJobResult { | ||
| suspend fun createModernizationJob(copyResult: MavenCopyCommandsResult?): CodeModernizerStartJobResult { | ||
| LOG.info { "Compressing local project" } | ||
| val payload: File? | ||
| var payloadSize = 0 | ||
|
|
@@ -377,8 +382,12 @@ class CodeModernizerSession( | |
| /** | ||
| * Adapted from [CodeWhispererCodeScanSession] | ||
| */ | ||
| fun uploadPayload(payload: File): String { | ||
| val sha256checksum: String = Base64.getEncoder().encodeToString(DigestUtils.sha256(FileInputStream(payload))) | ||
| suspend fun uploadPayload(payload: File): String { | ||
| val sha256checksum: String = Base64.getEncoder().encodeToString( | ||
| withContext(getCoroutineBgContext()) { | ||
| DigestUtils.sha256(FileInputStream(payload)) | ||
| } | ||
| ) | ||
| if (isDisposed.get()) { | ||
| throw AlreadyDisposedException("Disposed when about to create upload URL") | ||
| } | ||
|
|
@@ -394,17 +403,22 @@ class CodeModernizerSession( | |
| throw AlreadyDisposedException("Disposed when about to upload project artifact to s3") | ||
| } | ||
| val uploadStartTime = Instant.now() | ||
| try { | ||
| waitUntil( | ||
| exceptionsToIgnore = setOf( | ||
| UnknownHostException::class, | ||
| SocketTimeoutException::class, | ||
| HttpRequests.HttpStatusException::class, | ||
| ConnectException::class | ||
|
Contributor
Author
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.
|
||
| ) | ||
| ) { | ||
| clientAdaptor.uploadArtifactToS3( | ||
| createUploadUrlResponse.uploadUrl(), | ||
| payload, | ||
| sha256checksum, | ||
| createUploadUrlResponse.kmsKeyArn().orEmpty(), | ||
| ) { shouldStop.get() } | ||
| } catch (e: Exception) { | ||
| LOG.error { "Unexpected error when uploading project artifact to S3: $e" } | ||
| throw e // pass along error to callee | ||
| } | ||
| LOG.info { "Upload to S3 succeeded" } | ||
|
Contributor
Author
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'm not a big fan of implementing our own retry logic rather than doing it at the SDK layer, but the existing S3 client's upload functionality requires a bucket name as a part of the request, and 1) I don't think we should have the internal S3 bucket names we use floating around this repo, 2) we use multiple different buckets, and 3) we don't have access to the bucket name in the response of our CreateUploadUrl — this API would have to be changed and then we can use the existing S3 client.
Contributor
Author
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. Update: use |
||
| if (!shouldStop.get()) { | ||
| LOG.info { "Uploaded artifact. Latency: ${calculateTotalLatency(uploadStartTime, Instant.now())}ms" } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.