Skip to content

connecting to Bigtable emulator using environment variable - #6067

Merged
igorbernstein2 merged 4 commits into
googleapis:masterfrom
rahulKQL:autoEmulator
Aug 19, 2019
Merged

connecting to Bigtable emulator using environment variable#6067
igorbernstein2 merged 4 commits into
googleapis:masterfrom
rahulKQL:autoEmulator

Conversation

@rahulKQL

Copy link
Copy Markdown
Contributor

Fixes#6057

User can now connect to Bigtable emulator in three ways:

  • By settings hostName:portNum in BIGTABLE_EMULATOR_HOST environment variable.
  • By providing only the port number within the local workstation.
  • By providing hostName & port Number.

Now user can connect to Bigtable emulator in three ways:
- By settings hostName:portNum in BIGTABLE_EMULATOR_HOST environment variable.
- By providing only port number within the local workstation.
- By providing hostName & port Number.
@googlebotgooglebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 12, 2019

@igorbernstein2igorbernstein2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A couple more things:

  • please add a log statement notifying the user that the client is targeting the emulator.
  • in the test rule please add a precondition preventing tests from running when the environment variable is set. The test environment should be controlled via maven profiles not environment variables and the mixture will just create confusion
  • Please add a safe guard to the instance admin client that prevents its use when the env var is set (the emulator doesn't support instance admin api)

Thanks!

@codecov

codecovBot commented Aug 19, 2019

Copy link
Copy Markdown

Codecov Report

Merging #6067 into master will increase coverage by 0.26%.
The diff coverage is 20%.

Impacted file tree graph

@@ Coverage Diff @@## master #6067 +/- ##
============================================
+ Coverage 47.11% 47.38% +0.26% + Complexity 27195 27182 -13 
============================================
Files 2522 2523 +1 Lines 274264 274599 +335 Branches 31326 31383 +57 ============================================
+ Hits 129231 130124 +893 - Misses 134602 134862 +260 + Partials 10431 9613 -818
Impacted FilesCoverage ΔComplexity Δ
...e/cloud/bigtable/data/v2/BigtableDataSettings.java33.33% <16.66%> (-1.45%)4 <2> (+1)
.../bigtable/admin/v2/BigtableTableAdminSettings.java63.63% <18.18%> (-8.11%)8 <2> (+1)
...gtable/admin/v2/BigtableInstanceAdminSettings.java96.55% <50%> (-3.45%)6 <1> (ø)
...ain/java/com/google/cloud/storage/StorageImpl.java77.81% <0%> (-8.39%)98% <0%> (-5%)
...rc/main/java/com/google/cloud/storage/Storage.java79.72% <0%> (-5.45%)0% <0%> (ø)
...ud/storage/contrib/nio/testing/FakeStorageRpc.java59.66% <0%> (-1.29%)44% <0%> (ø)
...om/google/cloud/storage/spi/v1/HttpStorageRpc.java1.64% <0%> (-0.18%)1% <0%> (ø)
...e/cloud/vision/v1p4beta1/ImageAnnotatorClient.java62% <0%> (ø)19% <0%> (ø)⬇️
...ogle/cloud/storage/spi/v1/HttpStorageRpcSpans.java100% <0%> (ø)3% <0%> (ø)⬇️
...rc/main/java/com/google/cloud/storage/HmacKey.java5.73% <0%> (ø)0% <0%> (?)
... and 151 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 1c9c48c...5b9688b. Read the comment docs.

@igorbernstein2igorbernstein2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is looking good.

try {
port = Integer.parseInt(hostAndPort.substring(hostAndPort.lastIndexOf(":") + 1));
return newBuilderForEmulator(hostAndPort.substring(0, hostAndPort.lastIndexOf(":")), port);
} catch (NumberFormatException ex) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please handle IndexOutOfBoundsException as well

builder
.stubSettings()
.setProjectId("fake-project")
.setInstanceId("fake-instance")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This diverges from the other clients. I don't think we should set project & instance ids any more

* Create a new builder preconfigured to connect to the Bigtable emulator with host & port number.
*/
public static Builder newBuilderForEmulator(String hostname, int port) {
Builder builder = new Builder().setProjectId("fake-project").setInstanceId("fake-instance");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we should be setting the project instance ids to stay consistent with other languages

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

For Java, we have projectId & instanceId required. Shall I remove the Preconditions checks for projectId & InstanceId?
I would vote to keep these checks and continue with "fake-project" & "fake-instance".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure what you mean by that. I'm picturing something along the lines of:

BigtableTableAdminSettings.newBuilderForEmulator("localhost", 1234).setProjectId("blah").setInstanceId("blah2").build()

I think the other client languages require something similar

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Thanks for the explanation, I mistook it as emulator without any projectId & instanceId. Have updated with the suggestion. please have a look.

- Updated null check with String.isNullOrEmpty
- Handled IndexOutOfBoundsException
- fixed java doc in newBuilder()
- Adapted with TruthJunit.assume() instead of Assert.assume().

@igorbernstein2igorbernstein2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thanks for implementing this!

@igorbernstein2
igorbernstein2 merged commit 13fc06a into googleapis:masterAug 19, 2019
benjaminp pushed a commit to benjaminp/google-cloud-java that referenced this pull request Jul 13, 2026
…s#6067)
* connecting to Bigtable emulator using environment variable
Now user can connect to Bigtable emulator in three ways:
- By settings hostName:portNum in BIGTABLE_EMULATOR_HOST environment variable.
- By providing only port number within the local workstation.
- By providing hostName & port Number.
* Address feedback comment for emulator configs
* Address feedback commets
- Updated null check with String.isNullOrEmpty
- Handled IndexOutOfBoundsException
- fixed java doc in newBuilder()
- Adapted with TruthJunit.assume() instead of Assert.assume().
* Addressing more comments
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yesThis human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement BIGTABLE_EMULATOR_HOST environment variable support as in golang

3 participants

@rahulKQL@igorbernstein2@googlebot