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

fix: Update useragent string with npm version #13903

Merged
merged 9 commits into from
Oct 10, 2024
Merged

Conversation

ashika112
Copy link
Member

@ashika112 ashika112 commented Oct 9, 2024

Description of changes

  • Fixes the issue with userAgent string getting encoded for the signer
    • Geo category recently had a failing test . The root cause of the issue was that the userAgent string was not properly encoded especially special character +. Lerna adds this special character + to the version and npm strips the value of post the + [Ref] we will do the same thing since we care about version in NPM for our metrics.
  • Update yarn.lock since some version were backtracked weirdly last time we updated it

Description of how you validated changes

  • Unit test
  • Manual test in sample geo app

Checklist

  • PR description included
  • yarn test passes
  • Unit Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

Checklist for repo maintainers

  • Verify E2E tests for existing workflows are working as expected or add E2E tests for newly added workflows
  • New source file paths included in this PR have been added to CODEOWNERS, if appropriate

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ashika112 ashika112 marked this pull request as ready for review October 9, 2024 23:33
@ashika112 ashika112 requested review from a team as code owners October 9, 2024 23:33
@ashika112 ashika112 changed the title Fix/maybe geo issue fix: Update useragent string with npm version Oct 9, 2024
@@ -11,7 +11,7 @@ import { getCustomUserAgent } from './customUserAgent';
const BASE_USER_AGENT = `aws-amplify`;

class PlatformBuilder {
userAgent = `${BASE_USER_AGENT}/${version}`;
userAgent = `${BASE_USER_AGENT}/${version.replace(/\+.*/, '')}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will changing this cause any issues with our metrics? Will we need to query for multiple versions of the version string now?

Copy link
Member Author

Choose a reason for hiding this comment

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

Confirmed with product it does not affect them

Copy link
Member

Choose a reason for hiding this comment

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

As we discussed, this is going to leave the preid versions with the hash duplication. Probably non-impacting, but a bit ugly. If PM is bought in on this variation, its not a blocker for any technical reasons.

Copy link
Member Author

Choose a reason for hiding this comment

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

@stocaaro confirmed this wont cause an issue there since the current change will still preserve the hash. Its a duplicated bit of hash that is removed. Etc,

if version is 6.5.1-multi-bucket.7bc5681.0+7bc5681 -> 6.5.1-multi-bucket.7bc5681.0, hash 7bc5681 is preserved :)


jest.mock('../../src/Platform/customUserAgent');
const expectedVersion = version.replace(/\+.*/, '');
Copy link
Member

Choose a reason for hiding this comment

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

nit: For testing purposes this could be a some hardcoded strings

Copy link
Member Author

Choose a reason for hiding this comment

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

i was going to do that but then we will have to mock the version in first place so for now kept the same logic

Copy link
Member

Choose a reason for hiding this comment

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

You could push the version replacement into a function and then test that function with a variety of inputs/outputs.

stocaaro
stocaaro previously approved these changes Oct 10, 2024
Copy link
Member

@stocaaro stocaaro left a comment

Choose a reason for hiding this comment

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

LGTM. Made a suggestion around the testing. I'm on the fence about whether thats more than a nit, so approving and good either way on if that happens.


jest.mock('../../src/Platform/customUserAgent');
const expectedVersion = version.replace(/\+.*/, '');
Copy link
Member

Choose a reason for hiding this comment

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

You could push the version replacement into a function and then test that function with a variety of inputs/outputs.

@@ -11,7 +11,7 @@ import { getCustomUserAgent } from './customUserAgent';
const BASE_USER_AGENT = `aws-amplify`;

class PlatformBuilder {
userAgent = `${BASE_USER_AGENT}/${version}`;
userAgent = `${BASE_USER_AGENT}/${version.replace(/\+.*/, '')}`;
Copy link
Member

Choose a reason for hiding this comment

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

As we discussed, this is going to leave the preid versions with the hash duplication. Probably non-impacting, but a bit ugly. If PM is bought in on this variation, its not a blocker for any technical reasons.

@ashika112 ashika112 merged commit 541e463 into main Oct 10, 2024
30 checks passed
@ashika112 ashika112 deleted the fix/maybe-geo-issue branch October 10, 2024 21:12
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.

4 participants