Skip to content

Commit 26c4f1f

Browse files
authored
Core: Default node.name to the hostname (#33677)
Changes the default of the `node.name` setting to the hostname of the machine on which Elasticsearch is running. Previously it was the first 8 characters of the node id. This had the advantage of producing a unique name even when the node name isn't configured but the disadvantage of being unrecognizable and not being available until fairly late in the startup process. Of particular interest is that it isn't available until after logging is configured. This forces us to use a volatile read whenever we add the node name to the log. Using the hostname is available immediately on startup and is generally recognizable but has the disadvantage of not being unique when run on machines that don't set their hostname or when multiple elasticsearch processes are run on the same host. I believe that, taken together, it is better to default to the hostname. 1. Running multiple copies of Elasticsearch on the same node is a fairly advanced feature. We do it all the as part of the elasticsearch build for testing but we make sure to set the node name then. 2. That the node.name defaults to some flavor of "localhost" on an unconfigured box feels like it isn't going to come up too much in production. I expect most production deployments to at least set the hostname. As a bonus, production deployments need no longer set the node name in most cases. At least in my experience most folks set it to the hostname anyway.
1 parent 3df285d commit 26c4f1f

File tree

26 files changed

+170
-228
lines changed

26 files changed

+170
-228
lines changed

distribution/archives/integ-test-zip/src/test/java/org/elasticsearch/test/rest/NodeNameInLogsIT.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.test.rest;
2121

2222
import org.elasticsearch.common.logging.NodeNameInLogsIntegTestCase;
23+
import org.hamcrest.Matcher;
2324

2425
import java.io.IOException;
2526
import java.io.BufferedReader;
@@ -29,9 +30,16 @@
2930
import java.security.AccessController;
3031
import java.security.PrivilegedAction;
3132

33+
import static org.hamcrest.Matchers.is;
34+
3235
public class NodeNameInLogsIT extends NodeNameInLogsIntegTestCase {
3336
@Override
34-
protected BufferedReader openReader(Path logFile) throws IOException {
37+
protected Matcher<String> nodeNameMatcher() {
38+
return is("node-0");
39+
}
40+
41+
@Override
42+
protected BufferedReader openReader(Path logFile) {
3543
return AccessController.doPrivileged((PrivilegedAction<BufferedReader>) () -> {
3644
try {
3745
return Files.newBufferedReader(logFile, StandardCharsets.UTF_8);

docs/reference/getting-started.asciidoc

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -236,29 +236,36 @@ If everything goes well with installation, you should see a bunch of messages th
236236

237237
["source","sh",subs="attributes,callouts"]
238238
--------------------------------------------------
239-
[2016-09-16T14:17:51,251][INFO ][o.e.n.Node ] [] initializing ...
240-
[2016-09-16T14:17:51,329][INFO ][o.e.e.NodeEnvironment ] [6-bjhwl] using [1] data paths, mounts [[/ (/dev/sda1)]], net usable_space [317.7gb], net total_space [453.6gb], spins? [no], types [ext4]
241-
[2016-09-16T14:17:51,330][INFO ][o.e.e.NodeEnvironment ] [6-bjhwl] heap size [1.9gb], compressed ordinary object pointers [true]
242-
[2016-09-16T14:17:51,333][INFO ][o.e.n.Node ] [6-bjhwl] node name [6-bjhwl] derived from node ID; set [node.name] to override
243-
[2016-09-16T14:17:51,334][INFO ][o.e.n.Node ] [6-bjhwl] version[{version}], pid[21261], build[f5daa16/2016-09-16T09:12:24.346Z], OS[Linux/4.4.0-36-generic/amd64], JVM[Oracle Corporation/Java HotSpot(TM) 64-Bit Server VM/1.8.0_60/25.60-b23]
244-
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded module [aggs-matrix-stats]
245-
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded module [ingest-common]
246-
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded module [lang-expression]
247-
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded module [lang-mustache]
248-
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded module [lang-painless]
249-
[2016-09-16T14:17:51,967][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded module [percolator]
250-
[2016-09-16T14:17:51,968][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded module [reindex]
251-
[2016-09-16T14:17:51,968][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded module [transport-netty3]
252-
[2016-09-16T14:17:51,968][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded module [transport-netty4]
253-
[2016-09-16T14:17:51,968][INFO ][o.e.p.PluginsService ] [6-bjhwl] loaded plugin [mapper-murmur3]
254-
[2016-09-16T14:17:53,521][INFO ][o.e.n.Node ] [6-bjhwl] initialized
255-
[2016-09-16T14:17:53,521][INFO ][o.e.n.Node ] [6-bjhwl] starting ...
256-
[2016-09-16T14:17:53,671][INFO ][o.e.t.TransportService ] [6-bjhwl] publish_address {192.168.8.112:9300}, bound_addresses {{192.168.8.112:9300}
257-
[2016-09-16T14:17:53,676][WARN ][o.e.b.BootstrapCheck ] [6-bjhwl] max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
258-
[2016-09-16T14:17:56,718][INFO ][o.e.c.s.ClusterService ] [6-bjhwl] new_master {6-bjhwl}{6-bjhwl4TkajjoD2oEipnQ}{8m3SNKoFR6yQl1I0JUfPig}{192.168.8.112}{192.168.8.112:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
259-
[2016-09-16T14:17:56,731][INFO ][o.e.h.HttpServer ] [6-bjhwl] publish_address {192.168.8.112:9200}, bound_addresses {[::1]:9200}, {192.168.8.112:9200}
260-
[2016-09-16T14:17:56,732][INFO ][o.e.g.GatewayService ] [6-bjhwl] recovered [0] indices into cluster_state
261-
[2016-09-16T14:17:56,748][INFO ][o.e.n.Node ] [6-bjhwl] started
239+
[2018-09-13T12:20:01,766][INFO ][o.e.e.NodeEnvironment ] [localhost.localdomain] using [1] data paths, mounts [[/home (/dev/mapper/fedora-home)]], net usable_space [335.3gb], net total_space [410.3gb], types [ext4]
240+
[2018-09-13T12:20:01,772][INFO ][o.e.e.NodeEnvironment ] [localhost.localdomain] heap size [990.7mb], compressed ordinary object pointers [true]
241+
[2018-09-13T12:20:01,774][INFO ][o.e.n.Node ] [localhost.localdomain] node name [localhost.localdomain], node ID [B0aEHNagTiWx7SYj-l4NTw]
242+
[2018-09-13T12:20:01,775][INFO ][o.e.n.Node ] [localhost.localdomain] version[{version}], pid[13030], build[oss/zip/77fc20e/2018-09-13T15:37:57.478402Z], OS[Linux/4.16.11-100.fc26.x86_64/amd64], JVM["Oracle Corporation"/OpenJDK 64-Bit Server VM/10/10+46]
243+
[2018-09-13T12:20:01,775][INFO ][o.e.n.Node ] [localhost.localdomain] JVM arguments [-Xms1g, -Xmx1g, -XX:+UseConcMarkSweepGC, -XX:CMSInitiatingOccupancyFraction=75, -XX:+UseCMSInitiatingOccupancyOnly, -XX:+AlwaysPreTouch, -Xss1m, -Djava.awt.headless=true, -Dfile.encoding=UTF-8, -Djna.nosys=true, -XX:-OmitStackTraceInFastThrow, -Dio.netty.noUnsafe=true, -Dio.netty.noKeySetOptimization=true, -Dio.netty.recycler.maxCapacityPerThread=0, -Dlog4j.shutdownHookEnabled=false, -Dlog4j2.disable.jmx=true, -Djava.io.tmpdir=/tmp/elasticsearch.LN1ctLCi, -XX:+HeapDumpOnOutOfMemoryError, -XX:HeapDumpPath=data, -XX:ErrorFile=logs/hs_err_pid%p.log, -Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m, -Djava.locale.providers=COMPAT, -XX:UseAVX=2, -Dio.netty.allocator.type=unpooled, -Des.path.home=/home/manybubbles/Workspaces/Elastic/master/elasticsearch/qa/unconfigured-node-name/build/cluster/integTestCluster node0/elasticsearch-7.0.0-alpha1-SNAPSHOT, -Des.path.conf=/home/manybubbles/Workspaces/Elastic/master/elasticsearch/qa/unconfigured-node-name/build/cluster/integTestCluster node0/elasticsearch-7.0.0-alpha1-SNAPSHOT/config, -Des.distribution.flavor=oss, -Des.distribution.type=zip]
244+
[2018-09-13T12:20:02,543][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [aggs-matrix-stats]
245+
[2018-09-13T12:20:02,543][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [analysis-common]
246+
[2018-09-13T12:20:02,543][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [ingest-common]
247+
[2018-09-13T12:20:02,544][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [lang-expression]
248+
[2018-09-13T12:20:02,544][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [lang-mustache]
249+
[2018-09-13T12:20:02,544][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [lang-painless]
250+
[2018-09-13T12:20:02,544][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [mapper-extras]
251+
[2018-09-13T12:20:02,544][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [parent-join]
252+
[2018-09-13T12:20:02,544][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [percolator]
253+
[2018-09-13T12:20:02,544][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [rank-eval]
254+
[2018-09-13T12:20:02,544][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [reindex]
255+
[2018-09-13T12:20:02,545][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [repository-url]
256+
[2018-09-13T12:20:02,545][INFO ][o.e.p.PluginsService ] [localhost.localdomain] loaded module [transport-netty4]
257+
[2018-09-13T12:20:02,545][INFO ][o.e.p.PluginsService ] [localhost.localdomain] no plugins loaded
258+
[2018-09-13T12:20:04,657][INFO ][o.e.d.DiscoveryModule ] [localhost.localdomain] using discovery type [zen]
259+
[2018-09-13T12:20:05,006][INFO ][o.e.n.Node ] [localhost.localdomain] initialized
260+
[2018-09-13T12:20:05,007][INFO ][o.e.n.Node ] [localhost.localdomain] starting ...
261+
[2018-09-13T12:20:05,202][INFO ][o.e.t.TransportService ] [localhost.localdomain] publish_address {127.0.0.1:9300}, bound_addresses {[::1]:9300}, {127.0.0.1:9300}
262+
[2018-09-13T12:20:05,221][WARN ][o.e.b.BootstrapChecks ] [localhost.localdomain] max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
263+
[2018-09-13T12:20:05,221][WARN ][o.e.b.BootstrapChecks ] [localhost.localdomain] max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
264+
[2018-09-13T12:20:08,355][INFO ][o.e.c.s.MasterService ] [localhost.localdomain] zen-disco-elected-as-master ([0] nodes joined)[, ], reason: master node changed {previous [], current [{localhost.localdomain}{B0aEHNagTiWx7SYj-l4NTw}{hzsQz6CVQMCTpMCVLM4IHg}{127.0.0.1}{127.0.0.1:9300}{testattr=test}]}
265+
[2018-09-13T12:20:08,360][INFO ][o.e.c.s.ClusterApplierService] [localhost.localdomain] master node changed {previous [], current [{localhost.localdomain}{B0aEHNagTiWx7SYj-l4NTw}{hzsQz6CVQMCTpMCVLM4IHg}{127.0.0.1}{127.0.0.1:9300}{testattr=test}]}, reason: apply cluster state (from master [master {localhost.localdomain}{B0aEHNagTiWx7SYj-l4NTw}{hzsQz6CVQMCTpMCVLM4IHg}{127.0.0.1}{127.0.0.1:9300}{testattr=test} committed version [1] source [zen-disco-elected-as-master ([0] nodes joined)[, ]]])
266+
[2018-09-13T12:20:08,384][INFO ][o.e.h.n.Netty4HttpServerTransport] [localhost.localdomain] publish_address {127.0.0.1:9200}, bound_addresses {[::1]:9200}, {127.0.0.1:9200}
267+
[2018-09-13T12:20:08,384][INFO ][o.e.n.Node ] [localhost.localdomain] started
268+
262269
--------------------------------------------------
263270

264271
Without going too much into detail, we can see that our node named "6-bjhwl" (which will be a different set of characters in your case) has started and elected itself as a master in a single cluster. Don't worry yet at the moment what master means. The main thing that is important here is that we have started one node within one cluster.

docs/reference/migration/migrate_7_0/settings.asciidoc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
=== Settings changes
44

5+
==== The default for `node.name` is now the hostname
6+
7+
`node.name` now defaults to the hostname at the time when Elasticsearch
8+
is started. Previously the default node name was the first eight characters
9+
of the node id. It can still be configured explicitly in `elasticsearch.yml`.
10+
511
==== Percolator
612

713
* The deprecated `index.percolator.map_unmapped_fields_as_string` setting has been removed in favour of
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
[[node.name]]
22
=== `node.name`
33

4-
By default, Elasticsearch will use the first seven characters of the randomly
5-
generated UUID as the node id. Note that the node id is persisted and does
6-
not change when a node restarts and therefore the default node name will also
7-
not change.
8-
9-
It is worth configuring a more meaningful name which will also have the
10-
advantage of persisting after restarting the node:
4+
Elasticsearch uses `node.name` as a human readable identifier for a
5+
particular instance of Elasticsearch so it is included in the response
6+
of many APIs. It defaults to the hostname that the machine has when
7+
Elasticsearch starts but can be configured explicitly in
8+
`elasticsearch.yml` as follows:
119

1210
[source,yaml]
1311
--------------------------------------------------
1412
node.name: prod-data-2
1513
--------------------------------------------------
16-
17-
The `node.name` can also be set to the server's HOSTNAME as follows:
18-
19-
[source,yaml]
20-
--------------------------------------------------
21-
node.name: ${HOSTNAME}
22-
--------------------------------------------------

docs/reference/setup/logging-config.asciidoc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
Elasticsearch uses https://logging.apache.org/log4j/2.x/[Log4j 2] for
55
logging. Log4j 2 can be configured using the log4j2.properties
66
file. Elasticsearch exposes three properties, `${sys:es.logs.base_path}`,
7-
`${sys:es.logs.cluster_name}`, and `${sys:es.logs.node_name}` (if the node name
8-
is explicitly set via `node.name`) that can be referenced in the configuration
9-
file to determine the location of the log files. The property
10-
`${sys:es.logs.base_path}` will resolve to the log directory,
7+
`${sys:es.logs.cluster_name}`, and `${sys:es.logs.node_name}` that can be
8+
referenced in the configuration file to determine the location of the log
9+
files. The property `${sys:es.logs.base_path}` will resolve to the log directory,
1110
`${sys:es.logs.cluster_name}` will resolve to the cluster name (used as the
1211
prefix of log filenames in the default configuration), and
1312
`${sys:es.logs.node_name}` will resolve to the node name (if the node name is

qa/evil-tests/src/test/java/org/elasticsearch/common/logging/EvilLoggerTests.java

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -340,26 +340,22 @@ public void testPrefixLoggerMarkersCanBeCollected() throws IOException, UserExce
340340
}
341341

342342
public void testProperties() throws IOException, UserException {
343-
final Settings.Builder builder = Settings.builder().put("cluster.name", randomAlphaOfLength(16));
344-
if (randomBoolean()) {
345-
builder.put("node.name", randomAlphaOfLength(16));
346-
}
347-
final Settings settings = builder.build();
343+
final Settings settings = Settings.builder()
344+
.put("cluster.name", randomAlphaOfLength(16))
345+
.put("node.name", randomAlphaOfLength(16))
346+
.build();
348347
setupLogging("minimal", settings);
349348

350349
assertNotNull(System.getProperty("es.logs.base_path"));
351350

352351
assertThat(System.getProperty("es.logs.cluster_name"), equalTo(ClusterName.CLUSTER_NAME_SETTING.get(settings).value()));
353-
if (Node.NODE_NAME_SETTING.exists(settings)) {
354-
assertThat(System.getProperty("es.logs.node_name"), equalTo(Node.NODE_NAME_SETTING.get(settings)));
355-
} else {
356-
assertNull(System.getProperty("es.logs.node_name"));
357-
}
352+
assertThat(System.getProperty("es.logs.node_name"), equalTo(Node.NODE_NAME_SETTING.get(settings)));
358353
}
359354

360355
public void testNoNodeNameInPatternWarning() throws IOException, UserException {
356+
String nodeName = randomAlphaOfLength(16);
357+
LogConfigurator.setNodeName(nodeName);
361358
setupLogging("no_node_name");
362-
363359
final String path =
364360
System.getProperty("es.logs.base_path") +
365361
System.getProperty("file.separator") +
@@ -368,10 +364,10 @@ public void testNoNodeNameInPatternWarning() throws IOException, UserException {
368364
assertThat(events.size(), equalTo(2));
369365
final String location = "org.elasticsearch.common.logging.LogConfigurator";
370366
// the first message is a warning for unsupported configuration files
371-
assertLogLine(events.get(0), Level.WARN, location, "\\[unknown\\] Some logging configurations have %marker but don't "
372-
+ "have %node_name. We will automatically add %node_name to the pattern to ease the migration for users "
373-
+ "who customize log4j2.properties but will stop this behavior in 7.0. You should manually replace "
374-
+ "`%node_name` with `\\[%node_name\\]%marker ` in these locations:");
367+
assertLogLine(events.get(0), Level.WARN, location, "\\[" + nodeName + "\\] Some logging configurations have "
368+
+ "%marker but don't have %node_name. We will automatically add %node_name to the pattern to ease the "
369+
+ "migration for users who customize log4j2.properties but will stop this behavior in 7.0. You should "
370+
+ "manually replace `%node_name` with `\\[%node_name\\]%marker ` in these locations:");
375371
if (Constants.WINDOWS) {
376372
assertThat(events.get(1), endsWith("no_node_name\\log4j2.properties"));
377373
} else {

qa/evil-tests/src/test/java/org/elasticsearch/env/NodeEnvironmentEvilTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void testMissingWritePermission() throws IOException {
5252
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
5353
.putList(Environment.PATH_DATA_SETTING.getKey(), tempPaths).build();
5454
IOException ioException = expectThrows(IOException.class, () -> {
55-
new NodeEnvironment(build, TestEnvironment.newEnvironment(build), nodeId -> {});
55+
new NodeEnvironment(build, TestEnvironment.newEnvironment(build));
5656
});
5757
assertTrue(ioException.getMessage(), ioException.getMessage().startsWith(path.toString()));
5858
}
@@ -72,7 +72,7 @@ public void testMissingWritePermissionOnIndex() throws IOException {
7272
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
7373
.putList(Environment.PATH_DATA_SETTING.getKey(), tempPaths).build();
7474
IOException ioException = expectThrows(IOException.class, () -> {
75-
new NodeEnvironment(build, TestEnvironment.newEnvironment(build), nodeId -> {});
75+
new NodeEnvironment(build, TestEnvironment.newEnvironment(build));
7676
});
7777
assertTrue(ioException.getMessage(), ioException.getMessage().startsWith("failed to test writes in data directory"));
7878
}
@@ -97,7 +97,7 @@ public void testMissingWritePermissionOnShard() throws IOException {
9797
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toAbsolutePath().toString())
9898
.putList(Environment.PATH_DATA_SETTING.getKey(), tempPaths).build();
9999
IOException ioException = expectThrows(IOException.class, () -> {
100-
new NodeEnvironment(build, TestEnvironment.newEnvironment(build), nodeId -> {});
100+
new NodeEnvironment(build, TestEnvironment.newEnvironment(build));
101101
});
102102
assertTrue(ioException.getMessage(), ioException.getMessage().startsWith("failed to test writes in data directory"));
103103
}

qa/unconfigured-node-name/src/test/java/org/elasticsearch/unconfigured_node_name/NodeNameInLogsIT.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
package org.elasticsearch.unconfigured_node_name;
2121

22-
import org.elasticsearch.bootstrap.BootstrapInfo;
2322
import org.elasticsearch.common.logging.NodeNameInLogsIntegTestCase;
23+
import org.hamcrest.Matcher;
2424

2525
import java.io.IOException;
2626
import java.io.BufferedReader;
@@ -30,11 +30,16 @@
3030
import java.security.AccessController;
3131
import java.security.PrivilegedAction;
3232

33+
import static org.hamcrest.Matchers.not;
34+
3335
public class NodeNameInLogsIT extends NodeNameInLogsIntegTestCase {
3436
@Override
35-
protected BufferedReader openReader(Path logFile) throws IOException {
36-
assumeTrue("We log a line without the node name if we can't install the seccomp filters",
37-
BootstrapInfo.isSystemCallFilterInstalled());
37+
protected Matcher<String> nodeNameMatcher() {
38+
return not("");
39+
}
40+
41+
@Override
42+
protected BufferedReader openReader(Path logFile) {
3843
return AccessController.doPrivileged((PrivilegedAction<BufferedReader>) () -> {
3944
try {
4045
return Files.newBufferedReader(logFile, StandardCharsets.UTF_8);
@@ -43,11 +48,4 @@ protected BufferedReader openReader(Path logFile) throws IOException {
4348
}
4449
});
4550
}
46-
47-
public void testDummy() {
48-
/* Dummy test case so that when we run this test on a platform that
49-
* does not support our syscall filters and we skip the test above
50-
* we don't fail the entire test run because we skipped all the tests.
51-
*/
52-
}
5351
}

0 commit comments

Comments
 (0)