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

Add initial architecture rules #5741

Merged
merged 5 commits into from
Dec 11, 2024
Merged

Conversation

zoewangg
Copy link
Contributor

@zoewangg zoewangg commented Dec 4, 2024

Motivation and Context

Codify architecture rules, coding conventions and naming conventions and ensure they are followed.

Modifications

Create a new test module architecture-tests to add the following rules:

Package conventions

  • Internal APIs (@SdkInternalApi) MUST reside in ”..internal..” subpackage
  • Public APIs (@SdkPublicApi) and Protected APIs (@SdkProtectedApi) MUST NOT reside in “..internal..” subpackage
  • Internal APIs (@SdkInternalApi) MUST NOT be used across modules

Coding conventions

  • Public APIs MUST be final
  • Log.error/warn MUST be added carefully
  • Use Java SDK Logger instead of Slf4j Logger
  • Prefer CompletableFuture over Future
  • Optional MUST NOT be used for fields
  • Public APIs MUST NOT declare checked exception

Naming conventions

  • Implementations of Supplier MUST have ”Supplier” suffix
  • Implementations MUST NOT have “Impl” suffix.
  • Implementations of Presigner MUST have “Presigner” suffix

Testing

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

@zoewangg zoewangg force-pushed the zoewang/addArchitectureTestsModule branch 11 times, most recently from aee08c7 to c17e892 Compare December 6, 2024 18:59
import software.amazon.awssdk.annotations.SdkPublicApi;

@AnalyzeClasses(packages = "software.amazon.awssdk..")
@ArchIgnore(reason = "CI keeps crashing when running the tests. Ignoring them for now")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to ignore tests in this class because CI keeps crashing for some reason. Will take a look and follow up in a separate PR

@zoewangg zoewangg marked this pull request as ready for review December 6, 2024 23:13
@zoewangg zoewangg requested a review from a team as a code owner December 6, 2024 23:13
@zoewangg zoewangg changed the title [WIP] Add initial architecture rules Add initial architecture rules Dec 6, 2024
* @param maybeCloseable the given closeable
* @param log logger used to log any failure should the close fail
*/
public static void closeIfCloseableV2(Object maybeCloseable, Logger log) {
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 can't use the same signature because it'll break people who invoke closeIfClosable(closable, null)

* @param is the given closeable
* @param log logger used to log any failure should the close fail
*/
public static void closeQuietlyV2(AutoCloseable is, Logger log) {
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 can't use the same signature because it'll break people who invoke closeQuietly(closable, null)

Comment on lines +44 to +48
<dependency>
<artifactId>dynamodb-enhanced</artifactId>
<groupId>software.amazon.awssdk</groupId>
<version>${awsjavasdk.version}</version>
</dependency>
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we choose to add a dependency here, vs just including everything? Does it save time to just include things with customizations?

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, saving build time and avoiding oom error (I think the library has memory leak somewhere) is the main reason. I'm planning to add this to the new module checklist. Ideally, we should run this test on all handwritten modules as well as service modules with heavy customization.

}

public static String findRootPackage(String pkg) {
if (pkg.startsWith("software.amazon.awssdk.services.")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to treat "services" differently? It feels like from where we're using this method in this PR, it wouldn't need to be treated specially.

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, because the root component for service package is the the last component after software.amazon.awssdk.services. whereas for core modules, it's the one after software.amazon.awssdk.awssdk. For example. softare.amazon.awssdk.services.s3 and software.amazon.awssdk.services.rds are not under the same root.

@zoewangg zoewangg force-pushed the zoewang/addArchitectureTestsModule branch from b1a07bb to 630444c Compare December 10, 2024 21:00
@zoewangg zoewangg enabled auto-merge December 10, 2024 21:02
@zoewangg zoewangg force-pushed the zoewang/addArchitectureTestsModule branch from 12df7e8 to a03a412 Compare December 11, 2024 01:05
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
68.4% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@zoewangg zoewangg added this pull request to the merge queue Dec 11, 2024
Merged via the queue into master with commit 2bddb0c Dec 11, 2024
16 of 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