Skip to content

Commit

Permalink
telemetry(amazonq): telemetry updates (aws#5522)
Browse files Browse the repository at this point in the history
## Problem

Need to update telemetry to reflect that we are no longer emitting a
metric for API errors or latency, and to reflect the latest common
telemetry updates.


## Solution

Update telemetry as described.


---

<!--- REMINDER: Ensure that your PR meets the guidelines in
CONTRIBUTING.md -->

License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.

---------

Co-authored-by: David Hasani <[email protected]>
  • Loading branch information
dhasani23 and David Hasani authored Aug 30, 2024
1 parent 7330f78 commit 5073cc8
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 103 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"generateNonCodeFiles": "npm run generateNonCodeFiles -w packages/ --if-present"
},
"devDependencies": {
"@aws-toolkits/telemetry": "^1.0.247",
"@aws-toolkits/telemetry": "^1.0.250",
"@playwright/browser-chromium": "^1.43.1",
"@types/vscode": "^1.68.0",
"@types/vscode-webview": "^1.57.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async function validateJavaHome(): Promise<boolean> {
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_isDoubleClickedToTriggerInvalidProject.emit({
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformPreValidationError: 'ProjectJDKDiffersFromMavenJDK',
codeTransformPreValidationError: 'ProjectJDKDiffersFromBuildSystemJDK',
result: MetadataResult.Fail,
reason: `${transformByQState.getSourceJDKVersion()} (project) - ${javaVersionUsedByMaven} (maven)`,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,10 @@ export async function uploadArtifactToS3(
Math.round(uploadFileByteSize / 1000)
)

const apiStartTime = globals.clock.Date.now()
const response = await request.fetch('PUT', resp.uploadUrl, {
body: buffer,
headers: getHeadersObj(sha256, resp.kmsKeyArn),
}).response
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_logApiLatency.emit({
codeTransformApiNames: 'UploadZip',
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformUploadId: resp.uploadId,
codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime),
codeTransformTotalByteSize: uploadFileByteSize,
result: MetadataResult.Pass,
})
getLogger().info(`CodeTransformation: Status from S3 Upload = ${response.status}`)
} catch (e: any) {
let errorMessage = `The upload failed due to: ${(e as Error).message}. For more information, see the [Amazon Q documentation](${CodeWhispererConstants.codeTransformTroubleshootUploadError})`
Expand All @@ -149,21 +139,11 @@ export async function uploadArtifactToS3(

export async function resumeTransformationJob(jobId: string, userActionStatus: TransformationUserActionStatus) {
try {
const apiStartTime = globals.clock.Date.now()
const response = await codeWhisperer.codeWhispererClient.codeModernizerResumeTransformation({
transformationJobId: jobId,
userActionStatus, // can be "COMPLETED" or "REJECTED"
})
if (response) {
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_logApiLatency.emit({
codeTransformApiNames: 'ResumeTransformation',
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformJobId: jobId,
codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime),
codeTransformRequestId: response.$response.requestId,
result: MetadataResult.Pass,
})
// always store request ID, but it will only show up in a notification if an error occurs
return response.transformationStatus
}
Expand All @@ -180,20 +160,10 @@ export async function stopJob(jobId: string) {
}

try {
const apiStartTime = globals.clock.Date.now()
const response = await codeWhisperer.codeWhispererClient.codeModernizerStopCodeTransformation({
transformationJobId: jobId,
})
if (response !== undefined) {
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_logApiLatency.emit({
codeTransformApiNames: 'StopTransformation',
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformJobId: jobId,
codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime),
codeTransformRequestId: response.$response.requestId,
result: MetadataResult.Pass,
})
// always store request ID, but it will only show up in a notification if an error occurs
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
Expand All @@ -213,7 +183,6 @@ export async function uploadPayload(payloadFileName: string, uploadContext?: Upl
throwIfCancelled()
let response = undefined
try {
const apiStartTime = globals.clock.Date.now()
response = await codeWhisperer.codeWhispererClient.createUploadUrl({
contentChecksum: sha256,
contentChecksumType: CodeWhispererConstants.contentChecksumType,
Expand All @@ -223,15 +192,6 @@ export async function uploadPayload(payloadFileName: string, uploadContext?: Upl
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_logApiLatency.emit({
codeTransformApiNames: 'CreateUploadUrl',
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime),
codeTransformUploadId: response.uploadId,
codeTransformRequestId: response.$response.requestId,
result: MetadataResult.Pass,
})
} catch (e: any) {
const errorMessage = `The upload failed due to: ${(e as Error).message}`
getLogger().error(`CodeTransformation: CreateUploadUrl error: = ${e}`)
Expand Down Expand Up @@ -446,7 +406,6 @@ export async function startJob(uploadId: string) {
const sourceLanguageVersion = `JAVA_${transformByQState.getSourceJDKVersion()}`
const targetLanguageVersion = `JAVA_${transformByQState.getTargetJDKVersion()}`
try {
const apiStartTime = globals.clock.Date.now()
const response = await codeWhisperer.codeWhispererClient.codeModernizerStartCodeTransformation({
workspaceState: {
uploadId: uploadId,
Expand All @@ -461,15 +420,6 @@ export async function startJob(uploadId: string) {
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_logApiLatency.emit({
codeTransformApiNames: 'StartTransformation',
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime),
codeTransformJobId: response.transformationJobId,
codeTransformRequestId: response.$response.requestId,
result: MetadataResult.Pass,
})
return response.transformationJobId
} catch (e: any) {
const errorMessage = `Starting the job failed due to: ${(e as Error).message}`
Expand Down Expand Up @@ -586,19 +536,9 @@ export async function getTransformationPlan(jobId: string) {
response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({
transformationJobId: jobId,
})
const apiStartTime = globals.clock.Date.now()
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_logApiLatency.emit({
codeTransformApiNames: 'GetTransformationPlan',
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformJobId: jobId,
codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime),
codeTransformRequestId: response.$response.requestId,
result: MetadataResult.Pass,
})

const stepZeroProgressUpdates = response.transformationPlan.transformationSteps[0].progressUpdates

Expand Down Expand Up @@ -657,22 +597,12 @@ export async function getTransformationSteps(jobId: string, handleThrottleFlag:
if (handleThrottleFlag) {
await sleep(2000)
}
const apiStartTime = globals.clock.Date.now()
const response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformationPlan({
transformationJobId: jobId,
})
if (response.$response.requestId) {
transformByQState.setJobFailureMetadata(` (request ID: ${response.$response.requestId})`)
}
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_logApiLatency.emit({
codeTransformApiNames: 'GetTransformationPlan',
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformJobId: jobId,
codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime),
codeTransformRequestId: response.$response.requestId,
result: MetadataResult.Pass,
})
return response.transformationPlan.transformationSteps.slice(1) // skip step 0 (contains supplemental info)
} catch (e: any) {
const errorMessage = (e as Error).message
Expand All @@ -687,19 +617,9 @@ export async function pollTransformationJob(jobId: string, validStates: string[]
while (true) {
throwIfCancelled()
try {
const apiStartTime = globals.clock.Date.now()
const response = await codeWhisperer.codeWhispererClient.codeModernizerGetCodeTransformation({
transformationJobId: jobId,
})
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_logApiLatency.emit({
codeTransformApiNames: 'GetTransformation',
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformJobId: jobId,
codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime),
codeTransformRequestId: response.$response.requestId,
result: MetadataResult.Pass,
})
status = response.transformationJob.status!
if (CodeWhispererConstants.validStatesForBuildSucceeded.includes(status)) {
jobPlanProgress['buildCode'] = StepProgress.Succeeded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export async function validateOpenProjects(
// TODO: remove deprecated metric once BI started using new metrics
telemetry.codeTransform_isDoubleClickedToTriggerInvalidProject.emit({
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformPreValidationError: 'NonMavenProject',
codeTransformPreValidationError: 'UnsupportedBuildSystem',
result: MetadataResult.Fail,
reason: 'NoPomFileFound',
})
Expand Down
16 changes: 0 additions & 16 deletions packages/core/src/shared/utilities/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
import path from 'path'
import { CodeWhispererStreaming, ExportResultArchiveCommandInput } from '@amzn/codewhisperer-streaming'
import { ToolkitError } from '../errors'
import { CodeTransformTelemetryState } from '../../amazonqGumby/telemetry/codeTransformTelemetryState'
import { transformByQState } from '../../codewhisperer/models/model'
import { calculateTotalLatency } from '../../amazonqGumby/telemetry/codeTransformTelemetry'
import { telemetry } from '../telemetry/telemetry'
import fs from '../fs/fs'
import globals from '../../shared/extensionGlobals'

/**
* This class represents the structure of the archive returned by the ExportResultArchive endpoint
Expand All @@ -27,8 +22,6 @@ export async function downloadExportResultArchive(
exportResultArchiveArgs: ExportResultArchiveCommandInput,
toPath: string
) {
const apiStartTime = globals.clock.Date.now()
let totalDownloadBytes = 0
const result = await cwStreamingClient.exportResultArchive(exportResultArchiveArgs)

const buffer = []
Expand All @@ -42,18 +35,9 @@ export async function downloadExportResultArchive(
const chunkData = chunk.binaryPayloadEvent
if (chunkData.bytes) {
buffer.push(chunkData.bytes)
totalDownloadBytes += chunkData.bytes?.length
}
}
}

await fs.writeFile(toPath, Buffer.concat(buffer))
telemetry.codeTransform_logApiLatency.emit({
codeTransformApiNames: 'ExportResultArchive',
codeTransformSessionId: CodeTransformTelemetryState.instance.getSessionId(),
codeTransformJobId: transformByQState.getJobId(),
codeTransformRunTimeLatency: calculateTotalLatency(apiStartTime),
codeTransformTotalByteSize: totalDownloadBytes,
codeTransformRequestId: result.$metadata.requestId,
})
}

0 comments on commit 5073cc8

Please sign in to comment.