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

feat: Allow the user to set fallback to rest #1203

Merged
merged 30 commits into from Dec 11, 2023

Conversation

danieljbruce
Copy link
Contributor

@danieljbruce danieljbruce commented Nov 17, 2023

Change:

Users need to be able to use the rest fallback property. This change allows client library calls to be rest calls instead of grpc calls. They can make this happen by instantiating the client library like so:

new Datastore({namespace, fallback: 'rest'})

This provides a workaround for the connection issue.
@product-auto-label product-auto-label bot added size: xs Pull request size is extra small. api: datastore Issues related to the googleapis/nodejs-datastore API. labels Nov 17, 2023
@pmwisdom
Copy link

@danieljbruce Hey there. Is there a reason this was closed?

Currently having to hack around this in my code to support HTTP with the datastore class which isn't ideal.

@danieljbruce danieljbruce reopened this Dec 1, 2023
@danieljbruce danieljbruce changed the title Allow the user to set fallback to rest feat: Allow the user to set fallback to rest Dec 1, 2023
Copy link

🤖 I detect that the PR title and the commit message differ and there's only one commit. To use the PR title for the commit history, you can use Github's automerge feature with squashing, or use automerge label. Good luck human!

-- conventional-commit-lint bot
https://conventionalcommits.org/

@danieljbruce danieljbruce marked this pull request as ready for review December 1, 2023 18:14
@danieljbruce danieljbruce requested review from a team as code owners December 1, 2023 18:14
@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 1, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 1, 2023
Need to mock out Gapic and compare constructors
The harness mocks out the constructor and calls reach the constructor as well as the get function. So now we can see what values get passed into the constructor and get function.
Add a working test that makes sure the rest parameter gets passed down to the gapic layer.
Proper describe blocks make it easier for the code to be arranged so that with and without rest tests can be incorporated into the code.
Remove the datastore mock. It is not necessary.
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: xs Pull request size is extra small. labels Dec 4, 2023
Make a programmatic link to the data type so that the intent is clearer.
Parameterized tests will allow us to delete half the tests. A new type is created for the test parameters.
Explain the purpose of the class. This will make it useful for testing.
This type is only used once so inline it.
Changes to system tests are not necessary. Remove them.
assert resolves to falsy in tests. See if this solves the issue.
Add console logs and assert checks back in.
This should allow the unit tests to pass in the continuous integration environment.
The title of the describe block should match the file. Remove console logs too.
*
*/
class FakeDatastoreClient extends DatastoreClient {
restParameter: string | undefined;

Choose a reason for hiding this comment

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

Hi Dan, just wondering is this "restParameter" expecting a boolean type from Fallback type too? https://github.com/googleapis/nodejs-datastore/pull/1203/files#diff-a2a171449d862fe29692ce031981047d7ab755ae7f84c707aef80701b3ea0c80R100

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 changed the type to Fallback here so that the types line up better.

@@ -1912,6 +1913,7 @@ export interface DatastoreOptions extends GoogleAuthOptions {
apiEndpoint?: string;
sslCreds?: ChannelCredentials;
databaseId?: string;
fallback?: Fallback;

Choose a reason for hiding this comment

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

Maybe this is already commented somewhere else. Do you think we can provide an example how to initiate client library with fallback options?

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 added a simple system test for this.

danieljbruce and others added 4 commits December 6, 2023 09:51
This parameter more specifically describes the change.
This system test should show how the rest parameter is being used.
This allows the test to pass with a simple assertion check.
*/
function compareRequest(
request: DatastoreRequest,
expectedFallback: string | undefined,

Choose a reason for hiding this comment

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

Maybe here change the type to Fallback to be consistent too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@danieljbruce danieljbruce added the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 7, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Dec 7, 2023
@danieljbruce danieljbruce merged commit 8a1fa54 into googleapis:main Dec 11, 2023
15 checks passed
@looker-colmeia
Copy link

hey @danieljbruce thanks for this feature, I would like to ask you a couple of things:

  1. you have any estimate of how much percent of query performance in datastore we will loose by enabling fallback to rest?
  2. this feature will use 100% of requests to datastore using rest or it's really some kind of fallback in case of error?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: datastore Issues related to the googleapis/nodejs-datastore API. size: m Pull request size is medium.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants