Skip to content

Commit 1793093

Browse files
committed
Update after review
1 parent 3804bfc commit 1793093

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

docs/plugins/discovery-ec2.asciidoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,13 @@ The following are a list of settings (prefixed with `discovery.ec2`) that can fu
176176
--
177177
The type of host type to use to communicate with other instances. Can be
178178
one of `private_ip`, `public_ip`, `private_dns`, `public_dns` or `tag:TAGNAME` where
179-
`TAGNAME` is the tag field you defined for your ec2 instance.
179+
`TAGNAME` refers to a name of a tag configured for all EC2 instances. Instances which don't
180+
have this tag set will be ignored by the discovery process.
180181

181182
For example if you defined a tag `my-elasticsearch-host` in ec2 and set it to `myhostname1.mydomain.com`, then
182183
setting `host_type: tag:my-elasticsearch-host` will tell Discovery Ec2 plugin to read the host name from the
183184
`my-elasticsearch-host` tag. In this case, it will be resolved to `myhostname1.mydomain.com`.
185+
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Using_Tags.html[Read more about EC2 Tags].
184186

185187
Defaults to `private_ip`.
186188
--

plugins/discovery-ec2/src/main/java/org/elasticsearch/cloud/aws/AwsEc2Service.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,9 @@ class HostType {
174174

175175
/**
176176
* discovery.ec2.host_type: The type of host type to use to communicate with other instances.
177-
* Can be one of private_ip, public_ip, private_dns, public_dns or meta:XXXX where
178-
* XXXX is the metadata field name we will read the address from. Defaults to private_ip.
177+
* Can be one of private_ip, public_ip, private_dns, public_dns or tag:XXXX where
178+
* XXXX refers to a name of a tag configured for all EC2 instances. Instances which don't
179+
* have this tag set will be ignored by the discovery process. Defaults to private_ip.
179180
*/
180181
Setting<String> HOST_TYPE_SETTING =
181182
new Setting<>("discovery.ec2.host_type", HostType.PRIVATE_IP, Function.identity(), Property.NodeScope);

plugins/discovery-ec2/src/main/java/org/elasticsearch/discovery/ec2/AwsEc2UnicastHostsProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ && disjoint(securityGroupIds, groups)) {
181181
TransportAddress[] addresses = transportService.addressesFromString(address, 1);
182182
for (int i = 0; i < addresses.length; i++) {
183183
logger.trace("adding {}, address {}, transport_address {}", instance.getInstanceId(), address, addresses[i]);
184-
discoNodes.add(new DiscoveryNode("#cloud-" + instance.getInstanceId() + "-" + i, addresses[i],
184+
discoNodes.add(new DiscoveryNode(instance.getInstanceId(), "#cloud-" + instance.getInstanceId() + "-" + i, addresses[i],
185185
emptyMap(), emptySet(), Version.CURRENT.minimumCompatibilityVersion()));
186186
}
187187
} catch (Exception e) {

plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2DiscoveryTests.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void testReadHostFromTag() throws InterruptedException, UnknownHostExcept
268268

269269
for (int node = 0; node < nodes; node++) {
270270
addresses[node] = "192.168.0." + (node + 1);
271-
poorMansDNS.put("bar_" + node, new TransportAddress(InetAddress.getByName(addresses[node]), 9300));
271+
poorMansDNS.put("node" + (node + 1), new TransportAddress(InetAddress.getByName(addresses[node]), 9300));
272272
}
273273

274274
Settings nodeSettings = Settings.builder()
@@ -279,15 +279,17 @@ public void testReadHostFromTag() throws InterruptedException, UnknownHostExcept
279279

280280
for (int node = 0; node < nodes; node++) {
281281
List<Tag> tags = new ArrayList<>();
282-
tags.add(new Tag("foo", "bar_" + node));
282+
tags.add(new Tag("foo", "node" + (node + 1)));
283283
tagsList.add(tags);
284284
}
285285

286286
logger.info("started [{}] instances", nodes);
287287
List<DiscoveryNode> discoveryNodes = buildDynamicNodes(nodeSettings, nodes, tagsList);
288288
assertThat(discoveryNodes, hasSize(nodes));
289289
for (DiscoveryNode discoveryNode : discoveryNodes) {
290-
assertThat(discoveryNode.getHostName(), isOneOf(addresses));
290+
TransportAddress address = discoveryNode.getAddress();
291+
TransportAddress expected = poorMansDNS.get(discoveryNode.getName());
292+
assertEquals(address, expected);
291293
}
292294
}
293295

0 commit comments

Comments
 (0)