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 support for Cloud Spanner Emulator #48

Closed
aeroastro opened this issue Nov 11, 2020 · 3 comments · Fixed by #70
Closed

Add support for Cloud Spanner Emulator #48

aeroastro opened this issue Nov 11, 2020 · 3 comments · Fixed by #70
Assignees
Labels
api: spanner Issues related to the googleapis/ruby-spanner-activerecord API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@aeroastro
Copy link
Contributor

I would like to use Cloud Spanner Emulator to develop this gem and to develop Rails application using gem. Although, there are limitations and differences, the emulator does not cost money 💸 and the separated environments are suited for local development.

https://cloud.google.com/spanner/docs/emulator

Then, I've found out that the current implementation of this library does not support emulator.
This is because Google::Cloud.spanner is used instead of Google::Cloud::Spanner.new. The former method pass the limited portion of parameters to the latter.

@spanners[database_path(config)] ||= Google::Cloud.spanner(
config[:project],
config[:credentials],
scope: config[:scope],
timeout: config[:timeout],
client_config: config[:client_config]&.symbolize_keys,
lib_name: "spanner-activerecord-adapter",
lib_version: ActiveRecordSpannerAdapter::VERSION
)

If we directly call Google::Cloud::Spanner.new(config), we can pass the emulator_host parameter in config, which enable developers to use Cloud Spanner Emulator.

https://github.com/googleapis/google-cloud-ruby/blob/06c73b3b4b09e5f4dded27b61662fe110fea57bb/google-cloud-spanner/lib/google/cloud/spanner.rb#L91-L101

Although, this breaks config[:project], config[:credentials] compatibility, I think keeping consistency with Google::Cloud::Spanner.new reduces maintenance cost.
Of course, If required, I can write backward-compatible code.

If the above strategy is O.K., I am willing to work on this issue.

@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/ruby-spanner-activerecord API. label Nov 11, 2020
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Nov 12, 2020
@skuruppu skuruppu added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Nov 12, 2020
@skuruppu
Copy link
Collaborator

@jiren would you please be able to answer this question?

@jiren
Copy link
Member

jiren commented Nov 12, 2020

@aeroastro To run against emulator need to export env variable SPANNER_EMULATOR_HOST

i.e

export SPANNER_EMULATOR_HOST=localhost:9010

If env variable exported then goole-cloud-spanner lib will by default pickup spanner endpoint as emulator.

FYI, I have not tested activereocrd connector with emulator. I will try and let you know.

@aeroastro
Copy link
Contributor Author

Thank you for your prompt response.
After I checked the following command in my local environment, I still have errors and I need to look deeper into the code.

$ SPANNER_EMULATOR_HOST=localhost:9010 bundle exec rake acceptance[test-project,test.json,test-instance]

Also, specifically speaking, what I would like to achieve here is to treat emulator environment just like the ordinary Cloud Spanner.

by specifying database.yml

development:
  adapter: "spanner"
  emulator_host: localhost:9010
  project: "emulator-project"
  instance: "emulator-instance"
  database: "app-dev"

production:
  adapter: "spanner"
  project: "<google project name>"
  instance: "<google instance name>"
  credentials: "<google credentails file path>"
  database: "app-prod"

or, by directly specifying settings as the arguments.

ActiveRecordSpannerAdapter::Connection.new(
  emulator_host: 'localhost:9010',
  keyfile: 'emulator.json',
  project: 'emulator-project'
)

This is already achieved in python library, and I think I can implement the similar design.

googleapis/python-spanner#87

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 googleapis/ruby-spanner-activerecord API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants