Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Internal Review] updating messages in logs for transform #494

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CodeWhispererStreaming, ExportIntent } from '@amzn/codewhisperer-streaming'
import { Logging, Workspace } from '@aws/language-server-runtimes/server-interface'
import * as fs from 'fs'

Check warning on line 3 in server/aws-lsp-codewhisperer/src/language-server/netTransform/transformHandler.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "fs"

Check warning on line 3 in server/aws-lsp-codewhisperer/src/language-server/netTransform/transformHandler.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "fs"
import got from 'got'
import { v4 as uuidv4 } from 'uuid'
import {
Expand Down Expand Up @@ -29,7 +29,7 @@
import * as validation from './validation'
import path = require('path')
import AdmZip = require('adm-zip')
import { Console } from 'console'

Check warning on line 32 in server/aws-lsp-codewhisperer/src/language-server/netTransform/transformHandler.ts

View workflow job for this annotation

GitHub Actions / Test

Do not import Node.js builtin module "console"

Check warning on line 32 in server/aws-lsp-codewhisperer/src/language-server/netTransform/transformHandler.ts

View workflow job for this annotation

GitHub Actions / Test (Windows)

Do not import Node.js builtin module "console"
import { supportedProjects, unsupportedViewComponents } from './resources/SupportedProjects'
import { String } from 'aws-sdk/clients/codebuild'
import { ProjectMetadata } from 'aws-sdk/clients/lookoutvision'
Expand Down Expand Up @@ -75,9 +75,9 @@

const uploadId = await this.preTransformationUploadCode(payloadFilePath)
const request = getCWStartTransformRequest(userInputrequest, uploadId, this.logging)
this.logging.log('send request to start transform api: ' + JSON.stringify(request))
this.logging.log('Sending request to start transform api: ' + JSON.stringify(request))
const response = await this.client.codeModernizerStartCodeTransformation(request)
this.logging.log('response start transform api: ' + JSON.stringify(response))
this.logging.log('Response from start transform api: ' + JSON.stringify(response))
jonlouie marked this conversation as resolved.
Show resolved Hide resolved
return getCWStartTransformResponse(
response,
uploadId,
Expand All @@ -101,7 +101,7 @@
async preTransformationUploadCode(payloadFilePath: string): Promise<string> {
try {
const uploadId = await this.uploadPayloadAsync(payloadFilePath)
this.logging.log('artifact successfully uploaded. upload tracking id: ' + uploadId)
this.logging.log('Code artifacts were successfully uploaded. Tracking id for upload is : ' + uploadId)
jonlouie marked this conversation as resolved.
Show resolved Hide resolved
return uploadId
} catch (error) {
const errorMessage = (error as Error).message ?? 'Failed to upload zip file'
Expand Down Expand Up @@ -182,9 +182,9 @@
const getCodeTransformationRequest = {
transformationJobId: request.TransformationJobId,
} as GetTransformationRequest
this.logging.log('send request to get transform api: ' + JSON.stringify(getCodeTransformationRequest))
this.logging.log('Sending request to get transform api: ' + JSON.stringify(getCodeTransformationRequest))
const response = await this.client.codeModernizerGetCodeTransformation(getCodeTransformationRequest)
this.logging.log('response received from get transform api: ' + JSON.stringify(response))
this.logging.log('Response received from get transform api: ' + JSON.stringify(response))
return {
TransformationJob: response.transformationJob,
} as GetTransformResponse
Expand All @@ -203,12 +203,12 @@
transformationJobId: request.TransformationJobId,
} as GetTransformationRequest
this.logging.log(
'send request to get transform plan api: ' + JSON.stringify(getCodeTransformationPlanRequest)
'Sending request to get transform plan api: ' + JSON.stringify(getCodeTransformationPlanRequest)
)
const response = await this.client.codeModernizerGetCodeTransformationPlan(
getCodeTransformationPlanRequest
)
this.logging.log('received response from get transform plan api: ' + JSON.stringify(response))
this.logging.log('Received response from get transform plan api: ' + JSON.stringify(response))
return {
TransformationPlan: response.transformationPlan,
} as GetTransformPlanResponse
Expand Down Expand Up @@ -242,10 +242,10 @@
transformationJobId: request.TransformationJobId,
} as StopTransformationRequest
this.logging.log(
'send request to cancel transform plan api: ' + JSON.stringify(stopCodeTransformationRequest)
'Sending request to cancel transform plan api: ' + JSON.stringify(stopCodeTransformationRequest)
)
const response = await this.client.codeModernizerStopCodeTransformation(stopCodeTransformationRequest)
this.logging.log('received response from cancel transform plan api: ' + JSON.stringify(response))
this.logging.log('Received response from cancel transform plan api: ' + JSON.stringify(response))
let status: CancellationJobStatus
switch (response.transformationStatus) {
case 'STOPPED':
Expand Down Expand Up @@ -292,14 +292,13 @@
const getCodeTransformationRequest = {
transformationJobId: request.TransformationJobId,
} as GetTransformationRequest
this.logging.log('poll : send request to get transform api: ' + JSON.stringify(getCodeTransformationRequest))
this.logging.log(
'polling details: Sending request to get transform api: ' + JSON.stringify(getCodeTransformationRequest)
)
let response = await this.client.codeModernizerGetCodeTransformation(getCodeTransformationRequest)
this.logging.log('poll : received response from get transform api: ' + JSON.stringify(response))
this.logging.log('polling details: Received response from get transform api: ' + JSON.stringify(response))
jonlouie marked this conversation as resolved.
Show resolved Hide resolved
let status = response?.transformationJob?.status ?? PollTransformationStatus.NOT_FOUND

this.logging.log('validExitStatus here are : ' + validExitStatus)
this.logging.log('failureStatus here are : ' + failureStates)

while (status != PollTransformationStatus.TIMEOUT && !failureStates.includes(status)) {
try {
const apiStartTime = Date.now()
Expand All @@ -308,28 +307,31 @@
transformationJobId: request.TransformationJobId,
} as GetTransformationRequest
this.logging.log(
'poll : send request to get transform api: ' + JSON.stringify(getCodeTransformationRequest)
'polling details: Sending request to get transform api: ' +
JSON.stringify(getCodeTransformationRequest)
)
response = await this.client.codeModernizerGetCodeTransformation(getCodeTransformationRequest)
this.logging.log('poll : received response from get transform api: ' + JSON.stringify(response))
this.logging.log('poll : job status here : ' + response.transformationJob.status)
this.logging.log(
'polling details: Received response from get transform api: ' + JSON.stringify(response)
)
this.logging.log('polling details: Current job status is ' + response.transformationJob.status)

if (response.transformationJob?.status) {
this.logging.log(
'status is included in validExitSTatus for poll ' +
'Status matches to the desired final status of polling request' +
validExitStatus.includes(response.transformationJob.status)
)
}

if (validExitStatus.includes(status)) {
this.logging.log('returning status as : ' + status)
this.logging.log('Exiting polling loop with job status as : ' + status)
jonlouie marked this conversation as resolved.
Show resolved Hide resolved
break
}

status = response.transformationJob.status!
await this.sleep(10 * 1000)
timer += 10
this.logging.log('current polling timer ' + timer)
this.logging.log('polling details: Current polling timer ' + timer)
jonlouie marked this conversation as resolved.
Show resolved Hide resolved

if (timer > 24 * 3600 * 1000) {
status = PollTransformationStatus.TIMEOUT
Expand All @@ -338,7 +340,9 @@
getTransformAttempt = 0 // a successful polling will reset attempt
} catch (e: any) {
const errorMessage = (e as Error).message ?? 'Error in GetTransformation API call'
this.logging.log('poll : error polling transformation job from the server: ' + errorMessage)
this.logging.log(
'polling details : Error in polling transformation job from the server: ' + errorMessage
)
jonlouie marked this conversation as resolved.
Show resolved Hide resolved

getTransformAttempt += 1
if (getTransformAttempt >= getTransformMaxAttempts) {
Expand All @@ -351,12 +355,12 @@

const expDelayMs = this.getExpDelayForApiRetryMs(getTransformAttempt)
this.logging.log(
`poll : Attempt ${getTransformAttempt}/${getTransformMaxAttempts} to get transformation plan failed, retry in ${expDelayMs} seconds`
`polling details: Attempt ${getTransformAttempt}/${getTransformMaxAttempts} to get transformation plan failed, retry in ${expDelayMs} seconds`
)
await this.sleep(expDelayMs * 1000)
}
}
this.logging.log('poll : returning response from server : ' + JSON.stringify(response))
this.logging.log('polling details: Returning response from server : ' + JSON.stringify(response))
this.logSuggestionForFailureResponse(request, response.transformationJob, failureStates)
return {
TransformationJob: response.transformationJob,
Expand All @@ -372,7 +376,7 @@
})

const buffer = []
this.logging.log('artifact downloaded successfully.')
this.logging.log('Transformation results downloaded successfully.')

if (result.body === undefined) {
throw new Error('Empty response from CodeWhisperer Streaming service.')
Expand Down Expand Up @@ -446,7 +450,7 @@
'Please close Visual Studio, delete the directories where build artifacts are generated (e.g. bin and obj), and try running the transformation again.'
}
this.logging.log(
`Transformation job for job ${request.TransformationJobId} is ${status} due to "${reason}".
`Transformation job for Job ID ${request.TransformationJobId} is ${status} due to "${reason}".
${suggestion}`
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export const QNetTransformServerToken =
}
case GetTransformCommand: {
const request = params as GetTransformRequest
logging.log('Calling getTransform request with job Id: ' + request.TransformationJobId)
logging.log(
'Calling getTransform request with Transformation Job ID: ' + request.TransformationJobId
)
const response = await transformHandler.getTransformation(request)
if (response != null) {
emitTransformationJobReceivedTelemetry(telemetry, response)
Expand All @@ -75,14 +77,16 @@ export const QNetTransformServerToken =
}
case PollTransformCommand: {
const request = params as GetTransformRequest
logging.log('Calling pollTransform request with job Id: ' + request.TransformationJobId)
logging.log(
'Calling pollTransform request with Transformation Job ID: ' + request.TransformationJobId
)
const response = await transformHandler.pollTransformation(
request,
validStatesForComplete,
failureStates
)
logging.log(
'Transformation job for job Id' +
'Transformation job details for Transformation Job ID' +
request.TransformationJobId +
' is ' +
JSON.stringify(response)
Expand All @@ -92,14 +96,17 @@ export const QNetTransformServerToken =
}
case PollTransformForPlanCommand: {
const request = params as GetTransformRequest
logging.log('Calling pollTransformForPlan request with job Id: ' + request.TransformationJobId)
logging.log(
'Calling pollTransformForPlan request with Transformation Job ID: ' +
request.TransformationJobId
)
jonlouie marked this conversation as resolved.
Show resolved Hide resolved
const response = await transformHandler.pollTransformation(
request,
validStatesForGettingPlan,
failureStates
)
logging.log(
'Transformation job for job Id' +
'Transformation job details for Transformation Job ID' +
request.TransformationJobId +
' is ' +
JSON.stringify(response)
Expand All @@ -109,10 +116,13 @@ export const QNetTransformServerToken =
}
case GetTransformPlanCommand: {
const request = params as GetTransformPlanRequest
logging.log('Calling getTransformPlan request with job Id: ' + request.TransformationJobId)
logging.log(
'Calling getTransformPlan request with Transformation Job ID: ' +
request.TransformationJobId
)
const response = await transformHandler.getTransformationPlan(request)
logging.log(
'Transformation plan for job Id' +
'Transformation plan details for Transformation Job ID' +
request.TransformationJobId +
' is ' +
JSON.stringify(response)
Expand All @@ -122,7 +132,7 @@ export const QNetTransformServerToken =
}
case CancelTransformCommand: {
const request = params as CancelTransformRequest
logging.log('request job ID: ' + request.TransformationJobId)
logging.log('Cancellation request with Transformation Job ID: ' + request.TransformationJobId)
const response = await transformHandler.cancelTransformation(request)
emitTransformationJobCancelledTelemetry(telemetry, response, request.TransformationJobId)
return response
Expand All @@ -134,7 +144,10 @@ export const QNetTransformServerToken =
credentialsProvider,
customCWClientConfig
)
logging.log('Calling Download Archive with job Id: ' + request.TransformationJobId)
logging.log(
'Calling Download Transformation results with Transformation Job ID: ' +
request.TransformationJobId
)
const response = await transformHandler.downloadExportResultArchive(
cwStreamingClient,
request.TransformationJobId,
Expand Down
Loading