-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Core: Default node.name to the hostname #33677
Changes from all commits
4dbcbef
605ce74
5efba9e
d240e66
ae00663
eb04e04
31707dc
81a0594
d2257d1
1384762
74618d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,13 @@ | ||
[[node.name]] | ||
=== `node.name` | ||
|
||
By default, Elasticsearch will use the first seven characters of the randomly | ||
generated UUID as the node id. Note that the node id is persisted and does | ||
not change when a node restarts and therefore the default node name will also | ||
not change. | ||
|
||
It is worth configuring a more meaningful name which will also have the | ||
advantage of persisting after restarting the node: | ||
Elasticsearch uses `node.name` as a human readable identifier for a | ||
particular instance of Elasticsearch so it is included in the response | ||
of many APIs. It defaults to the hostname that the machine has when | ||
Elasticsearch starts but can be configured explicitly in | ||
`elasticsearch.yml` as follows: | ||
|
||
[source,yaml] | ||
-------------------------------------------------- | ||
node.name: prod-data-2 | ||
-------------------------------------------------- | ||
|
||
The `node.name` can also be set to the server's HOSTNAME as follows: | ||
|
||
[source,yaml] | ||
-------------------------------------------------- | ||
node.name: ${HOSTNAME} | ||
-------------------------------------------------- |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -340,26 +340,22 @@ public void testPrefixLoggerMarkersCanBeCollected() throws IOException, UserExce | |
} | ||
|
||
public void testProperties() throws IOException, UserException { | ||
final Settings.Builder builder = Settings.builder().put("cluster.name", randomAlphaOfLength(16)); | ||
if (randomBoolean()) { | ||
builder.put("node.name", randomAlphaOfLength(16)); | ||
} | ||
final Settings settings = builder.build(); | ||
final Settings settings = Settings.builder() | ||
.put("cluster.name", randomAlphaOfLength(16)) | ||
.put("node.name", randomAlphaOfLength(16)) | ||
.build(); | ||
setupLogging("minimal", settings); | ||
|
||
assertNotNull(System.getProperty("es.logs.base_path")); | ||
|
||
assertThat(System.getProperty("es.logs.cluster_name"), equalTo(ClusterName.CLUSTER_NAME_SETTING.get(settings).value())); | ||
if (Node.NODE_NAME_SETTING.exists(settings)) { | ||
assertThat(System.getProperty("es.logs.node_name"), equalTo(Node.NODE_NAME_SETTING.get(settings))); | ||
} else { | ||
assertNull(System.getProperty("es.logs.node_name")); | ||
} | ||
assertThat(System.getProperty("es.logs.node_name"), equalTo(Node.NODE_NAME_SETTING.get(settings))); | ||
} | ||
|
||
public void testNoNodeNameInPatternWarning() throws IOException, UserException { | ||
String nodeName = randomAlphaOfLength(16); | ||
LogConfigurator.setNodeName(nodeName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we automatically add a node name to the pattern we need to configure one or else the NodeNamePatternConverter will refuse to be built. |
||
setupLogging("no_node_name"); | ||
|
||
final String path = | ||
System.getProperty("es.logs.base_path") + | ||
System.getProperty("file.separator") + | ||
|
@@ -368,10 +364,10 @@ public void testNoNodeNameInPatternWarning() throws IOException, UserException { | |
assertThat(events.size(), equalTo(2)); | ||
final String location = "org.elasticsearch.common.logging.LogConfigurator"; | ||
// the first message is a warning for unsupported configuration files | ||
assertLogLine(events.get(0), Level.WARN, location, "\\[unknown\\] Some logging configurations have %marker but don't " | ||
+ "have %node_name. We will automatically add %node_name to the pattern to ease the migration for users " | ||
+ "who customize log4j2.properties but will stop this behavior in 7.0. You should manually replace " | ||
+ "`%node_name` with `\\[%node_name\\]%marker ` in these locations:"); | ||
assertLogLine(events.get(0), Level.WARN, location, "\\[" + nodeName + "\\] Some logging configurations have " | ||
+ "%marker but don't have %node_name. We will automatically add %node_name to the pattern to ease the " | ||
+ "migration for users who customize log4j2.properties but will stop this behavior in 7.0. You should " | ||
+ "manually replace `%node_name` with `\\[%node_name\\]%marker ` in these locations:"); | ||
if (Constants.WINDOWS) { | ||
assertThat(events.get(1), endsWith("no_node_name\\log4j2.properties")); | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,8 @@ | |
|
||
package org.elasticsearch.unconfigured_node_name; | ||
|
||
import org.elasticsearch.bootstrap.BootstrapInfo; | ||
import org.elasticsearch.common.logging.NodeNameInLogsIntegTestCase; | ||
import org.hamcrest.Matcher; | ||
|
||
import java.io.IOException; | ||
import java.io.BufferedReader; | ||
|
@@ -30,11 +30,16 @@ | |
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
import static org.hamcrest.Matchers.not; | ||
|
||
public class NodeNameInLogsIT extends NodeNameInLogsIntegTestCase { | ||
@Override | ||
protected BufferedReader openReader(Path logFile) throws IOException { | ||
assumeTrue("We log a line without the node name if we can't install the seccomp filters", | ||
BootstrapInfo.isSystemCallFilterInstalled()); | ||
protected Matcher<String> nodeNameMatcher() { | ||
return not(""); | ||
} | ||
|
||
@Override | ||
protected BufferedReader openReader(Path logFile) { | ||
return AccessController.doPrivileged((PrivilegedAction<BufferedReader>) () -> { | ||
try { | ||
return Files.newBufferedReader(logFile, StandardCharsets.UTF_8); | ||
|
@@ -43,11 +48,4 @@ protected BufferedReader openReader(Path logFile) throws IOException { | |
} | ||
}); | ||
} | ||
|
||
public void testDummy() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm glad to remove this! |
||
/* Dummy test case so that when we run this test on a platform that | ||
* does not support our syscall filters and we skip the test above | ||
* we don't fail the entire test run because we skipped all the tests. | ||
*/ | ||
} | ||
} |
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.
node.name
is always available at this point in the course of normal operation.