GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: check Compute Engine environment for DirectPath by mohanli-ml · Pull Request #1250 · googleapis/gax-java

This repository was archived by the owner on Sep 26, 2023. It is now read-only.

Conversation

@mohanli-ml

@mohanli-ml mohanli-ml commented Nov 14, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Add Compute Engine environment check since DirectPath can only be used on Compute Engine. This doc is used for checking: https://docs.google.com/document/d/1xQXE27x9wTvwPsgiX9Hn0o8mcq5z3SKi-1jwscQsCAk/edit#. Relevant issue and PR: grpc/grpc-java#7604 and googleapis/java-bigtable#520.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mohanli-ml
mohanli-ml requested review from a team November 14, 2020 03:31
@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Nov 14, 2020
elharo
elharo reviewed Nov 14, 2020
View reviewed changes

@elharo elharo left a comment

Copy link
Copy Markdown
Contributor

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.

needs tests

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@elharo elharo changed the title fix: check Compute Engine environmentfor DirectPath fix: check Compute Engine environment for DirectPath Nov 17, 2020
elharo
elharo suggested changes Nov 18, 2020
View reviewed changes
Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Outdated
resultOutStream.write(bs, 0, num);
}
String result = new String(resultOutStream.toByteArray());
return result.contains("01/01/2011") && result.contains("Google");

@elharo elharo Nov 18, 2020

Copy link
Copy Markdown
Contributor

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.

why this date?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mohanli-ml mohanli-ml Nov 18, 2020

Copy link
Copy Markdown
Contributor Author

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.

See this doc: https://docs.google.com/document/d/1xQXE27x9wTvwPsgiX9Hn0o8mcq5z3SKi-1jwscQsCAk/edit#heading=h.7ioa2p9bw6l1

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Nov 19, 2020

Copy link
Copy Markdown
Contributor

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.

As this is open source code, can this be made with a reference to a public doc?
Also this needs a comment in the source code explaining it, and possibly a named constant for the date.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mohanli-ml mohanli-ml Nov 19, 2020

Copy link
Copy Markdown
Contributor Author

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 could not find a public doc, so I just removed the link in the code. Two constants are added though.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Nov 19, 2020

Copy link
Copy Markdown
Contributor

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.

per doc, Virtual machines started after August 2016 have access to a more reliable "product name" string which is equal to "Google Compute Engine".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mohanli-ml mohanli-ml Nov 19, 2020

Copy link
Copy Markdown
Contributor Author

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.

"Google Compute Engine" is for /sys/class/dmi/id/product_name, but for now we are checking /sys/class/dmi/id/bios_date and /sys/class/dmi/id/bios_vendor in the code. Do you think we also need to check /sys/class/dmi/id/product_name?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Nov 19, 2020

Copy link
Copy Markdown
Contributor

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'm just going by the doc you cited. I read it as saying one should use product name instead of bios id and vendor

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mohanli-ml mohanli-ml Nov 19, 2020

Copy link
Copy Markdown
Contributor Author

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 see, yeah, thanks, product name is used now.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@codecov

codecov Bot commented Nov 19, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #1250 (cf494ce) into master (d455da2) will decrease coverage by 0.34%.
The diff coverage is 42.85%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1250      +/-   ##
============================================
- Coverage     79.32%   78.98%   -0.35%     
  Complexity     1226     1226              
============================================
  Files           209      209              
  Lines          5344     5357      +13     
  Branches        442      446       +4     
============================================
- Hits           4239     4231       -8     
- Misses          931      948      +17     
- Partials        174      178       +4     
Impacted Files Coverage Δ Complexity Δ
...api/gax/grpc/InstantiatingGrpcChannelProvider.java 69.08% <42.85%> (-8.76%) 33.00 <1.00> (ø)

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 d455da2...cf494ce. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

elharo
elharo reviewed Nov 19, 2020
View reviewed changes
Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Outdated
resultOutStream.write(bs, 0, num);
}
String result = new String(resultOutStream.toByteArray());
return result.contains("01/01/2011") && result.contains("Google");

@elharo elharo Nov 19, 2020

Copy link
Copy Markdown
Contributor

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.

per doc, Virtual machines started after August 2016 have access to a more reliable "product name" string which is equal to "Google Compute Engine".

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Outdated
Process process = Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", cmd});
process.waitFor();
String result = CharStreams.toString(new InputStreamReader(process.getInputStream()));
return result.contains(GCE_BIOS_DATE) && result.contains(GCE_BIOS_VENDOR);

@elharo elharo Nov 19, 2020

Copy link
Copy Markdown
Contributor

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.

per doc, "Virtual machines started after August 2016 have access to a more reliable "product name" string which is equal to "Google Compute Engine"."

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mohanli-ml
mohanli-ml requested a review from elharo November 19, 2020 18:32
elharo
elharo reviewed Nov 19, 2020
View reviewed changes
Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Outdated
try {
Process process = Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", cmd});
process.waitFor();
String result = CharStreams.toString(new InputStreamReader(process.getInputStream()));

@elharo elharo Nov 19, 2020

Copy link
Copy Markdown
Contributor

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.

This needs an explicit encoding, probably UTF-8

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mohanli-ml mohanli-ml Nov 19, 2020

Copy link
Copy Markdown
Contributor Author

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.

UTF-8 encoding added. Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
elharo
elharo approved these changes Nov 19, 2020
View reviewed changes
chingor13
chingor13 suggested changes Nov 19, 2020
View reviewed changes
Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java Outdated

// DirectPath should only be used on Compute Engine.
// Notice Windows is supported for now.
public static boolean isOnComputeEngine() {

@chingor13 chingor13 Nov 19, 2020

Copy link
Copy Markdown
Contributor

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.

Does this need to be public? If it's just for testing we can make it default visibility.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mohanli-ml mohanli-ml Nov 19, 2020

Copy link
Copy Markdown
Contributor Author

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.

This is a good point. public has been removed. Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mohanli-ml
fix: check Compute Engine environment for DirectPath
cf494ce
chingor13
chingor13 approved these changes Nov 19, 2020
View reviewed changes
@chingor13
chingor13 merged commit 656b613 into googleapis:master Nov 19, 2020
ejona86
ejona86 reviewed Nov 23, 2020
View reviewed changes
Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
if ("Linux".equals(osName)) {
String cmd = "cat /sys/class/dmi/id/product_name";
try {
Process process = Runtime.getRuntime().exec(new String[] {"/bin/sh", "-c", cmd});

@ejona86 ejona86 Nov 23, 2020

Copy link
Copy Markdown

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.

What is going on here? Why is this forking a process, to call a shell to then run the cat command to read a file? That seems unnecessary on two levels. Why not use a FileInputStream? Is there something I'm missing?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mohanli-ml mohanli-ml Nov 23, 2020

Copy link
Copy Markdown
Contributor Author

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.

Hey Eric, yes FileInputStream can definitely work. Sorry I am not a java expert and I directly follow the doc to use a shall command. Do you want me to make the change?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ejona86 ejona86 Nov 23, 2020

Copy link
Copy Markdown

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'm not a gax-java maintaner, so "I have no power here." But it seems like a good idea to fix it, as it reduces the chances of something going wrong and makes it easier to debug. For example, if there's permission problems the error will be more obvious.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@mohanli-ml mohanli-ml Nov 23, 2020

Copy link
Copy Markdown
Contributor Author

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.

OK, I will have another PR for this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sanjaypujare sanjaypujare Mar 9, 2021

Copy link
Copy Markdown

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 think we should fix this. Process/exec on "bin/sh" seems completely unnecessary

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Mar 9, 2021

Copy link
Copy Markdown
Contributor

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.

Please file an issue

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sanjaypujare sanjaypujare Mar 9, 2021

Copy link
Copy Markdown

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.

Done #1323

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@mohanli-ml mohanli-ml mentioned this pull request Nov 30, 2020
feat: attempt DirectPath by default googleapis/java-bigtable#544
Merged
sanjaypujare
sanjaypujare reviewed Mar 9, 2021
View reviewed changes
Comment thread gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java
String result =
CharStreams.toString(new InputStreamReader(process.getInputStream(), "UTF-8"));
return result.contains(GCE_PRODUCTION_NAME_PRIOR_2016)
|| result.contains(GCE_PRODUCTION_NAME_AFTER_2016);

@sanjaypujare sanjaypujare Mar 9, 2021

Copy link
Copy Markdown

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.

So couple of comments:

  • if the result contains something like Google App Engine then this will return true because GCE_PRODUCTION_NAME_PRIOR_2016 = "Google" even though this is App Engine and not GCE.

  • Secondly I did a test on a pod in GKE and

cat /sys/class/dmi/id/product_name
Google Compute Engine

So even on GKE it returns "Google Compute Engine" so it is quite possible even on GAE it returns the same string.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@sanjaypujare sanjaypujare mentioned this pull request Mar 9, 2021
code should be updated as indicated in the PR comments #1323
Closed
@igorbernstein2 igorbernstein2 mentioned this pull request Jun 29, 2021
feat: allow DirectPath by default + update integration tests googleapis/java-bigtable-hbase#3031
Merged
@mohanli-ml mohanli-ml mentioned this pull request Oct 17, 2023
feat: log DirectPath misconfiguration googleapis/sdk-platform-java#2105
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

4 more reviewers
@elharo elharo elharo approved these changes
@ejona86 ejona86 ejona86 left review comments
@sanjaypujare sanjaypujare sanjaypujare left review comments
@chingor13 chingor13 chingor13 approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@mohanli-ml @chingor13 @elharo @ejona86 @sanjaypujare
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.