-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
[GCE Discovery] Automatically set project-id and zone #33721
Conversation
Pinging @elastic/es-distributed |
@elasticmachine test this please |
@vladimirdolzhenko thanks for picking this up! do you mind updating the PR title to indicate it relates to GCE discovery and maybe add a sentence or two to the descriptiont telling people what zone and project id are used for and why this is a good default? |
@elasticmachine test this please |
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 left some minor comments. As a follow up I think we should upgrade the SDK here. And do you think that we could have a fixture based integration test (QA) for this plugin?
plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceInstancesServiceImpl.java
Outdated
Show resolved
Hide resolved
plugins/discovery-gce/src/main/java/org/elasticsearch/cloud/gce/GceInstancesServiceImpl.java
Outdated
Show resolved
Hide resolved
…s from metadata service
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.
LGTM - Did you test it on GCE?
tested on GCE: |
May be that changed since I opened the original issue. :) |
@elasticmachine test this please |
@tlrx I'd like to ask you to have another look into this PR as I've spotted an issue on a real GCE and therefore added QA tests (and performed manual tests after fix). One think I don't feel quite comfortable is to exposing two new settings - it is not possible to run QA cluster w/o them. |
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.
It looks good, I left some minor comments. That's a very good thing that the QA test spotted an issue during manual tests, well done!
One think I don't feel quite comfortable is to exposing two new settings - it is not possible to run QA cluster w/o them
I agree... Maybe we could use a system property here (something similar to es.allow_insecure_settings) that would register the test settings only when the system property is set? In regular test classes you could still extend the GceDiscoveryPlugin to register the extra settings.
@ywelsch Can you give an opinion? And look at the PR too? Thanks :)
testCompile project(path: ':plugins:discovery-gce', configuration: 'runtime') | ||
} | ||
|
||
/** A task to start the GCEFixture which emulates an GCE service **/ |
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.
nit: an -> a
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: ba608f7
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
/** | ||
* {@link GCEFixture} is a fixture that emulates an GCE service. |
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.
Same here
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 well in ba608f7
commonHeaderConsumer.accept(headers); | ||
|
||
final StringBuilder builder = new StringBuilder(); | ||
builder.append("{\"id\": \"test-instances\",\"items\":["); |
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.
Could you have used a jsonBuilder() instead?
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.
sure: 67f6b22
|
||
@SuppressForbidden(reason = "use http server") | ||
public class GceInstancesServiceTests extends ESTestCase { | ||
private static HttpServer httpServer; |
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.
Now we have a QA test do we really need this one?
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.
agree, unit test has no additional value with qa test, dropped in cf4f744
@@ -0,0 +1,36 @@ | |||
{ |
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 that we should replace those JSON files by simple code in the test class (not in this PR). I'm not even sure that they are all used.
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.
they are used in GceDiscoveryTests#testMetadataServerValues
numNodes = gceNumberOfNodes | ||
plugin ':plugins:discovery-gce' | ||
setting 'discovery.zen.hosts_provider', 'gce' | ||
setting 'cloud.gce.host', "http://${-> gceFixture.addressAndPort}" |
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.
Can you add a small comment about what is each setting here?
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 aa7c93b
…ile unit tests don't spot all issues
…se GCE-specific settings: `cloud.gce.host` and `cloud.gce.root_url`
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.
LGTM, thanks @vladimirdolzhenko
...s/discovery-gce/src/main/java/org/elasticsearch/plugin/discovery/gce/GceDiscoveryPlugin.java
Outdated
Show resolved
Hide resolved
docs/plugins/discovery-gce.asciidoc
Outdated
https://developers.google.com/compute/docs/zones#available[GCE supported zones]. | ||
helps to retrieve instances running in a given zone. | ||
It should be one of the https://developers.google.com/compute/docs/zones#available[GCE supported zones]. | ||
If the value is not specified, default zone is picked up from a metadata server. |
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.
Same here:
By default the zone will be derived from the instance metadata
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.
thanks, this and other doc related comments are applied in 1159638
@@ -180,6 +234,16 @@ public synchronized Compute client() { | |||
return this.client; | |||
} | |||
|
|||
@Override | |||
public String project() { |
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.
call this method projectId
?
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.
addressed in 38cdcc0
Fetch default values for project-id and zone from metadata server Closes #13618
Settings
cloud.gce.project_id
,cloud.gce.zone
are not mandatory - they could be automatically set from a gce metadata server. Picking up the default zone is useful for cases like a single region.Details on impl differences with GCE:
com.google.cloud.ServiceOptions#getDefaultProjectId tries to resolve project based on
GOOGLE_CLOUD_PROJECT
(or legacy system propertyGCLOUD_PROJECT
)GOOGLE_CLOUD_PROJECT
orGCLOUD_PROJECT
http://metadata.google.internal/computeMetadata/v1/project/project-id
This PR allows without settings to fallback to retrieve info from gce metadata server
Closes #13618