Skip to content

Retrieve the right AWS metadata for private hostname#849

Merged
asfgit merged 1 commit intoapache:masterfrom
tbouron:fix/aws-local-hostname
Oct 4, 2017
Merged

Retrieve the right AWS metadata for private hostname#849
asfgit merged 1 commit intoapache:masterfrom
tbouron:fix/aws-local-hostname

Conversation

@tbouron
Copy link
Member

@tbouron tbouron commented Oct 2, 2017

In most conditions for AWS deployments (machine sshable) Brooklyn was retrieving the public-hostname metadata for both public AND private hostname sensors.

@tbouron tbouron force-pushed the fix/aws-local-hostname branch from d7786ce to 2455e05 Compare October 2, 2017 12:20
Copy link
Contributor

@andreaturli andreaturli Oct 2, 2017

Choose a reason for hiding this comment

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

thanks @tbouron, could we avoid the extra boolean parameter if we use something like

response=$(curl --write-out %{http_code} --silent --output /dev/null http://169.254.169.254/latest/meta-data/local-hostname)
if [ $(response) == "200" ] ; 
then
echo `curl --silent --retry 20 http://169.254.169.254/latest/meta-data/local-hostname"`; exit"));
else
echo `curl --silent --retry 20 http://169.254.169.254/latest/meta-data/public-hostname"`; exit"));

or something similar?

Copy link
Member Author

@tbouron tbouron Oct 2, 2017

Choose a reason for hiding this comment

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

@andreaturli I don't think so. http://169.254.169.254/latest/meta-data/local-hostname will always return some data and a 200 as AWS assigns a private IP/host for every single EC2 instance.

http://169.254.169.254/latest/meta-data/public-hostname could return a 404 (if the machine has been provisioned without an elastic IP, not entirely sure though) but in this situation, but that's not what we want

Copy link
Contributor

Choose a reason for hiding this comment

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

not sure I follow, @tbouron -- I think it would be easier to read if we have 2 methods
getPrivateAwsHostname and getPublicAwsHostname what do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

@andreaturli In you code example, http://169.254.169.254/latest/meta-data/local-hostname will always return a 200 (as an EC2 instance always as a private IP) so your if statement will always go one way which is not what we want here.

It would may be easier to read (although I'm not sure about that) but will also introduce some code duplication which I would be reluctant do to, especially in this huge file.

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry @tbouron, String getHostnameAws(...) is already very confusing, not mentioning the fact that is AWS specific which is another smell, IMHO.
Which hostname is going to return that method?
I think we have the chance to improve this area of the code and I think another (boolean) parameter is not going to help in that respect. wdyt?

Copy link
Member Author

@tbouron tbouron Oct 2, 2017

Choose a reason for hiding this comment

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

If you are ok to add even more code + duplication then sure, no problem, I'll do that :D

Agree this is a code smell (which has already been identified based on this comment) but I don't have a magical solution to improve this particular area. If you have any idea, I'm opened to suggestions @andreaturli

Copy link
Contributor

@andreaturli andreaturli Oct 2, 2017

Choose a reason for hiding this comment

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

@tbouron if we can rely on jclouds for getting the private hostname usingNodeMetadata.getHostname, Brooklyn doesn’t need to calculate a new one especially for nodes created using JcloudsLocation. Notice NodeMetadata.getHostname is nullable so I think JcloudsLocation should manage that or assign the value to host.addresses.private

Copy link
Member Author

Choose a reason for hiding this comment

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

@andreaturli I did what you suggested: using NodeMetadata.getHostname or reusing the getPrivateHostnameGeneric() method for private hostname. The public hostname is calculated as before.

@tbouron tbouron force-pushed the fix/aws-local-hostname branch from 2455e05 to 8877368 Compare October 2, 2017 15:20
// exceptional situation rather than a pattern to follow. We need a better way to
// do cloud-specific things.
if ("aws-ec2".equals(provider) && Boolean.TRUE.equals(lookupAwsHostname)) {
Maybe<String> result = getHostnameAws(node, sshHostAndPort, userCredentials, setup);
Copy link
Contributor

Choose a reason for hiding this comment

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

looks much easier @tbouron -- can we remove getHostnameAws or is it used elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

@andreaturli It is unfortunately used by the DefaultConnectivityResolver class

@tbouron
Copy link
Member Author

tbouron commented Oct 3, 2017

@andreaturli Looks like it works as expected :)

screen shot 2017-10-03 at 11 17 06

@andreaturli
Copy link
Contributor

lgtm thanks @tbouron

@asfgit asfgit merged commit 8877368 into apache:master Oct 4, 2017
asfgit pushed a commit that referenced this pull request Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments