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

Move docker cgroup override to SystemJvmOptions #85960

Merged
merged 1 commit into from
Apr 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion distribution/src/bin/elasticsearch
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fi
# - second, JVM options are read from jvm.options and jvm.options.d/*.options
# - third, JVM options from ES_JAVA_OPTS are applied
# - fourth, ergonomic JVM options are applied
ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" -cp "$LAUNCHERS_CLASSPATH" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF" "$ES_HOME/plugins"`
ES_JAVA_OPTS=`export ES_TMPDIR; "$JAVA" -cp "$LAUNCHERS_CLASSPATH" -Des.distribution.type="$ES_DISTRIBUTION_TYPE" org.elasticsearch.tools.launchers.JvmOptionsParser "$ES_PATH_CONF" "$ES_HOME/plugins"`

# Remove enrollment related parameters before passing the arg list to Elasticsearch
for i in "${!ARG_LIST[@]}"; do
Expand Down
17 changes: 0 additions & 17 deletions distribution/src/bin/elasticsearch-env
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,4 @@ ES_PATH_CONF=`cd "$ES_PATH_CONF"; pwd`

[email protected]@

if [[ "$ES_DISTRIBUTION_TYPE" == "docker" ]]; then

# The virtual file /proc/self/cgroup should list the current cgroup
# membership. For each hierarchy, you can follow the cgroup path from
# this file to the cgroup filesystem (usually /sys/fs/cgroup/) and
# introspect the statistics for the cgroup for the given
# hierarchy. Alas, Docker breaks this by mounting the container
# statistics at the root while leaving the cgroup paths as the actual
# paths. Therefore, Elasticsearch provides a mechanism to override
# reading the cgroup path from /proc/self/cgroup and instead uses the
# cgroup path defined the JVM system property
# es.cgroups.hierarchy.override. Therefore, we set this value here so
# that cgroup statistics are available for the container this process
# will run in.
export ES_JAVA_OPTS="-Des.cgroups.hierarchy.override=/ $ES_JAVA_OPTS"
fi

cd "$ES_HOME"
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,29 @@ static List<String> systemJvmOptions() {
*
* TODO: either modularlize Elasticsearch so that we can limit the opening of this module, or find an alternative
*/
"--add-opens=java.base/java.io=ALL-UNNAMED"
"--add-opens=java.base/java.io=ALL-UNNAMED",
maybeOverrideDockerCgroup()
).stream().filter(e -> e.isEmpty() == false).collect(Collectors.toList());
}

/*
* The virtual file /proc/self/cgroup should list the current cgroup
* membership. For each hierarchy, you can follow the cgroup path from
* this file to the cgroup filesystem (usually /sys/fs/cgroup/) and
* introspect the statistics for the cgroup for the given
* hierarchy. Alas, Docker breaks this by mounting the container
* statistics at the root while leaving the cgroup paths as the actual
* paths. Therefore, Elasticsearch provides a mechanism to override
* reading the cgroup path from /proc/self/cgroup and instead uses the
* cgroup path defined the JVM system property
* es.cgroups.hierarchy.override. Therefore, we set this value here so
* that cgroup statistics are available for the container this process
* will run in.
*/
private static String maybeOverrideDockerCgroup() {
if ("docker".equals(System.getProperty("es.distribution.type"))) {
return "-Des.cgroups.hierarchy.override=/";
}
return "";
}
}