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

telemetry(amazonq): Improving error handling and telemetry in unit test generation. #6187

Open
wants to merge 18 commits into
base: master
Choose a base branch
from

Conversation

laileni-aws
Copy link
Contributor

@laileni-aws laileni-aws commented Dec 9, 2024

Implementation:

  • Adding 4XX vs 5XX httpStatusCode field to amazonq_utgGenerateTests event.
  • Improving error handling in unit test generation.

  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.

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

Copy link

github-actions bot commented Dec 9, 2024

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.
  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

@laileni-aws laileni-aws changed the title feature(amazonq): Improving error handling in unit test generation. feat(amazonq): Improving error handling in unit test generation. Dec 9, 2024
@laileni-aws laileni-aws changed the title feat(amazonq): Improving error handling in unit test generation. feat(amazonq): Improving error handling and telemetry in unit test generation. Dec 9, 2024
@laileni-aws laileni-aws changed the title feat(amazonq): Improving error handling and telemetry in unit test generation. telemetry(amazonq): Improving error handling and telemetry in unit test generation. Dec 9, 2024
@laileni-aws laileni-aws marked this pull request as ready for review December 9, 2024 22:21
@laileni-aws laileni-aws requested review from a team as code owners December 9, 2024 22:21
error: string,
code: string,
public statusCode: string,
public customerFacingMessage: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name it uiMessage. This is really a special case, and will lead to confusion and hard-to-follow code, and inconsistent UX. Why can't customers see the actual error message? This will cause drift and confusion, and adds steps to troubleshooting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't customers see the actual error message

Unfortunately error messages received from the backend is not aligning to the UX messages. So IDE need to handle this explicitly.
I will update customerFacingMessage to uiMessage

Comment on lines 722 to 730
getLogger().info(
session.fileLanguage ?? 'plaintext',
session.listOfTestGenerationJobId[0],
session.testGenerationJobGroupName,
'Succeeded',
AuthUtil.instance.startUrl,
'200'
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this format work? I think only the first arg will be logged


this.messenger.sendMessage(message, data.tabID, 'prompt')
this.messenger.sendMessage(`Unit test generation workflow is completed.`, data.tabID, 'answer')
// this.messenger.sendMessage(`Unit test generation workflow is completed.`, data.tabID, 'answer')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Existing public plugin does not reach this part of code as IDE throws an error at sessionCleanUp

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you fixed it, do we still want to comment this out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check whether we need to have this text after Accept or Reject action?
As JB does show this text after Accept/Reject but VSC don't.
We can add this accordingly.

if (error.message.includes(CodeWhispererConstants.utgLimitReached)) {
getLogger().error('Monthly quota reached for QSDA actions.')
return this.messenger.sendMessage(
i18n('AWS.amazonq.featureDev.error.monthlyLimitReached'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is using featureDev message, is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes its intentional, Its a generic message for Q agent.

"AWS.amazonq.featureDev.error.monthlyLimitReached": "You've reached the monthly quota for Amazon Q Developer's agent capabilities. You can try again next month. For more information on usage limits, see the <a href=\"https://aws.amazon.com/q/developer/pricing/\" target=\"_blank\">Amazon Q Developer pricing page</a>.",

'answer'
)
} else {
getLogger().error('Too many requests.')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this path always mean "Too many requests"? I would have expected something more generic

@@ -736,10 +747,10 @@ export class TestController {
isSupportedLanguage: true,
credentialStartUrl: AuthUtil.instance.startUrl,
result: 'Succeeded',
httpStatusCode: '200',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a number or a string? I think in the previous block you are using a number type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In MetricBase, It was mentioned as string readonly httpStatusCode?: string.
I am making change from

httpStatusCode: data.error.statusCode ?? 0

to

httpStatusCode: data.error.statusCode ?? '0', 


this.messenger.sendMessage(message, data.tabID, 'prompt')
this.messenger.sendMessage(`Unit test generation workflow is completed.`, data.tabID, 'answer')
// this.messenger.sendMessage(`Unit test generation workflow is completed.`, data.tabID, 'answer')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you fixed it, do we still want to comment this out?

packages/core/src/amazonqTest/error.ts Outdated Show resolved Hide resolved
@@ -343,6 +345,7 @@ export function throwIfCancelled(scope: CodeWhispererConstants.CodeAnalysisScope
export async function uploadArtifactToS3(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a separate function for testGen in testGenHandler.ts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to cover these changes as part of Code Refactoring PR.
I added a task for this in milestone doc as there is some good amount of refactoring, needs to be done.

} else {
errorMessage = errorDesc ?? defaultMessage
}
throw isCodeScan ? new UploadArtifactToS3Error(errorMessage) : new UploadTestArtifactToS3Error(errorMessage)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like error description can have either 4xx or 5xx. But UploadTestArtifactToS3Error always has 500 hardcoded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this with new UploadTestArtifactToS3Error(errorMessage, (error as any).statusCode)

error: string,
code: string,
public statusCode: string,
public uiMessage: string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need uiMessage. The ToolkitError.message field is explicitly documented as "potentially shown to the user". You can store the lower-level message on ToolkitError.details

this.details = info.details

This has far-reaching benefits. It allows all the existing architecture to treat these standard fields in a consistent way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like details has different type readonly details?: Record<string, unknown>

Copy link
Contributor

@justinmk3 justinmk3 Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you look at existing code and figure out a way to make it work with details. It shouldn't matter that the type isn't exactly the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Saw the usage of this but I think we can use the existing way as we use same structure for Reviewbird error handling too.
This change neither impacts other features nor functionality or telemetry.

super(error, 'CreateTestJobError', code, technicalErrorCustomerFacingMessage)
}
}
export class TestGenTimedOutError extends TestGenError {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the plan here? Maintaining one-to-one errors with all the service-side errors is not maintainable. Can you find something more generalizable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestGenTimedOutError is client side error if plugin did not get response for limited time we throw this error. This helps us understand the number of requests timed out from generic backend errors.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not asking about this error only, I'm referring to all of the errors in this file. It is not maintainable to create special errors for every service-side error.

constructor(
error: string,
code: string,
public statusCode: string,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this a number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought of using number but in our Telemetry statusCode is declared as String.
aws-toolkit-common

If required I can use number here and can convert to string while emitting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed this as part of this commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants