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(spanner): add admin instance wrapper #16080

Merged

Conversation

bajajneha27
Copy link
Contributor

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea.
  • Follow the instructions in CONTRIBUTING. Most importantly, ensure the tests and linter pass by running bundle exec rake ci in the gem subdirectory.
  • Update code documentation if necessary.

@bajajneha27 bajajneha27 requested review from a team as code owners November 19, 2021 10:06
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 19, 2021
@product-auto-label product-auto-label bot added the api: spanner Issues related to the Spanner API. label Nov 19, 2021
@bajajneha27 bajajneha27 added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Nov 19, 2021
@hengfengli
Copy link
Contributor

@bajajneha27 Can you please fix the tests before we can review this PR? Thanks.

@bajajneha27
Copy link
Contributor Author

@bajajneha27 Can you please fix the tests before we can review this PR? Thanks.

Yeah, I'm working on it. I'll update once done. Thanks.

@bajajneha27
Copy link
Contributor Author

Hi @hengfengli , does emulator support update instance request? I'm getting the following error here:

Google::Cloud::UnimplementedError: 12:Cloud Spanner Emulator does not support updating instances

@hengfengli
Copy link
Contributor

Hi @hengfengli , does emulator support update instance request? I'm getting the following error here:

Google::Cloud::UnimplementedError: 12:Cloud Spanner Emulator does not support updating instances

No I don't think it supports that. You have to skip the test just for the emulator.

Gapic::ServiceStub.stub :new, :stub do
client = Google::Cloud::Spanner::Admin::Instance.instance_admin project_id: "1234"
assert_kind_of Google::Cloud::Spanner::Admin::Instance::V1::InstanceAdmin::Client, client
assert_equal emulator_host, client.configure.endpoint
Copy link
Contributor

Choose a reason for hiding this comment

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

In #13456, I was also trying to assert if the credentials are :this_channel_is_insecure. But I couldn't get it working. Would you be able to figure out how to get it working?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Shanika for pointing this out. The credentials is actually set to :this_channel_is_insecure at L105 but then it gets changed over here
I'm not sure about the right behaviour here. Can you please help me out?

Copy link
Member

Choose a reason for hiding this comment

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

@bajajneha27 @skuruppu Unfortunately the actual GRPC::Core::Channel object does not expose the provided credentials, afaik. However, you can use stub to intercept and test the arguments provided to GRPC::Core::Channel#new. I will provide a GH suggestion.

Copy link
Member

Choose a reason for hiding this comment

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

See suggested change, above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @quartzmo

Copy link
Contributor

@hengfengli hengfengli left a comment

Choose a reason for hiding this comment

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

LGTM.

require "gapic/grpc"

class Google::Cloud::Spanner::AdminInstanceClientConstructionMinitest < Minitest::Test
def test_instance_admin
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def test_instance_admin
def test_instance_admin
emulator_host = "localhost:4567"
channel_args = { "grpc.service_config_disable_resolution" => 1 }
channel_creds = :this_channel_is_insecure
channel = GRPC::Core::Channel.new emulator_host, channel_args, channel_creds
emulator_check = ->(name) { (name == "SPANNER_EMULATOR_HOST") ? emulator_host : nil }
channel_check = ->(chan_host, chan_args, chan_creds) do
assert_equal emulator_host, chan_host
assert_equal channel_args, chan_args
assert_equal channel_creds, chan_creds
channel
end
# Clear all environment variables, except SPANNER_EMULATOR_HOST
ENV.stub :[], emulator_check do
Gapic::ServiceStub.stub :new, :stub do
GRPC::Core::Channel.stub :new, channel_check do
client = Google::Cloud::Spanner::Admin::Instance.instance_admin project_id: "1234"
assert_kind_of Google::Cloud::Spanner::Admin::Instance::V1::InstanceAdmin::Client, client
assert_equal emulator_host, client.configure.endpoint
end
end
end
end

Copy link
Member

@quartzmo quartzmo left a comment

Choose a reason for hiding this comment

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

LGTM. I added a suggested change in response to @skuruppu's comment on client_test.rb:30.

@bajajneha27 bajajneha27 removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Nov 25, 2021
@bajajneha27 bajajneha27 merged commit d26c9c9 into googleapis:main Nov 26, 2021
gcf-merge-on-green bot pushed a commit that referenced this pull request Dec 10, 2021
🤖 I have created a release \*beep\* \*boop\*
---
### 2.11.0 / 2021-12-10

#### Features

* add admin instance wrapper ([#16080](https://www.github.com/googleapis/google-cloud-ruby/issues/16080))
* Updated benchwrapper and proto for spanner. ([#16152](https://www.github.com/googleapis/google-cloud-ruby/issues/16152))
* use gRPC clients for instance/database management ([#13157](https://www.github.com/googleapis/google-cloud-ruby/issues/13157))
* wrapper to create generated admin database client. ([#13456](https://www.github.com/googleapis/google-cloud-ruby/issues/13456))
---
### Commits since last release:

* [feat(spanner): Updated benchwrapper and proto for spanner. (#16152)](c67d621)
* [feat(spanner): use gRPC clients for instance/database management (#13157)](b6fdf2f)
* [feat(spanner): add admin instance wrapper (#16080)](d26c9c9)
* [feat(spanner): wrapper to create generated admin database client. (#13456)](24bf835)

### Files edited since last release:

<pre><code>google-cloud-spanner/benchmark/benchwrapper/benchwrapper.rb
google-cloud-spanner/benchmark/benchwrapper/spanner.proto
google-cloud-spanner/benchmark/benchwrapper/spanner_pb.rb
google-cloud-spanner/benchmark/benchwrapper/spanner_services_pb.rb
google-cloud-spanner/OVERVIEW.md
google-cloud-spanner/README.md
google-cloud-spanner/lib/google/cloud/spanner/backup.rb
google-cloud-spanner/lib/google/cloud/spanner/backup/job.rb
google-cloud-spanner/lib/google/cloud/spanner/backup/job/list.rb
google-cloud-spanner/lib/google/cloud/spanner/backup/list.rb
google-cloud-spanner/lib/google/cloud/spanner/backup/restore/job.rb
google-cloud-spanner/lib/google/cloud/spanner/database.rb
google-cloud-spanner/lib/google/cloud/spanner/database/backup_info.rb
google-cloud-spanner/lib/google/cloud/spanner/database/job.rb
google-cloud-spanner/lib/google/cloud/spanner/database/job/list.rb
google-cloud-spanner/lib/google/cloud/spanner/database/list.rb
google-cloud-spanner/lib/google/cloud/spanner/database/restore_info.rb
google-cloud-spanner/lib/google/cloud/spanner/instance.rb
google-cloud-spanner/lib/google/cloud/spanner/instance/config.rb
google-cloud-spanner/lib/google/cloud/spanner/instance/config/list.rb
google-cloud-spanner/lib/google/cloud/spanner/instance/job.rb
google-cloud-spanner/lib/google/cloud/spanner/instance/list.rb
google-cloud-spanner/lib/google/cloud/spanner/project.rb
google-cloud-spanner/acceptance/instance_client_test.rb
google-cloud-spanner/lib/google/cloud/spanner/admin/instance.rb
google-cloud-spanner/test/google/cloud/spanner/admin/instance/client_config_test.rb
google-cloud-spanner/test/google/cloud/spanner/admin/instance/client_test.rb
google-cloud-spanner/acceptance/spanner/database_client_test.rb
google-cloud-spanner/lib/google/cloud/spanner/admin/database.rb
google-cloud-spanner/test/google/cloud/spanner/admin/database/client_config_test.rb
google-cloud-spanner/test/google/cloud/spanner/database/client_test.rb
</code></pre>
[Compare Changes](8b1d497...HEAD)



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
api: spanner Issues related to the Spanner API. 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

4 participants