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

Update user agent construction and deprecate old SdkUserAgent class #5596

Merged
merged 7 commits into from
Sep 20, 2024

Conversation

cenedhryn
Copy link
Contributor

@cenedhryn cenedhryn commented Sep 13, 2024

Motivation and Context

New cross-SDK specifications changes the format of the Java user agent header. This change refactors Java SDK to conform to those specifications.

Modifications

Creates a SystemUserAgent and deprecates SdkUserAgent

The existing software.amazon.awssdk.core.util.SdkUserAgent class is used for two types of requests:

  1. Standard SDK client requests to AWS services
  2. Other types of calls, usually to local HTTP endpoints

The latter can only use system level information in the user agent, while the former also can include client- and request-level information.

The new SystemUserAgent stores a general system user agent string to be used in both use cases. The old user agent class is deprecated, because the name is confusing. SystemUserAgent has public methods to retrieve the individual system properties it supports, in addition to the system user agent string (which is a concatenated value).

Minor changes

  • Removes system property user.region and adds user.country. The JVM doesn't populate user.region anymore, and the lang/region value (like en_US) has not been added to the user agent string for a while.
  • Added a separate properties class SdkClientUserAgentProperties.java as input to building the main part of the SDK user agent string. It is currently a grab bag because at another point in the implementation it was stored in execution attributes. It can be a POJO as well, but the upcoming business metrics refactor also gives ample opportunities to refactor the code again.
  • Removes adding default values of empty string for USER_AGENT_PREFIX and USER_AGENT_SUFFIX. It's unclear why the implementation was that way.

Discussion topics

How to handle old SdkUserAgent

We can

  1. Deprecate (current choice)
  2. Delete it
  3. Log a warning if people use it.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@cenedhryn cenedhryn requested a review from a team as a code owner September 13, 2024 05:26
…esting, since client no longer depends on those values to be an empty string
* Replace any spaces, parentheses in the input with underscores.
*/
public static String sanitizeInput(String input) {
return input == null ? UNKNOWN : input.replaceAll(UA_DENYLIST_REGEX, "_");
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worthwile to precompile this into a Pattern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current usage doesn't require it, since it's mainly used in the singleton class, but I'm adding it still.

* returns the first value.
*/
public static String concat(String prefix, String suffix, String separator) {
return suffix != null && !suffix.isEmpty() ? prefix + separator + suffix : prefix;
Copy link
Contributor

Choose a reason for hiding this comment

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

isEmpty() returns false for whitespace. Is that okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's fine; it's on a few different call paths but mainly it's legacy code. I don't think there is any case where there would only be a whitespace value - don't think that can happen with system setting values.

} catch (ClassNotFoundException e) {
//Ignore
} catch (Exception e) {
if (log.isTraceEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: don't think this is necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kept previous code, but can remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To clarify, this code is unchanged from before. I want to leave it as is to not risk any issues with errors.

} catch (ClassNotFoundException e) {
//Ignore
} catch (Exception e) {
if (log.isTraceEnabled()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessary

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same

Copy link

sonarcloud bot commented Sep 19, 2024

@cenedhryn cenedhryn added this pull request to the merge queue Sep 20, 2024
Merged via the queue into master with commit 8d24920 Sep 20, 2024
17 checks passed
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.

2 participants