Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mockitoKotlin = "5.4.0"
mockk = "1.13.10"
nimbus-jose-jwt = "9.40"
node-gradle = "7.0.2"
telemetryGenerator = "1.0.284"
telemetryGenerator = "1.0.291"
testLogger = "4.0.0"
testRetry = "1.5.10"
# test-only; platform provides slf4j transitively at runtime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import software.aws.toolkits.jetbrains.utils.notifyStickyInfo
import software.aws.toolkits.jetbrains.utils.notifyStickyWarn
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.CodeTransformArtifactType
import software.aws.toolkits.telemetry.CodeTransformVCSViewerSrcComponents
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
Expand Down Expand Up @@ -93,17 +92,17 @@ class ArtifactHandler(
private var totalPatchFiles: Int = 0
private var sharedPatchIndex: Int = 0

internal suspend fun displayDiff(job: JobId, source: CodeTransformVCSViewerSrcComponents) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed source because it's not useful to us

internal suspend fun displayDiff(job: JobId) {
if (isCurrentlyDownloading.get()) return
when (val result = downloadArtifact(job, TransformationDownloadArtifactType.CLIENT_INSTRUCTIONS)) {
is DownloadArtifactResult.Success -> {
if (result.artifact !is CodeModernizerArtifact) return notifyUnableToApplyPatch("")
totalPatchFiles = result.artifact.patches.size
if (result.artifact.description == null) {
displayDiffUsingPatch(result.artifact.patches.first(), totalPatchFiles, null, job, source)
displayDiffUsingPatch(result.artifact.patches.first(), totalPatchFiles, null, job)
} else {
val diffDescription = result.artifact.description[getCurrentPatchIndex()]
displayDiffUsingPatch(result.artifact.patches[getCurrentPatchIndex()], totalPatchFiles, diffDescription, job, source)
displayDiffUsingPatch(result.artifact.patches[getCurrentPatchIndex()], totalPatchFiles, diffDescription, job)
}
}
is DownloadArtifactResult.ParseZipFailure -> notifyUnableToApplyPatch(result.failureReason.errorMessage)
Expand Down Expand Up @@ -285,7 +284,6 @@ class ArtifactHandler(
totalPatchFiles: Int,
diffDescription: PatchInfo?,
jobId: JobId,
source: CodeTransformVCSViewerSrcComponents,
) {
withContext(EDT) {
val dialog = ApplyPatchDifferentiatedDialog(
Expand All @@ -312,8 +310,7 @@ class ArtifactHandler(
dialog.isModal = true

if (dialog.showAndGet()) {
telemetry.submitSelection("Submit-${diffDescription?.name}")
telemetry.viewArtifact(CodeTransformArtifactType.ClientInstructions, jobId, "Submit", source)
telemetry.submitSelection("Submit-${diffDescription?.name}", jobId.toString())
if (diffDescription == null) {
val resultContent = CodeTransformChatMessageContent(
type = CodeTransformChatMessageType.PendingAnswer,
Expand Down Expand Up @@ -352,7 +349,7 @@ class ArtifactHandler(
}
}
} else {
telemetry.viewArtifact(CodeTransformArtifactType.ClientInstructions, jobId, "Cancel", source)
telemetry.submitSelection("Cancel", jobId.toString())
}
}
}
Expand Down Expand Up @@ -465,9 +462,9 @@ class ArtifactHandler(
)
}

fun displayDiffAction(jobId: JobId, source: CodeTransformVCSViewerSrcComponents) = runReadAction {
fun displayDiffAction(jobId: JobId) = runReadAction {
projectCoroutineScope(project).launch {
displayDiff(jobId, source)
displayDiff(jobId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import software.aws.toolkits.telemetry.CodeTransformCancelSrcComponents
import software.aws.toolkits.telemetry.CodeTransformJavaSourceVersionsAllowed
import software.aws.toolkits.telemetry.CodeTransformJavaTargetVersionsAllowed
import software.aws.toolkits.telemetry.CodeTransformPreValidationError
import software.aws.toolkits.telemetry.CodeTransformVCSViewerSrcComponents
import software.aws.toolkits.telemetry.CodetransformTelemetry
import software.aws.toolkits.telemetry.MetricResult
import software.aws.toolkits.telemetry.Result
import java.time.Instant
import java.util.Base64
Expand Down Expand Up @@ -65,13 +65,14 @@ class CodeTransformTelemetryManager(private val project: Project) {
)
}

fun submitSelection(userChoice: String, customerSelection: CustomerSelection? = null, telemetryErrorMessage: String? = null) {
fun submitSelection(userChoice: String, jobId: String? = null, customerSelection: CustomerSelection? = null, telemetryErrorMessage: String? = null) {
CodetransformTelemetry.submitSelection(
// TODO: remove below 2 lines (JavaSource / JavaTarget) once BI is updated to use source / target
codeTransformJavaSourceVersionsAllowed = CodeTransformJavaSourceVersionsAllowed.from(customerSelection?.sourceJavaVersion?.name.orEmpty()),
codeTransformJavaTargetVersionsAllowed = CodeTransformJavaTargetVersionsAllowed.from(customerSelection?.targetJavaVersion?.name.orEmpty()),
codeTransformSessionId = sessionId,
codeTransformProjectId = customerSelection?.let { getProjectHash(it) },
codeTransformJobId = jobId,
source = if (userChoice == "Confirm-Java") customerSelection?.sourceJavaVersion?.name.orEmpty() else customerSelection?.sourceVendor.orEmpty(),
target = if (userChoice == "Confirm-Java") customerSelection?.targetJavaVersion?.name.orEmpty() else customerSelection?.targetVendor.orEmpty(),
userChoice = userChoice,
Expand Down Expand Up @@ -128,25 +129,6 @@ class CodeTransformTelemetryManager(private val project: Project) {
)
}

fun viewArtifact(
artifactType: CodeTransformArtifactType,
jobId: JobId,
userChoice: String,
source: CodeTransformVCSViewerSrcComponents,
telemetryErrorMessage: String? = null,
) {
CodetransformTelemetry.viewArtifact(
codeTransformArtifactType = artifactType,
codeTransformVCSViewerSrcComponents = source,
codeTransformSessionId = sessionId,
codeTransformJobId = jobId.id,
codeTransformStatus = currentJobStatus,
userChoice = userChoice,
result = if (telemetryErrorMessage.isNullOrEmpty()) Result.Succeeded else Result.Failed,
reason = telemetryErrorMessage,
)
}

fun getProjectHash(customerSelection: CustomerSelection) = Base64.getEncoder().encodeToString(
DigestUtils.sha256(customerSelection.configurationFile?.toNioPath()?.toAbsolutePath().toString())
)
Expand Down Expand Up @@ -196,12 +178,12 @@ class CodeTransformTelemetryManager(private val project: Project) {

fun logHil(jobId: String, metaData: HilTelemetryMetaData, success: Boolean, reason: String) {
CodetransformTelemetry.humanInTheLoop(
project,
jobId,
metaData.toString(),
sessionId,
reason,
success,
project = project,
codeTransformJobId = jobId,
codeTransformMetadata = metaData.toString(),
codeTransformSessionId = sessionId,
reason = reason,
result = if (success) MetricResult.Succeeded else MetricResult.Failed,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would recommend using Result.Succeeded and Result.Failed here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw that Result is deprecated in favor of MetricResult

)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.utils.unzipFile
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.validateSctMetadata
import software.aws.toolkits.jetbrains.services.cwc.messages.ChatMessageType
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.CodeTransformVCSViewerSrcComponents

class CodeTransformChatController(
private val context: AmazonQAppInitContext,
Expand Down Expand Up @@ -273,7 +272,7 @@ class CodeTransformChatController(

override suspend fun processCodeTransformCancelAction(message: IncomingCodeTransformMessage.CodeTransformCancel) {
if (!checkForAuth(message.tabId)) {
telemetry.submitSelection("Cancel", null, "User is not authenticated")
telemetry.submitSelection("Cancel", null, null, "User is not authenticated")
return
}

Expand All @@ -288,7 +287,7 @@ class CodeTransformChatController(

override suspend fun processCodeTransformStartAction(message: IncomingCodeTransformMessage.CodeTransformStart) {
if (!checkForAuth(message.tabId)) {
telemetry.submitSelection("Confirm", null, "User is not authenticated")
telemetry.submitSelection("Confirm", null, null, "User is not authenticated")
return
}

Expand All @@ -311,7 +310,7 @@ class CodeTransformChatController(
codeModernizerManager.createCodeModernizerSession(selection, context.project)

// Publish metric to capture user selection before local build starts
telemetry.submitSelection("Confirm-Java", selection)
telemetry.submitSelection("Confirm-Java", null, selection)

codeTransformChatHelper.run {
addNewMessage(buildUserInputSkipTestsFlagChatIntroContent())
Expand Down Expand Up @@ -343,7 +342,7 @@ class CodeTransformChatController(

unzipFile(selectedZipFile.toNioPath(), extractedZip.toPath(), true)

val sctFile = extractedZip.listFiles { file -> file.name.endsWith(".sct") }.firstOrNull()
val sctFile = extractedZip.listFiles { file -> file.name.endsWith(".sct") }?.firstOrNull()

val metadataValidationResult = validateSctMetadata(sctFile)

Expand Down Expand Up @@ -373,7 +372,7 @@ class CodeTransformChatController(
sqlMetadataZip = extractedZip,
)
codeModernizerManager.createCodeModernizerSession(selection, context.project)
telemetry.submitSelection("Confirm-SQL", selection)
telemetry.submitSelection("Confirm-SQL", null, selection)
}
}

Expand Down Expand Up @@ -494,7 +493,6 @@ class CodeTransformChatController(
override suspend fun processCodeTransformViewDiff(message: IncomingCodeTransformMessage.CodeTransformViewDiff) {
artifactHandler.displayDiffAction(
CodeModernizerSessionState.getInstance(context.project).currentJobId as JobId,
CodeTransformVCSViewerSrcComponents.Chat
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.model.ValidationR
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.filterOnlyParentFiles
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.unzipFile
import software.aws.toolkits.telemetry.CodeTransformPreValidationError
import software.aws.toolkits.telemetry.CodeTransformVCSViewerSrcComponents
import kotlin.io.path.Path
import kotlin.io.path.createTempDirectory
import kotlin.io.path.exists
Expand All @@ -55,7 +54,7 @@ class CodeWhispererCodeModernizerTest : CodeWhispererCodeModernizerTestBase() {
doNothing().whenever(handler).notifyUnableToApplyPatch(any())
val result = DownloadArtifactResult.ParseZipFailure(expectedError)
doReturn(result).whenever(handler).downloadArtifact(any(), eq(TransformationDownloadArtifactType.CLIENT_INSTRUCTIONS), eq(false))
handler.displayDiff(jobId, CodeTransformVCSViewerSrcComponents.ToastNotification)
handler.displayDiff(jobId)
verify(handler, times(1)).notifyUnableToApplyPatch(any())
}

Expand Down Expand Up @@ -136,15 +135,14 @@ class CodeWhispererCodeModernizerTest : CodeWhispererCodeModernizerTestBase() {
doAnswer {
mockDialog.showAndGet()
mockDialog
}.whenever(handler).displayDiffUsingPatch(any(), any(), any(), any(), any())
handler.displayDiff(jobId, CodeTransformVCSViewerSrcComponents.Chat)
}.whenever(handler).displayDiffUsingPatch(any(), any(), any(), any())
handler.displayDiff(jobId)
verify(handler, never()).notifyUnableToApplyPatch(any())
verify(handler, times(1)).displayDiffUsingPatch(
testCodeModernizerArtifact.patches[0],
testCodeModernizerArtifact.patches.size,
testCodeModernizerArtifact.description?.get(0),
jobId,
CodeTransformVCSViewerSrcComponents.Chat
)
}

Expand Down
Loading