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
Conversation
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.
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
@@ -110,7 +112,7 @@ public GapicClass generate(GapicContext ignored, Service service) { | |||
.setName(className) | |||
.setExtendsType( | |||
TypeNode.withReference( | |||
FIXED_TYPESTORE | |||
getFixedTypeStore() |
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.
Curious - what is the motivation for using a getter if the field is immutable?
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.
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.
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.
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; |
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.
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.
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.
Sorry I'm not sure I understand your comment instantiating the intersection of gRPC and REST types.
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.
Discussed offline.
src/main/java/com/google/api/generator/gapic/composer/utils/ClassNames.java
Show resolved
Hide resolved
String defaultTransportProviderBuilderName) { | ||
this.fixedTypeStore = fixedTypeStore; | ||
this.instantiatingChannelProviderClass = instantiatingChannelProviderClass; | ||
this.defaultTransportProviderBuilderName = defaultTransportProviderBuilderName; |
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.
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. :)
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 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.
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.
Discussed offline.
super( | ||
createTypes(), | ||
InstantiatingGrpcChannelProvider.Builder.class, | ||
"defaultGrpcTransportProviderBuilder"); |
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.
super(InstantiatingGrpcChannelProvider.Builder.class,
"defaultGrpcTransportProviderBuilder");
secondFixedTypeStore.add(...);
TypeStore fixedTypeStore, | ||
Class<?> instantiatingChannelProviderClass, | ||
String defaultTransportProviderBuilderName) { | ||
this.fixedTypeStore = fixedTypeStore; |
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.
Discussed offline.
Mainly introduce TransportContex and all related stuff.
Mainly introduce TransportContex and all related stuff.
@miraleung PTAL |
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. 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?
src/main/java/com/google/api/generator/gapic/composer/utils/ClassNames.java
Show resolved
Hide resolved
GRPC, | ||
GRPC_REST; | ||
|
||
public static Transport parse(String name) { |
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.
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.
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.
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.
[![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#​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 ([#​1440](https://togithub.com/googleapis/java-core/issues/1440)) ([#​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 ([#​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 ([#​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 ([#​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 ([#​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 ([#​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 ([#​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 ([#​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 ([#​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 ([#​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 ([#​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 ([#​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 ([#​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).
[![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#​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#​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).
🤖 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).
This PR is a minimal subset of #717
This is as minimal of a PR that I could make such that:
I had to add a few quite ugly and artificial constructs:
ClassComposer
undercomposer
package which simply extendscomposer.common.Composer
to void changing the rest of the classesClassNames
,StubCommentComposer
andTestProtoLoaderUtil
(for the same reasons as above). All of those chagnes are marked with// TODO: remove after Pre-DIREGAPIC refactoring is fully merged
statement.