-
Notifications
You must be signed in to change notification settings - Fork 737
feat(sagemaker): free tier Q Chat with auto-login for iam users and login option for pro tier users #5858
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
Conversation
|
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a large change here and it is not clear what triggered it. Are you able to extract this related change to an isolated commit so we can better understand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what triggerred it either, but I believe it's the dependencies of the new Q developer client I added in src.gen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That new generated client won't result in new package-lock.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point I'm clueless as to why the package.json file was changed. But I see many of the dependencies added there are also part of the newly added client package-lock.json. this is why I suspected they're related.
I inspected the dependencies added / changed further and they're only relevant to the new client code
packages/amazonq/.changes/next-release/Feature-a007f02d-d737-4429-9b7d-245aa30d879c.json
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,91 @@ | |||
| { | |||
| "name": "@amzn/amazon-q-developer-streaming-client", | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this package? Why can we not use src.gen/@amzn/codewhisperer-streaming?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To answer this, please update https://github.com/aws/aws-toolkit-vscode/blob/master/docs/build.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, this client supports Sigv4 credentials instead of bearer token. this is mandatory to support both IAM and SSO users.
The instructions to generate these clients will be updated in the same quip doc referenced in this .md file
I updated the wording to reflect the new changes
packages/core/src/codewhispererChat/controllers/chat/messenger/messenger.ts
Outdated
Show resolved
Hide resolved
|
|
||
| export async function initialize(loginManager: LoginManager): Promise<void> { | ||
| if (isAmazonQ() && isSageMaker()) { | ||
| const result = (await vscode.commands.executeCommand('sagemaker.parseCookies')) as SagemakerCookie |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this command come from? Is it already registered in VSC by sagemaker? If so add a comment to mention this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, this command is registered in Sagemaker code editor. I'll add a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets make a new sagemaker folder in src/shared/sagemaker for all custom sagemaker code so that it is contained within a single place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a big refactor that I'd rather defer to a later followup to reduce risk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a long-term approach. The Toolkit/Q extensions already have an api to accept connections. If needed, they can be enhanced to accept tokens/credentials, so the caller (SM in this case) can inject credentials into the extension.
|
|
||
| if (isSageMaker()) { | ||
| return isIamConnection(conn) | ||
| return isIamConnection(conn) || (isSsoConnection(conn) && hasScopes(conn, codeWhispererCoreScopes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use amazonQScopes? Does sagemaker SSO auth allow for the complete Q scope set?
| return isIamConnection(conn) || (isSsoConnection(conn) && hasScopes(conn, codeWhispererCoreScopes)) | |
| return isIamConnection(conn) || (isSsoConnection(conn) && hasScopes(conn, amazonQScopes)) |
It is code smell that we have these scope subsets, so it is easy to confuse which one needs to be used/checked. We have plans to fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it doesn't, but tackling the scopes is a separate issue that I'll address later on. For now, if user login with their SSO credentials, they will go through the normal login flow which appends the full set of credentials for them. I can omit the scope check from here though as it doesn't make a difference for Sagemaker users.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now, I'll simplify the condition and put in a separate function for readability. it ignores any scope checking as we're handling deactivating features not supported by sagemaker in a separate change
| if (!isSsoConnection(conn)) { | ||
| throw new ToolkitError(`Connection "${conn.id}" is not a valid type: ${conn.type}`) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of deleting this you can add the check
if (!isSsoConnection(conn) && !isSageMaker()) { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this change is not just for Sagemaker, the new client enables chat for both Sso and Iam connections, so this restriction no longer applies with this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but this change is not just for Sagemaker
But this isn't a supported feature yet in all of the code yet right? That is a big product change to the Q extension. AFAIK there is no way to get IAM credentials outside of sagemaker. Until it's supported throughout we should still have these sanity checks. Also, for a change that big I would expect unit or integ test updates/additions if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, will adjust it now
hayemaxi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm pending team approval
| page: number = 0, | ||
| isSM: boolean = isSageMaker(), | ||
| retry: boolean = false | ||
| generate: boolean = isIamConnection(AuthUtil.instance.conn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should no longer be a single function for both IAM and bearer token code path. The number of if-else is too much to comprehend. Not a blocker for this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do lots of regression testing post merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test /dev and /transform
| message: generateAssistantResponseResponse, | ||
| } | ||
| } else { | ||
| const { $metadata, sendMessageResponse } = await session.chatIam(request as SendMessageRequest) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
source="IDE"
we need to set the request for the right routing in Q Dev
| message: sendMessageResponse, | ||
| } | ||
| } | ||
| this.telemetryHelper.recordEnterFocusConversation(triggerEvent.tabID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what kind of telemetry or error mechanism we can use to understand customers facing issues with the chat window ?
| // The command `sagemaker.parseCookies` is registered in VS Code Sagemaker environment. | ||
| const result = (await vscode.commands.executeCommand('sagemaker.parseCookies')) as SagemakerCookie | ||
| if (result.authMode !== 'Sso') { | ||
| initializeCredentialsProviderManager() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this refactor affect toolkit ? In sagemaker studio sso mode, toolkit will still work in IAM mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The higher level condition is scoped to amazonq, so it shouldn't impact aws toolkit
bhadrip
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how do we handle graceful failure of features that are not supported in free tier IAM mode
bhadrip
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there no unit tests for the changes ?
|
please add a |
All the files I touched didn't have unit tests related to the changes. I plan to improve the coverage of this package as the code paths (especially for auth and API calls) are very critical |
Added rule |
|
CI is failing: another PR merged to master is using old function |
SM IAM permissions have been working as of v1.99 and now it's broken. This change brings it back to support code completion for SM code editor
gogakoreli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Verified in Sagemaker
Problem
AmazonQ
Solution
License: I confirm that my contribution is made under the terms of the Apache 2.0 license.