Skip to content

Commit

Permalink
Amazon Q Code Transform: clean up deprecated metrics (#4860)
Browse files Browse the repository at this point in the history
  • Loading branch information
tincheng authored Sep 11, 2024
1 parent 340bd34 commit c9c8505
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 194 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,6 @@ 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: 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) {
Expand Down Expand Up @@ -260,18 +252,10 @@ 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 @@ -385,8 +369,6 @@ class ArtifactHandler(private val project: Project, private val clientAdaptor: G
}

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, source)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,6 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo

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 @@ -380,9 +377,6 @@ 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
codeTransformationSession = null
val session = createCodeModernizerSession(customerSelection, project)
Expand Down Expand Up @@ -497,7 +491,7 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
/**
* Silently try to resume the job, informs users only when job successfully resumed, suppresses exceptions.
*/
fun tryResumeJob(onProjectFirstOpen: Boolean = false) = projectCoroutineScope(project).launch {
fun tryResumeJob() = projectCoroutineScope(project).launch {
try {
val notYetResumed = isResumingJob.compareAndSet(false, true)
// If the job is already running, compareAndSet will return false because the expected
Expand All @@ -509,13 +503,6 @@ class CodeModernizerManager(private val project: Project) : PersistentStateCompo
LOG.info { "Attempting to resume job, current state is: $managerState" }
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)
}

val context = managerState.toSessionContext(project)
val session = CodeModernizerSession(context)
val lastJobId = managerState.getLatestJobId()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,6 @@ class CodeModernizerSession(
payload = result.payload
payloadSize = payload.length().toInt()

// TODO: deprecated metric - remove after BI started using new metric
telemetry.jobCreateZipEndTime(payloadSize, startTime)

LOG.info { "Uploading zip file with size: $payloadSize bytes" }

if (payloadSize > MAX_ZIP_SIZE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import software.aws.toolkits.telemetry.CodeTransformBuildCommand
import software.aws.toolkits.telemetry.CodeTransformCancelSrcComponents
import software.aws.toolkits.telemetry.CodeTransformJavaSourceVersionsAllowed
import software.aws.toolkits.telemetry.CodeTransformJavaTargetVersionsAllowed
import software.aws.toolkits.telemetry.CodeTransformMavenBuildCommand
import software.aws.toolkits.telemetry.CodeTransformPatchViewerCancelSrcComponents
import software.aws.toolkits.telemetry.CodeTransformPreValidationError
import software.aws.toolkits.telemetry.CodeTransformVCSViewerSrcComponents
import software.aws.toolkits.telemetry.CodetransformTelemetry
Expand All @@ -33,108 +31,13 @@ import java.time.Instant
import java.util.Base64

/**
* CodeModernizerTelemetry contains helper functions for common operations that require telemetry.
* CodeModernizerTelemetry contains g functions for common operations that require telemetry.
*/
@Service(Service.Level.PROJECT)
class CodeTransformTelemetryManager(private val project: Project) {
private val sessionId get() = CodeTransformTelemetryState.instance.getSessionId()
private val currentJobStatus get() = CodeModernizerSessionState.getInstance(project).currentJobStatus.toString()

/**
* TODO: DEPRECATED METRICS below this comment - remove once BI starts using new metrics
*/
fun sendValidationResult(validationResult: ValidationResult, onProjectFirstOpen: Boolean = false) {
// Old telemetry event to be fired only when users click on transform
if (!validationResult.valid && !onProjectFirstOpen) {
CodetransformTelemetry.isDoubleClickedToTriggerInvalidProject(
codeTransformPreValidationError = validationResult.invalidTelemetryReason.category ?: CodeTransformPreValidationError.Unknown,
codeTransformSessionId = sessionId,
result = Result.Failed,
reason = validationResult.invalidTelemetryReason.additonalInfo
)
}

val validationError = if (validationResult.valid) {
null
} else {
validationResult.invalidTelemetryReason.category ?: CodeTransformPreValidationError.Unknown
}

// New projectDetails metric should always be fired whether the project was valid or invalid
CodetransformTelemetry.projectDetails(
codeTransformSessionId = sessionId,
result = if (validationResult.valid) Result.Succeeded else Result.Failed,
reason = if (validationResult.valid) null else validationResult.invalidTelemetryReason.additonalInfo,
codeTransformPreValidationError = validationError,
codeTransformLocalJavaVersion = project.tryGetJdk().toString()
)
}

fun jobStartedCompleteFromPopupDialog(customerSelection: CustomerSelection) = CodetransformTelemetry.jobStartedCompleteFromPopupDialog(
codeTransformJavaSourceVersionsAllowed = CodeTransformJavaSourceVersionsAllowed.from(customerSelection.sourceJavaVersion.name),
codeTransformJavaTargetVersionsAllowed = CodeTransformJavaTargetVersionsAllowed.from(customerSelection.targetJavaVersion.name),
codeTransformSessionId = sessionId,
codeTransformProjectId = getProjectHash(customerSelection),
)

fun jobCreateZipEndTime(payloadSize: Int, startTime: Instant) = CodetransformTelemetry.jobCreateZipEndTime(
codeTransformTotalByteSize = payloadSize,
codeTransformSessionId = sessionId,
codeTransformRunTimeLatency = calculateTotalLatency(startTime, Instant.now()),
)

fun vcsDiffViewerVisible(jobId: JobId) = CodetransformTelemetry.vcsDiffViewerVisible(
codeTransformSessionId = sessionId,
codeTransformJobId = jobId.id,
)

fun vcsViewerSubmitted(jobId: JobId) = CodetransformTelemetry.vcsViewerSubmitted(
codeTransformSessionId = sessionId,
codeTransformJobId = jobId.id,
codeTransformStatus = currentJobStatus,
)

fun vscViewerCancelled(jobId: JobId) = CodetransformTelemetry.vcsViewerCanceled(
codeTransformPatchViewerCancelSrcComponents = CodeTransformPatchViewerCancelSrcComponents.CancelButton,
codeTransformSessionId = sessionId,
codeTransformJobId = jobId.id,
codeTransformStatus = currentJobStatus,
)

fun vcsViewerClicked(jobId: JobId) = CodetransformTelemetry.vcsViewerClicked(
codeTransformVCSViewerSrcComponents = CodeTransformVCSViewerSrcComponents.ToastNotification,
codeTransformSessionId = sessionId,
codeTransformJobId = jobId.id,
)

fun jobArtifactDownloadAndDeserializeTime(downloadStartTime: Instant, jobId: JobId, totalDownloadBytes: Int, telemetryErrorMessage: String?) {
CodetransformTelemetry.jobArtifactDownloadAndDeserializeTime(
codeTransformSessionId = sessionId,
codeTransformRunTimeLatency = calculateTotalLatency(downloadStartTime, Instant.now()),
codeTransformJobId = jobId.id,
codeTransformTotalByteSize = totalDownloadBytes,
codeTransformRuntimeError = telemetryErrorMessage,
)
}

fun mvnBuildFailed(mavenBuildCommand: CodeTransformMavenBuildCommand, error: String) {
CodetransformTelemetry.mvnBuildFailed(
codeTransformSessionId = sessionId,
codeTransformMavenBuildCommand = mavenBuildCommand,
reason = error
)
}

fun dependenciesCopied() = CodetransformTelemetry.dependenciesCopied(codeTransformSessionId = sessionId)

fun jobIsStartedFromChatPrompt() {
CodetransformTelemetry.jobIsStartedFromChatPrompt(codeTransformSessionId = sessionId, credentialSourceId = getAuthType(project))
}

/**
* END - DEPRECATED METRICS (below are new metrics to keep)
*/

fun initiateTransform(telemetryErrorMessage: String? = null) {
CodetransformTelemetry.initiateTransform(
codeTransformSessionId = sessionId,
Expand Down Expand Up @@ -265,6 +168,7 @@ class CodeTransformTelemetryManager(private val project: Project) {
)

fun totalRunTime(codeTransformResultStatusMessage: String, jobId: JobId?) = CodetransformTelemetry.totalRunTime(
buildSystemVersion = getMavenVersion(project),
codeTransformJobId = jobId?.toString(),
codeTransformSessionId = sessionId,
codeTransformResultStatusMessage = codeTransformResultStatusMessage,
Expand All @@ -273,7 +177,6 @@ class CodeTransformTelemetryManager(private val project: Project) {
Instant.now()
),
codeTransformLocalJavaVersion = getJavaVersionFromProjectSetting(project),
codeTransformLocalMavenVersion = getMavenVersion(project),
)

fun error(errorMessage: String) = CodetransformTelemetry.logGeneralError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ class CodeTransformChatController(

codeTransformChatHelper.chatDelayShort()

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

codeTransformChatHelper.addNewMessage(
buildUserInputChatContent(context.project, validationResult)
)
Expand Down
Loading

0 comments on commit c9c8505

Please sign in to comment.