Skip to content

Commit

Permalink
Fix reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
siakmun-aws committed Dec 18, 2024
1 parent 949d877 commit b911b63
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 45 deletions.
36 changes: 10 additions & 26 deletions packages/core/src/amazonqFeatureDev/controllers/chat/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,7 @@ export class FeatureDevController {
canBeVoted: true,
})
this.messenger.sendUpdatePlaceholder(tabID, i18n('AWS.amazonq.featureDev.pillText.generatingCode'))
await session.sendMetricDataTelemetry(
MetricDataOperationName.START_CODE_GENERATION,
MetricDataResult.SUCCESS
)
await session.sendMetricDataTelemetry(MetricDataOperationName.StartCodeGeneration, MetricDataResult.Success)
await session.send(message)
const filePaths = session.state.filePaths ?? []
const deletedFiles = session.state.deletedFiles ?? []
Expand Down Expand Up @@ -493,40 +490,27 @@ export class FeatureDevController {
} catch (err: any) {
getLogger().error(`${featureName}: Error during code generation: ${err}`)

let result: string
switch (err.constructor.name) {
case FeatureDevServiceError.name:
if (err.code === 'EmptyPatchException') {
await session.sendMetricDataTelemetry(
MetricDataOperationName.END_CODE_GENERATION,
MetricDataResult.LLMFAILURE
)
result = MetricDataResult.LlmFailure
} else if (err.code === 'GuardrailsException' || err.code === 'ThrottlingException') {
await session.sendMetricDataTelemetry(
MetricDataOperationName.END_CODE_GENERATION,
MetricDataResult.ERROR
)
result = MetricDataResult.Error
} else {
await session.sendMetricDataTelemetry(
MetricDataOperationName.END_CODE_GENERATION,
MetricDataResult.FAULT
)
result = MetricDataResult.Fault
}
break
case PromptRefusalException.name:
case NoChangeRequiredException.name:
await session.sendMetricDataTelemetry(
MetricDataOperationName.END_CODE_GENERATION,
MetricDataResult.ERROR
)
result = MetricDataResult.Error
break
default:
await session.sendMetricDataTelemetry(
MetricDataOperationName.END_CODE_GENERATION,
MetricDataResult.FAULT
)

result = MetricDataResult.Fault
break
}

await session.sendMetricDataTelemetry(MetricDataOperationName.EndCodeGeneration, result)
throw err
} finally {
// Finish processing the event
Expand Down Expand Up @@ -559,7 +543,7 @@ export class FeatureDevController {
}
}
}
await session.sendMetricDataTelemetry(MetricDataOperationName.END_CODE_GENERATION, MetricDataResult.SUCCESS)
await session.sendMetricDataTelemetry(MetricDataOperationName.EndCodeGeneration, MetricDataResult.Success)
}

private sendUpdateCodeMessage(tabID: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/amazonqFeatureDev/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class Session {
await this.proxyClient.sendMetricData({
metricName: 'Operation',
metricValue: 1,
timestamp: new Date(Date.now()),
timestamp: new Date(),
product: 'FeatureDev',
dimensions: [
{
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/amazonqFeatureDev/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ export interface UpdateFilesPathsParams {
}

export enum MetricDataOperationName {
START_CODE_GENERATION = 'StartCodeGeneration',
END_CODE_GENERATION = 'EndCodeGeneration',
StartCodeGeneration = 'StartCodeGeneration',
EndCodeGeneration = 'EndCodeGeneration',
}

export enum MetricDataResult {
SUCCESS = 'Success',
FAULT = 'Fault',
ERROR = 'Error',
LLMFAILURE = 'LLMFailure',
Success = 'Success',
Fault = 'Fault',
Error = 'Error',
LlmFailure = 'LLMFailure',
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,16 +462,16 @@ describe('Controller', () => {
let sendMetricDataTelemetrySpy: sinon.SinonStub

const errorResultMapping = new Map([
['EmptyPatchException', MetricDataResult.LLMFAILURE],
[PromptRefusalException.name, MetricDataResult.ERROR],
[NoChangeRequiredException.name, MetricDataResult.ERROR],
['EmptyPatchException', MetricDataResult.LlmFailure],
[PromptRefusalException.name, MetricDataResult.Error],
[NoChangeRequiredException.name, MetricDataResult.Error],
])

function getMetricResult(error: ToolkitError): MetricDataResult {
if (error instanceof FeatureDevServiceError && error.code) {
return errorResultMapping.get(error.code) ?? MetricDataResult.ERROR
return errorResultMapping.get(error.code) ?? MetricDataResult.Error
}
return errorResultMapping.get(error.constructor.name) ?? MetricDataResult.FAULT
return errorResultMapping.get(error.constructor.name) ?? MetricDataResult.Fault
}

async function createCodeGenState() {
Expand Down Expand Up @@ -512,13 +512,13 @@ describe('Controller', () => {
await verifyMetricsCalled()
assert.ok(
sendMetricDataTelemetrySpy.calledWith(
MetricDataOperationName.START_CODE_GENERATION,
MetricDataResult.SUCCESS
MetricDataOperationName.StartCodeGeneration,
MetricDataResult.Success
)
)
const metricResult = getMetricResult(error)
assert.ok(
sendMetricDataTelemetrySpy.calledWith(MetricDataOperationName.END_CODE_GENERATION, metricResult)
sendMetricDataTelemetrySpy.calledWith(MetricDataOperationName.EndCodeGeneration, metricResult)
)
}

Expand All @@ -541,14 +541,14 @@ describe('Controller', () => {

assert.ok(
sendMetricDataTelemetrySpy.calledWith(
MetricDataOperationName.START_CODE_GENERATION,
MetricDataResult.SUCCESS
MetricDataOperationName.StartCodeGeneration,
MetricDataResult.Success
)
)
assert.ok(
sendMetricDataTelemetrySpy.calledWith(
MetricDataOperationName.END_CODE_GENERATION,
MetricDataResult.SUCCESS
MetricDataOperationName.EndCodeGeneration,
MetricDataResult.Success
)
)
})
Expand Down

0 comments on commit b911b63

Please sign in to comment.