Skip to content

Commit 0495d56

Browse files
dhasani23David Hasani
andauthored
fix(CodeTransform): block upload if zip size > 1GB (#4143)
* feat(CodeTransform): block upload if zip size > 1GB * add changelog entry * make sure payloadSize is emitted in telemetry * re-order notification messages * alphabetize messages --------- Co-authored-by: David Hasani <[email protected]>
1 parent 6b5f024 commit 0495d56

File tree

7 files changed

+30
-3
lines changed

7 files changed

+30
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "feature",
3+
"description" : "CodeTransformation: block upload if project > 1GB"
4+
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerManager.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,10 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
405405
is CodeModernizerStartJobResult.CancelledMissingDependencies -> {
406406
CodeModernizerJobCompletedResult.JobAbortedMissingDependencies
407407
}
408+
409+
is CodeModernizerStartJobResult.CancelledZipTooLarge -> {
410+
CodeModernizerJobCompletedResult.JobAbortedZipTooLarge
411+
}
408412
}
409413
}
410414

@@ -591,6 +595,12 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
591595
project,
592596
listOf(openTroubleshootingGuideNotificationAction()),
593597
)
598+
is CodeModernizerJobCompletedResult.JobAbortedZipTooLarge -> notifyStickyInfo(
599+
message("codemodernizer.notification.warn.zip_too_large.title"),
600+
message("codemodernizer.notification.warn.zip_too_large.content"),
601+
project,
602+
listOf(openTroubleshootingGuideNotificationAction()),
603+
)
594604
}
595605
}
596606

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/CodeModernizerSession.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import java.util.concurrent.atomic.AtomicBoolean
4646
const val ZIP_SOURCES_PATH = "sources"
4747
const val BUILD_LOG_PATH = "build-logs.txt"
4848
const val UPLOAD_ZIP_MANIFEST_VERSION = 1.0F
49+
const val MAX_ZIP_SIZE = 1000000000 // 1GB
4950

5051
class CodeModernizerSession(
5152
val sessionContext: CodeModernizerSessionContext,
@@ -84,11 +85,18 @@ class CodeModernizerSession(
8485
}
8586

8687
payload = result.payload
88+
89+
val payloadSize = payload.length().toInt()
90+
8791
CodetransformTelemetry.jobCreateZipEndTime(
88-
codeTransformTotalByteSize = payload.length().toInt(),
92+
codeTransformTotalByteSize = payloadSize,
8993
codeTransformSessionId = CodeTransformTelemetryState.instance.getSessionId(),
9094
codeTransformRunTimeLatency = calculateTotalLatency(startTime, Instant.now())
9195
)
96+
97+
if (payloadSize > MAX_ZIP_SIZE) {
98+
return CodeModernizerStartJobResult.CancelledZipTooLarge
99+
}
92100
} catch (e: Exception) {
93101
val errorMessage = "Failed to create zip"
94102
LOG.error(e) { errorMessage }

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CodeModernizerJobCompletedResult.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ sealed class CodeModernizerJobCompletedResult {
1616
object ManagerDisposed : CodeModernizerJobCompletedResult()
1717
object JobAbortedBeforeStarting : CodeModernizerJobCompletedResult()
1818
object JobAbortedMissingDependencies : CodeModernizerJobCompletedResult()
19+
object JobAbortedZipTooLarge : CodeModernizerJobCompletedResult()
1920
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/model/CodeModernizerStartJobResult.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ sealed class CodeModernizerStartJobResult {
99
data class UnableToStartJob(val exception: String) : CodeModernizerStartJobResult()
1010
object Cancelled : CodeModernizerStartJobResult()
1111
object CancelledMissingDependencies : CodeModernizerStartJobResult()
12+
object CancelledZipTooLarge : CodeModernizerStartJobResult()
1213
object Disposed : CodeModernizerStartJobResult()
1314
}

jetbrains-core/src/software/aws/toolkits/jetbrains/services/codemodernizer/panels/managers/CodeModernizerBottomWindowPanelManager.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ class CodeModernizerBottomWindowPanelManager(private val project: Project) : JPa
180180
buildProgressSplitterPanelManager.apply {
181181
when (result) {
182182
is CodeModernizerJobCompletedResult.UnableToCreateJob,
183+
is CodeModernizerJobCompletedResult.JobAbortedZipTooLarge,
183184
is CodeModernizerJobCompletedResult.JobAbortedMissingDependencies -> setJobFailedToStartUI()
184185

185186
is CodeModernizerJobCompletedResult.RetryableFailure,

resources/resources/software/aws/toolkits/resources/MessagesBundle.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ codemodernizer.notification.warn.invalid_project.description.reason.not_logged_i
544544
codemodernizer.notification.warn.invalid_project.description.reason.remote_backend=We do not support transforming projects running on a remote backend.
545545
codemodernizer.notification.warn.invalid_project.description.reason.unknown=We could not find an upgrade eligible application. We currently support upgrade of Java applications of version 8 and 11.
546546
codemodernizer.notification.warn.maven_failed.content=We were unable to build and package your project and its dependencies. Please fix the issues shown in the opened build window and try again.
547-
codemodernizer.notification.warn.maven_failed.title=Q Code Transform unable to zip dependencies
547+
codemodernizer.notification.warn.maven_failed.title=Amazon Q Code Transform unable to zip dependencies
548548
codemodernizer.notification.warn.on_resume.unknown_status_response.content=We received data from Amazon Q in a format that the plugin cannot handle. You may need to update the plugin and then try again.
549549
codemodernizer.notification.warn.on_resume.unknown_status_response.title=Unable to resume job.
550550
codemodernizer.notification.warn.unable_to_generate_plan=The job failed before a code transform plan could be generated.
@@ -560,7 +560,9 @@ codemodernizer.notification.warn.zip_creation_failed=we were unable to zip the s
560560
codemodernizer.notification.warn.zip_creation_failed.reasons.mvn.content=We were unable to zip dependencies for the selected module as we ran into an issue, we will attempt to transform your code without your local dependencies: {0}
561561
codemodernizer.notification.warn.zip_creation_failed.reasons.mvn.content_not_installed=We are unable to transform your code as we were unable to zip up your dependencies using `mvn` or `mvnw` commands.
562562
codemodernizer.notification.warn.zip_creation_failed.reasons.mvn.title=Unable to zip module dependencies
563-
codemodernizer.notification.warn.zip_creation_failed.reasons.unknown=an unexpected error occurred
563+
codemodernizer.notification.warn.zip_creation_failed.reasons.unknown=An unexpected error occurred
564+
codemodernizer.notification.warn.zip_too_large.content=Your project size exceeds the Amazon Q Code Transformation upload limit of 1GB.
565+
codemodernizer.notification.warn.zip_too_large.title=Project size exceeds 1GB limit
564566
codemodernizer.patch.name=Patch with code changes required to upgrade to Java 17
565567
codemodernizer.toolwindow.banner.action.diff=View diff
566568
codemodernizer.toolwindow.banner.action.feedback=Provide Feedback

0 commit comments

Comments
 (0)