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

chore: Pre-DIREGAPIC Refactoring #1 #719

Merged
merged 4 commits into from May 18, 2021

Conversation

vam-google
Copy link
Contributor

@vam-google vam-google commented Apr 22, 2021

This PR is a minimal subset of #717

This is as minimal of a PR that I could make such that:

  1. Only a single composer is refactored.
  2. It compiles and tests run.
  3. All the key changes are present (abstract/grpc class, comment composer, class names, golden files move)

I had to add a few quite ugly and artificial constructs:

  • fake ClassComposer under composer package which simply extends composer.common.Composer to void changing the rest of the classes
  • put back static methods in ClassNames, StubCommentComposer and TestProtoLoaderUtil (for the same reasons as above). All of those chagnes are marked with // TODO: remove after Pre-DIREGAPIC refactoring is fully merged statement.

 This is as minimal of a PR that I could make stuch that:
 1) It compiles and tests run single composer plus minimal
 2) All the key changes are present (abstract/grpc class, comment composer, class names, golden files move)

 I had to add a few quite ugly and artificial   constructs:
 fake `ClassComposer` under `composer` package which simply extends `composer.common.Composer` to void changing the rest of the classes
 put back static methods in `ClassNames` and `StubCommentComposer` and `TestProtoLoaderUtil` (for the same reasons as above). All of those chagnes are marked with `// TODO: remove after Pre-DIREGAPIC refactoring is fully merged` statement.
@vam-google vam-google requested review from miraleung and a team as code owners April 22, 2021 21:44
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Apr 22, 2021
@codecov
Copy link

codecov bot commented Apr 22, 2021

Codecov Report

Merging #719 (e81d781) into master (83e2e3b) will increase coverage by 0.18%.
The diff coverage is 81.48%.

❗ Current head e81d781 differs from pull request most recent head a537c93. Consider uploading reports for the commit a537c93 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #719      +/-   ##
==========================================
+ Coverage   92.30%   92.48%   +0.18%     
==========================================
  Files         124      127       +3     
  Lines       13491    13501      +10     
  Branches      996      981      -15     
==========================================
+ Hits        12453    12487      +34     
+ Misses        786      773      -13     
+ Partials      252      241      -11     
Impacted Files Coverage Δ
.../google/api/generator/gapic/composer/Composer.java 12.67% <ø> (ø)
...pic/composer/ServiceStubSettingsClassComposer.java 99.02% <ø> (-0.08%) ⬇️
...api/generator/gapic/composer/utils/ClassNames.java 64.00% <0.00%> (-20.22%) ⬇️
...google/api/generator/gapic/model/GapicContext.java 94.73% <ø> (ø)
...google/api/generator/gapic/protoparser/Parser.java 47.58% <0.00%> (-0.48%) ⬇️
...le/api/generator/gapic/model/TransportContext.java 88.88% <88.88%> (ø)
...api/generator/gapic/composer/grpc/GrpcContext.java 94.44% <94.44%> (ø)
...apic/composer/comment/SettingsCommentComposer.java 93.93% <100.00%> (ø)
...or/gapic/composer/comment/StubCommentComposer.java 100.00% <100.00%> (+3.84%) ⬆️
...r/common/AbstractServiceSettingsClassComposer.java 97.85% <100.00%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 83e2e3b...a537c93. Read the comment docs.

@@ -110,7 +112,7 @@ public GapicClass generate(GapicContext ignored, Service service) {
.setName(className)
.setExtendsType(
TypeNode.withReference(
FIXED_TYPESTORE
getFixedTypeStore()
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious - what is the motivation for using a getter if the field is immutable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also just basically a best practice thing for java - do not use protected fields, use protected setter/getter for them instead. This field can't be private, because it is accessed in the subclasses, so it must be either protected or have a protected getter, which is what is done here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Leaving open to revisit after the upcoming changes - if this becomes unneeded by the transport-specific composers, consider making it inaccessible to the subclasses.

TypeStore fixedTypeStore,
Class<?> instantiatingChannelProviderClass,
String defaultTransportProviderBuilderName) {
this.fixedTypeStore = fixedTypeStore;
Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about instantiating the intersection of gRPC and REST types in this class's fixedTypeStore? Looks like each call to fixedTypeStore.get() in this file could be a good starter set.

In response to this comment: Good point on sticking with fixedTypeStore.get("Test"). Previously, type existence was guaranteed because fixedTypeStore was instantiated in the same class, which is no longer the case. Hence setting up the common types will address this area.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I'm not sure I understand your comment instantiating the intersection of gRPC and REST types.

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline.

String defaultTransportProviderBuilderName) {
this.fixedTypeStore = fixedTypeStore;
this.instantiatingChannelProviderClass = instantiatingChannelProviderClass;
this.defaultTransportProviderBuilderName = defaultTransportProviderBuilderName;
Copy link
Contributor

Choose a reason for hiding this comment

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

Responding to this comment:

To recap, we currently have three possible approaches:

  • Instantiate any transport-specific values in the transport composer (e.g. GrpcServiceSettingsClassComposer sets defaultTransportProviderBuilderName = "defaultGrpcTransportProviderBuilder" (current approach in this PR).
    • Advantages: Maximizes per-composer locality.
    • Drawbacks: Splits per-transport state across many composers, so it may be harder to debug or change transport-specific things. When ClassNames is later involved, there will be another potential set of classes to look up.
  • Pass the Transport enum into the Abstract class, which can then decide whether to use "Grpc" or "HttpJson" in the string (most suboptimal).
    • Advantages: Maximizes locality in the Abstract class's common logic (of which there's a significant amount).
    • Drawbacks: The abstract class should not know anything about per-transport state.
  • Have a per-transport context object that holds the respective values.
    • Advantages: Maximizes per-transport locality, transport-specific debugging may be easier.
    • Drawbacks: Need to look up context in a transport-specific file.

My $0.02: The per-transport context object doesn't have to hold all the state, just anything that needed to be passed into the superclass. Motivation: Passing in differing string values in each per-transport composer class may possibly be less maintainable, especially since the values change within the same transport (e.g. "gRPC" vs "Grpc").

We can also discuss more offline. :)

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 can do the contexts, no problem, two questions before doing it (we can discuss it via GVC, just mentioning it here to not forget it):

Please clarify what you mean by context maximizing per-transport locality?

Yes, the context will need to hold the stuff to be passed to the superclass, but there are multiple superlcasses (like 5+) and each of them needs a different set of things (with some intersection, but not much). This means we will either need 5+ different transport specific contexts, or one transport-specific context with stuff shared across different composers in, which will tightly couple the composers class hierarchy with the context and with each other.

Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline.

super(
createTypes(),
InstantiatingGrpcChannelProvider.Builder.class,
"defaultGrpcTransportProviderBuilder");
Copy link
Contributor

Choose a reason for hiding this comment

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

super(InstantiatingGrpcChannelProvider.Builder.class,
        "defaultGrpcTransportProviderBuilder");
secondFixedTypeStore.add(...);

TypeStore fixedTypeStore,
Class<?> instantiatingChannelProviderClass,
String defaultTransportProviderBuilderName) {
this.fixedTypeStore = fixedTypeStore;
Copy link
Contributor

Choose a reason for hiding this comment

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

Discussed offline.

Mainly introduce TransportContex and all related stuff.
Mainly introduce TransportContex and all related stuff.
@vam-google
Copy link
Contributor Author

@miraleung PTAL

@vam-google vam-google requested a review from miraleung May 13, 2021 09:45
Copy link
Contributor

@miraleung miraleung left a comment

Choose a reason for hiding this comment

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

LGTM. Given the scope of DIREGAPIC's refactorings, could we start a diregapic main branch for all the refactoring PRs, so we can merge that into master when it's all done?

GRPC,
GRPC_REST;

public static Transport parse(String name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Consider adding a comment with the expected input. As someone familiar with what we're doing, it looks like this will be parsing a Bazel param string like "grpc+rest", so it'd be great to document this method's usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will in the PR which will introduce the actual parameters (here it is just hardcoded everywhere as grpc for now, because unill regapic prs are merged, grpc is the only actually supported transport by the generator.

@vam-google vam-google changed the base branch from master to diregapic May 18, 2021 09:01
@vam-google vam-google merged commit 5d182dd into googleapis:diregapic May 18, 2021
suztomo pushed a commit that referenced this pull request Mar 21, 2023
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.cloud:google-cloud-core](https://togithub.com/googleapis/java-core) | `2.7.1` -> `2.8.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core/2.8.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core/2.8.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core/2.8.0/compatibility-slim/2.7.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core/2.8.0/confidence-slim/2.7.1)](https://docs.renovatebot.com/merge-confidence/) |
| [com.google.cloud:google-cloud-core-bom](https://togithub.com/googleapis/java-core) | `2.7.1` -> `2.8.0` | [![age](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core-bom/2.8.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core-bom/2.8.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core-bom/2.8.0/compatibility-slim/2.7.1)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.cloud:google-cloud-core-bom/2.8.0/confidence-slim/2.7.1)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/java-core</summary>

### [`v2.8.0`](https://togithub.com/googleapis/java-core/blob/HEAD/CHANGELOG.md#&#8203;280-httpsgithubcomgoogleapisjava-corecomparev271v280-2022-06-21)

[Compare Source](https://togithub.com/googleapis/java-core/compare/v2.7.1...v2.8.0)

##### Features

-   add build scripts for native image testing in Java 17 ([#&#8203;1440](https://togithub.com/googleapis/java-core/issues/1440)) ([#&#8203;836](https://togithub.com/googleapis/java-core/issues/836)) ([8826d9b](https://togithub.com/googleapis/java-core/commit/8826d9bc05eb9e4a54c40e8578de85ed79c50e99))

##### Dependencies

-   update dependency com.google.api-client:google-api-client-bom to v1.35.1 ([#&#8203;843](https://togithub.com/googleapis/java-core/issues/843)) ([9ffe0c5](https://togithub.com/googleapis/java-core/commit/9ffe0c5b25761abf7ff1bea091aa1db057dff2d0))
-   update dependency com.google.api:api-common to v2.2.1 ([#&#8203;844](https://togithub.com/googleapis/java-core/issues/844)) ([69dde56](https://togithub.com/googleapis/java-core/commit/69dde5641546b678a385b1ed3a2c7a020f81d285))
-   update dependency com.google.api:gax-bom to v2.18.2 ([#&#8203;849](https://togithub.com/googleapis/java-core/issues/849)) ([11764b0](https://togithub.com/googleapis/java-core/commit/11764b04629c5bfbc9b0d68174782cc126dc1646))
-   update dependency com.google.api.grpc:proto-google-common-protos to v2.9.0 ([#&#8203;846](https://togithub.com/googleapis/java-core/issues/846)) ([5dced6d](https://togithub.com/googleapis/java-core/commit/5dced6d25ce0f3e7587d7ac1f6f3713f3b2a18c2))
-   update dependency com.google.api.grpc:proto-google-iam-v1 to v1.4.0 ([#&#8203;838](https://togithub.com/googleapis/java-core/issues/838)) ([b0a7afe](https://togithub.com/googleapis/java-core/commit/b0a7afe342a5e15436d439b9cc1e3c58f894ab66))
-   update dependency com.google.api.grpc:proto-google-iam-v1 to v1.4.1 ([#&#8203;848](https://togithub.com/googleapis/java-core/issues/848)) ([8260997](https://togithub.com/googleapis/java-core/commit/826099767b0aabe0db26eff2f612f0847b451366))
-   update dependency com.google.errorprone:error_prone_annotations to v2.14.0 ([#&#8203;839](https://togithub.com/googleapis/java-core/issues/839)) ([3459fb6](https://togithub.com/googleapis/java-core/commit/3459fb668557b982cef5682ce47d3c978b83d69c))
-   update dependency com.google.http-client:google-http-client-bom to v1.42.0 ([#&#8203;845](https://togithub.com/googleapis/java-core/issues/845)) ([2d2c873](https://togithub.com/googleapis/java-core/commit/2d2c873e274b26f4687d569cc3b8ae58c3c5ed54))
-   update dependency com.google.protobuf:protobuf-bom to v3.21.0 ([#&#8203;840](https://togithub.com/googleapis/java-core/issues/840)) ([037da15](https://togithub.com/googleapis/java-core/commit/037da15b2aed1719e768ba5b4e001caf25952adc))
-   update dependency com.google.protobuf:protobuf-bom to v3.21.1 ([#&#8203;841](https://togithub.com/googleapis/java-core/issues/841)) ([04b8862](https://togithub.com/googleapis/java-core/commit/04b886224128f1525ad8398815dc62dac87680af))
-   update dependency io.grpc:grpc-bom to v1.47.0 ([#&#8203;842](https://togithub.com/googleapis/java-core/issues/842)) ([40984e2](https://togithub.com/googleapis/java-core/commit/40984e23242ba954b6ca741ca3f02ec89e92ae57))

##### [2.7.1](https://togithub.com/googleapis/java-core/compare/v2.7.0...v2.7.1) (2022-05-19)

##### Dependencies

-   update dependency com.google.api:gax-bom to v2.18.1 ([#&#8203;833](https://togithub.com/googleapis/java-core/issues/833)) ([7541115](https://togithub.com/googleapis/java-core/commit/7541115095e0ae28d938a4c9621fd0f82892fe55))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-shared-dependencies).
suztomo pushed a commit that referenced this pull request Mar 21, 2023
[![WhiteSource Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [com.google.api:gax-bom](https://togithub.com/googleapis/gax-java) | `2.12.0` -> `2.12.2` | [![age](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.12.2/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.12.2/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.12.2/compatibility-slim/2.12.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.api:gax-bom/2.12.2/confidence-slim/2.12.0)](https://docs.renovatebot.com/merge-confidence/) |

---

### Release Notes

<details>
<summary>googleapis/gax-java</summary>

### [`v2.12.2`](https://togithub.com/googleapis/gax-java/blob/HEAD/CHANGELOG.md#&#8203;2122-httpsgithubcomgoogleapisgax-javacomparev2121v2122-2022-02-09)

[Compare Source](https://togithub.com/googleapis/gax-java/compare/v2.12.1...v2.12.2)

### [`v2.12.1`](https://togithub.com/googleapis/gax-java/blob/HEAD/CHANGELOG.md#&#8203;2121-httpsgithubcomgoogleapisgax-javacomparev2120v2121-2022-02-09)

[Compare Source](https://togithub.com/googleapis/gax-java/compare/v2.12.0...v2.12.1)

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-core).
suztomo pushed a commit that referenced this pull request Mar 21, 2023
🤖 I have created a release *beep* *boop*
---


### [2.5.3](googleapis/java-core@v2.5.2...v2.5.3) (2022-02-10)


### Dependencies

* update dependency com.google.api:gax-bom to v2.12.2 ([#719](googleapis/java-core#719)) ([8c14b98](googleapis/java-core@8c14b98))
* update dependency com.google.http-client:google-http-client-bom to v1.41.3 ([#720](googleapis/java-core#720)) ([8addf7f](googleapis/java-core@8addf7f))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants