Skip to content

Commit

Permalink
Amazon Q Code Transform: Improve telemetry to capture transform journ…
Browse files Browse the repository at this point in the history
…ey (#4731)
  • Loading branch information
tincheng authored Jul 29, 2024
1 parent 89da690 commit e85fb8a
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 140 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mockitoKotlin = "5.4.0"
mockk = "1.13.10"
nimbus-jose-jwt = "9.40"
node-gradle = "7.0.2"
telemetryGenerator = "1.0.230"
telemetryGenerator = "1.0.232"
testLogger = "4.0.0"
testRetry = "1.5.10"
# test-only; platform provides slf4j transitively at runtime. <233, 1.7.36; >=233, 2.0.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.utils.openTrouble
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 All @@ -60,12 +62,12 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
private val downloadedBuildLogPath = mutableMapOf<JobId, Path>()
private var isCurrentlyDownloading = AtomicBoolean(false)

internal suspend fun displayDiff(job: JobId) {
internal suspend fun displayDiff(job: JobId, source: CodeTransformVCSViewerSrcComponents) {
if (isCurrentlyDownloading.get()) return
when (val result = downloadArtifact(job, TransformationDownloadArtifactType.CLIENT_INSTRUCTIONS)) {
is DownloadArtifactResult.Success -> {
if (result.artifact !is CodeModernizerArtifact) return notifyUnableToApplyPatch("")
displayDiffUsingPatch(result.artifact.patch, job)
displayDiffUsingPatch(result.artifact.patch, job, source)
}
is DownloadArtifactResult.ParseZipFailure -> notifyUnableToApplyPatch(result.failureReason.errorMessage)
is DownloadArtifactResult.UnzipFailure -> notifyUnableToApplyPatch(result.failureReason.errorMessage)
Expand Down Expand Up @@ -203,13 +205,15 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
telemetryErrorMessage = "Unexpected error when downloading result ${e.localizedMessage}"
DownloadArtifactResult.ParseZipFailure(ParseZipFailureReason(artifactType, e.message.orEmpty()))
} finally {
// TODO: add artifact type to telemetry to differentiate downloads for client instructions vs logs
// TODO: Deprecated - remove once BI starts using new metric
telemetry.jobArtifactDownloadAndDeserializeTime(
downloadStartTime,
job,
totalDownloadBytes,
telemetryErrorMessage,
)

telemetry.downloadArtifact(mapArtifactTypes(artifactType), downloadStartTime, job, totalDownloadBytes, telemetryErrorMessage)
}
} catch (e: Exception) {
if (isPreFetch) return DownloadArtifactResult.Skipped
Expand All @@ -236,7 +240,7 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
/**
* Opens the built-in patch dialog to display the diff and allowing users to apply the changes locally.
*/
internal fun displayDiffUsingPatch(patchFile: VirtualFile, jobId: JobId) {
internal fun displayDiffUsingPatch(patchFile: VirtualFile, jobId: JobId, source: CodeTransformVCSViewerSrcComponents) {
runInEdt {
val dialog = ApplyPatchDifferentiatedDialog(
project,
Expand All @@ -254,10 +258,17 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
)
dialog.isModal = true

// TODO: deprecated metric - remove after BI started using new metric
telemetry.vcsDiffViewerVisible(jobId) // download succeeded
if (dialog.showAndGet()) {
telemetry.viewArtifact(CodeTransformArtifactType.ClientInstructions, jobId, "Submit", source)

// TODO: deprecated metric - remove after BI started using new metric
telemetry.vcsViewerSubmitted(jobId)
} else {
telemetry.viewArtifact(CodeTransformArtifactType.ClientInstructions, jobId, "Cancel", source)

// TODO: deprecated metric - remove after BI started using new metric
telemetry.vscViewerCancelled(jobId)
}
}
Expand Down Expand Up @@ -352,10 +363,11 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
)
}

fun displayDiffAction(jobId: JobId) = runReadAction {
fun displayDiffAction(jobId: JobId, source: CodeTransformVCSViewerSrcComponents) = runReadAction {
// TODO: deprecated metric - remove after BI started using new metric
telemetry.vcsViewerClicked(jobId)
projectCoroutineScope(project).launch {
displayDiff(jobId)
displayDiff(jobId, source)
}
}

Expand Down Expand Up @@ -410,6 +422,13 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
}
}

private fun mapArtifactTypes(artifactType: TransformationDownloadArtifactType): CodeTransformArtifactType =
when (artifactType) {
TransformationDownloadArtifactType.CLIENT_INSTRUCTIONS -> CodeTransformArtifactType.ClientInstructions
TransformationDownloadArtifactType.LOGS -> CodeTransformArtifactType.Logs
TransformationDownloadArtifactType.UNKNOWN_TO_SDK_VERSION -> CodeTransformArtifactType.Unknown
}

companion object {
val LOG = getLogger<ArtifactHandler>()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import software.aws.toolkits.jetbrains.services.codemodernizer.toolwindow.CodeMo
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.STATES_WHERE_PLAN_EXIST
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.createFileCopy
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.findLineNumberByString
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getMavenVersion
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getModuleOrProjectNameForFile
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getPathToHilArtifactPomFile
import software.aws.toolkits.jetbrains.services.codemodernizer.utils.getPathToHilDependencyReport
Expand All @@ -77,8 +78,10 @@ import software.aws.toolkits.jetbrains.utils.isRunningOnRemoteBackend
import software.aws.toolkits.jetbrains.utils.notifyStickyError
import software.aws.toolkits.jetbrains.utils.notifyStickyInfo
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.CodeTransformBuildSystem
import software.aws.toolkits.telemetry.CodeTransformCancelSrcComponents
import software.aws.toolkits.telemetry.CodeTransformPreValidationError
import software.aws.toolkits.telemetry.CodeTransformVCSViewerSrcComponents
import java.io.File
import java.nio.file.Path
import java.time.Instant
Expand Down Expand Up @@ -172,23 +175,36 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
}
val validatedBuildFiles = project.getSupportedBuildFilesWithSupportedJdk(supportedBuildFileNames, supportedJavaMappings)
return if (validatedBuildFiles.isNotEmpty()) {
ValidationResult(true, validatedBuildFiles = validatedBuildFiles, validatedProjectJdkName = projectJdk?.description.orEmpty())
ValidationResult(
true,
validatedBuildFiles = validatedBuildFiles,
validatedProjectJdkName = projectJdk?.description.orEmpty(),
buildSystem = CodeTransformBuildSystem.Maven,
buildSystemVersion = getMavenVersion(project)
)
} else {
ValidationResult(
false,
message("codemodernizer.notification.warn.invalid_project.description.reason.no_valid_files", supportedBuildFileNames.joinToString()),
InvalidTelemetryReason(
invalidReason = message(
"codemodernizer.notification.warn.invalid_project.description.reason.no_valid_files",
supportedBuildFileNames.joinToString()
),
invalidTelemetryReason = InvalidTelemetryReason(
CodeTransformPreValidationError.NonMavenProject,
if (isGradleProject(project)) "Gradle build" else "other build"
)
),
buildSystem = if (isGradleProject(project)) CodeTransformBuildSystem.Gradle else CodeTransformBuildSystem.Unknown
)
}
}

val result = validateCore(project)

// TODO: deprecated metric - remove after BI started using new metric
telemetry.sendValidationResult(result)

telemetry.validateProject(result)

return result
}

Expand Down Expand Up @@ -363,6 +379,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
}

fun runLocalMavenBuild(project: Project, customerSelection: CustomerSelection) {
// TODO: deprecated metric - remove after BI started using new metric
telemetry.jobStartedCompleteFromPopupDialog(customerSelection)

// Create and set a session
Expand Down Expand Up @@ -490,6 +507,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
if (!managerState.flags.getOrDefault(StateFlags.IS_ONGOING, false)) return@launch

// Gather project details
// TODO: deprecated metric - remove after BI started using new metric
if (onProjectFirstOpen) {
val validationResult = validate(project)
telemetry.sendValidationResult(validationResult, onProjectFirstOpen)
Expand Down Expand Up @@ -553,7 +571,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
private fun displayDiffNotificationAction(jobId: JobId): NotificationAction = NotificationAction.createSimple(
message("codemodernizer.notification.info.modernize_complete.view_diff")
) {
artifactHandler.displayDiffAction(jobId)
artifactHandler.displayDiffAction(jobId, CodeTransformVCSViewerSrcComponents.ToastNotification)
}

private fun displaySummaryNotificationAction(jobId: JobId) =
Expand Down Expand Up @@ -746,7 +764,8 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo

fun showDiff() {
val job = codeTransformationSession?.getActiveJobId() ?: return
artifactHandler.displayDiffAction(job)
// Use "TreeViewHeader" for Hub
artifactHandler.displayDiffAction(job, CodeTransformVCSViewerSrcComponents.TreeViewHeader)
}

fun handleCredentialsChanged() {
Expand Down
Loading

0 comments on commit e85fb8a

Please sign in to comment.