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

[GCE Discovery] Automatically set project-id and zone #33721

Merged
merged 21 commits into from
Oct 3, 2018

Conversation

vladimirdolzhenko
Copy link
Contributor

@vladimirdolzhenko vladimirdolzhenko commented Sep 14, 2018

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

  • system property GOOGLE_CLOUD_PROJECT (or legacy system property GCLOUD_PROJECT)
  • environment variable GOOGLE_CLOUD_PROJECT or GCLOUD_PROJECT
  • from 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

@vladimirdolzhenko vladimirdolzhenko added >enhancement :Distributed Coordination/Discovery-Plugins Anything related to our integration plugins with EC2, GCP and Azure v7.0.0 labels Sep 14, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-distributed

@vladimirdolzhenko
Copy link
Contributor Author

@elasticmachine test this please

@bleskes
Copy link
Contributor

bleskes commented Sep 15, 2018

@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?

@vladimirdolzhenko vladimirdolzhenko changed the title Automatically set project-id and zone [GCE Discovery] Automatically set project-id and zone Sep 15, 2018
@vladimirdolzhenko
Copy link
Contributor Author

@elasticmachine test this please

Copy link
Member

@tlrx tlrx left a 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?

Copy link
Member

@tlrx tlrx left a 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?

@vladimirdolzhenko
Copy link
Contributor Author

vladimirdolzhenko commented Sep 19, 2018

tested on GCE:
project-id works
google-compute-default-zone is not there

@dadoonet
Copy link
Member

dadoonet commented Sep 19, 2018

May be that changed since I opened the original issue. :)

@vladimirdolzhenko
Copy link
Contributor Author

google-compute-default-zone metaattribute appeared after specifying default zone for the project :
screen shot 2018-09-20 at 22 06 27

AccessControlException happens on testing in a real GCE, to fix it QA test was added (two settings - cloud.gce.host and cloud.gce.root_url are exposed for that).

@vladimirdolzhenko
Copy link
Contributor Author

@elasticmachine test this please

@vladimirdolzhenko
Copy link
Contributor Author

@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.

Copy link
Member

@tlrx tlrx left a 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 **/
Copy link
Member

Choose a reason for hiding this comment

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

nit: an -> a

Copy link
Contributor Author

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.
Copy link
Member

Choose a reason for hiding this comment

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

Same here

Copy link
Contributor Author

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\":[");
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Member

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?

Copy link
Contributor Author

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 @@
{
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

numNodes = gceNumberOfNodes
plugin ':plugins:discovery-gce'
setting 'discovery.zen.hosts_provider', 'gce'
setting 'cloud.gce.host', "http://${-> gceFixture.addressAndPort}"
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done aa7c93b

@vladimirdolzhenko
Copy link
Contributor Author

@tlrx in 1c2a66b I've added a system property es.allow_reroute_gce_settings to expose for the test purposes those two GCE-specific settings, so they are not exposed by default

Copy link
Member

@tlrx tlrx left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @vladimirdolzhenko

docs/plugins/discovery-gce.asciidoc Outdated Show resolved Hide resolved
docs/plugins/discovery-gce.asciidoc Outdated Show resolved Hide resolved
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.
Copy link
Contributor

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

Copy link
Contributor Author

@vladimirdolzhenko vladimirdolzhenko Oct 1, 2018

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() {
Copy link
Contributor

Choose a reason for hiding this comment

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

call this method projectId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

addressed in 38cdcc0

@vladimirdolzhenko
Copy link
Contributor Author

thanks @tlrx and @ywelsch

@vladimirdolzhenko vladimirdolzhenko merged commit a7f62ee into elastic:master Oct 3, 2018
@vladimirdolzhenko vladimirdolzhenko deleted the 13618 branch October 3, 2018 09:38
vladimirdolzhenko added a commit that referenced this pull request Oct 3, 2018
Fetch default values for project-id and zone from metadata server

Closes #13618

(cherry picked from commit a7f62ee)
kcm pushed a commit that referenced this pull request Oct 30, 2018
Fetch default values for project-id and zone from metadata server

Closes #13618
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Distributed Coordination/Discovery-Plugins Anything related to our integration plugins with EC2, GCP and Azure >enhancement v6.5.0 v7.0.0-beta1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Automatically set project-id and zone
7 participants