Skip to content

Commit 75a8e0b

Browse files
committed
Enable GC logs by default
For too long we have been groping around in the dark when faced with GC issues because we rarely have GC logs at our disposal. This commit enables GC logging by default out of the box. Relates #27610
1 parent 6ae3afc commit 75a8e0b

File tree

12 files changed

+60
-21
lines changed

12 files changed

+60
-21
lines changed

distribution/build.gradle

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,11 @@ configure(distributions) {
224224
configure(distributions.findAll { ['zip', 'tar', 'integ-test-zip'].contains(it.name) }) {
225225
// CopySpec does not make it easy to create an empty director so we create the directory that we want, and then point CopySpec to its
226226
// parent to copy to the root of the distribution
227+
File logs = new File(buildDir, 'logs-hack/logs')
228+
task createLogDir(type: EmptyDirTask) {
229+
dir "${logs}"
230+
dirMode 0755
231+
}
227232
File plugins = new File(buildDir, 'plugins-hack/plugins')
228233
task createPluginsDir(type: EmptyDirTask) {
229234
dir "${plugins}"
@@ -247,6 +252,12 @@ configure(distributions.findAll { ['zip', 'tar', 'integ-test-zip'].contains(it.n
247252
MavenFilteringHack.filter(it, expansions)
248253
}
249254
}
255+
into('') {
256+
from {
257+
dirMode 0755
258+
logs.getParent()
259+
}
260+
}
250261
into('') {
251262
from {
252263
dirMode 0755
@@ -497,7 +508,9 @@ task run(type: RunTask) {
497508
Map<String, String> expansionsForDistribution(distributionType) {
498509
final String defaultHeapSize = "1g"
499510
final String packagingPathData = "path.data: /var/lib/elasticsearch"
500-
final String packagingPathLogs = "path.logs: /var/log/elasticsearch"
511+
final String pathLogs = "/var/log/elasticsearch"
512+
final String packagingPathLogs = "path.logs: ${pathLogs}"
513+
final String packagingLoggc = "${pathLogs}/gc.log"
501514

502515
String footer = "# Built for ${project.name}-${project.version} " +
503516
"(${distributionType})"
@@ -533,6 +546,11 @@ Map<String, String> expansionsForDistribution(distributionType) {
533546
'rpm': packagingPathLogs,
534547
'def': '#path.logs: /path/to/logs'
535548
],
549+
'loggc': [
550+
'deb': packagingLoggc,
551+
'rpm': packagingLoggc,
552+
'def': 'logs/gc.log'
553+
],
536554

537555
'heap.min': defaultHeapSize,
538556
'heap.max': defaultHeapSize,

distribution/integ-test-zip/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import org.elasticsearch.gradle.plugin.PluginBuildPlugin
2121
import org.apache.tools.ant.taskdefs.condition.Os
2222

2323
task buildZip(type: Zip) {
24-
dependsOn createPluginsDir
24+
dependsOn createLogDir, createPluginsDir
2525
baseName = 'elasticsearch'
2626
with archivesFiles
2727
}

distribution/src/main/resources/bin/elasticsearch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ ES_JVM_OPTIONS="$ES_PATH_CONF"/jvm.options
2727
JVM_OPTIONS=`parse_jvm_options "$ES_JVM_OPTIONS"`
2828
ES_JAVA_OPTS="${JVM_OPTIONS//\$\{ES_TMPDIR\}/$ES_TMPDIR} $ES_JAVA_OPTS"
2929

30+
cd "$ES_HOME"
3031
# manual parsing to find out, if process should be detached
3132
if ! echo $* | grep -E '(^-d |-d$| -d |--daemonize$|--daemonize )' > /dev/null; then
3233
exec \

distribution/src/main/resources/bin/elasticsearch.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ rem such options are the lines beginning with '-', thus "findstr /b"
4949
for /F "usebackq delims=" %%a in (`findstr /b \- "%ES_JVM_OPTIONS%"`) do set JVM_OPTIONS=!JVM_OPTIONS! %%a
5050
@endlocal & set ES_JAVA_OPTS=%JVM_OPTIONS:${ES_TMPDIR}=!ES_TMPDIR!% %ES_JAVA_OPTS%
5151

52+
cd "%ES_HOME%"
5253
%JAVA% %ES_JAVA_OPTS% -Delasticsearch -Des.path.home="%ES_HOME%" -Des.path.conf="%ES_PATH_CONF%" -cp "%ES_CLASSPATH%" "org.elasticsearch.bootstrap.Elasticsearch" !newparams!
5354

5455
endlocal

distribution/src/main/resources/config/jvm.options

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,20 +86,11 @@ ${heap.dump.path}
8686

8787
## GC logging
8888

89-
#-XX:+PrintGCDetails
90-
#-XX:+PrintGCTimeStamps
91-
#-XX:+PrintGCDateStamps
92-
#-XX:+PrintClassHistogram
93-
#-XX:+PrintTenuringDistribution
94-
#-XX:+PrintGCApplicationStoppedTime
95-
96-
# log GC status to a file with time stamps
97-
# ensure the directory exists
98-
#-Xloggc:${loggc}
99-
100-
# By default, the GC log file will not rotate.
101-
# By uncommenting the lines below, the GC log file
102-
# will be rotated every 128MB at most 32 times.
103-
#-XX:+UseGCLogFileRotation
104-
#-XX:NumberOfGCLogFiles=32
105-
#-XX:GCLogFileSize=128M
89+
-XX:+PrintGCDetails
90+
-XX:+PrintGCDateStamps
91+
-XX:+PrintTenuringDistribution
92+
-XX:+PrintGCApplicationStoppedTime
93+
-Xloggc:${loggc}
94+
-XX:+UseGCLogFileRotation
95+
-XX:NumberOfGCLogFiles=32
96+
-XX:GCLogFileSize=64m

distribution/tar/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
task buildTar(type: Tar) {
21-
dependsOn createPluginsDir
21+
dependsOn createLogDir, createPluginsDir
2222
baseName = 'elasticsearch'
2323
extension = 'tar.gz'
2424
with archivesFiles

distribution/zip/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.elasticsearch.gradle.plugin.PluginBuildPlugin
2121

2222
task buildZip(type: Zip) {
23-
dependsOn createPluginsDir
23+
dependsOn createLogDir, createPluginsDir
2424
baseName = 'elasticsearch'
2525
with archivesFiles
2626
}

docs/reference/setup/important-settings.asciidoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,3 +201,12 @@ the Elasticsearch process. If you wish to configure a heap dump path, you should
201201
modify the entry `#-XX:HeapDumpPath=/heap/dump/path` in
202202
<<jvm-options,`jvm.options`>> to remove the comment marker `#` and to specify an
203203
actual path.
204+
205+
[float]
206+
[[gc-logging]]
207+
=== GC logging
208+
209+
By default, Elasticsearch enables GC logs. These are configured in
210+
<<jvm-options,`jvm.options`>> and default to the same default location as the
211+
Elasticsearch logs. The default configuration rotates the logs every 64 MB and
212+
can consume up to 2 GB of disk space.

qa/vagrant/src/test/resources/packaging/tests/20_tar_package.bats

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ setup() {
133133
export ES_JAVA_OPTS=$es_java_opts
134134
}
135135

136+
@test "[TAR] GC logs exist" {
137+
start_elasticsearch_service
138+
assert_file_exist $ESHOME/logs/gc.log.0.current
139+
stop_elasticsearch_service
140+
}
141+
136142
@test "[TAR] remove tar" {
137143
rm -rf "/tmp/elasticsearch"
138144
}

qa/vagrant/src/test/resources/packaging/tests/60_systemd.bats

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,9 @@ setup() {
246246
[ -d /var/run/elasticsearch ]
247247
systemctl stop elasticsearch.service
248248
}
249+
250+
@test "[SYSTEMD] GC logs exist" {
251+
start_elasticsearch_service
252+
assert_file_exist /var/log/elasticsearch/gc.log.0.current
253+
stop_elasticsearch_service
254+
}

0 commit comments

Comments
 (0)