From 8dd44b4c6e9ad503a8d732924d50fc78e7424cdb Mon Sep 17 00:00:00 2001 From: smasa90 Date: Thu, 27 Jun 2019 16:37:37 +1100 Subject: [PATCH] fix(compat): bare min. to get srv running on 7.x Fixed jvm.options.erb to add required jvm options for 7.x Fixed jvm.options.erb to change jvm options required only for openjdk 8 Added ES_PATH_DIR instance environment var Fixed log4j2.properties.erb to fix Deprecation WARNINGS Keeped Backward Compatibility --- manifests/instance.pp | 7 +++++ .../005_elasticsearch_instance_spec.rb | 29 ++++++++++--------- templates/etc/elasticsearch/jvm.options.erb | 27 ++++++++++++----- .../etc/elasticsearch/log4j2.properties.erb | 13 +++++---- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/manifests/instance.pp b/manifests/instance.pp index 813136f81..93b63a8f0 100644 --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -190,6 +190,12 @@ false => undef, } + # Private var used by jvm.options.erb and log4j.properties.erb + $_is_7_min = ( $::elasticsearch::version =~ String + and versioncmp($::elasticsearch::version, '7.0.0') >= 0 + ) or ( defined('$::elastic_stack::repo::version') + and versioncmp(String($::elastic_stack::repo::version), '7') >= 0 ) + if ($ensure == 'present') { # Configuration hash @@ -461,6 +467,7 @@ $elasticsearch::init_defaults, { 'CONF_DIR' => $configdir, + 'ES_PATH_DIR' => $configdir, 'ES_HOME' => $elasticsearch::homedir, 'ES_JVM_OPTIONS' => "${configdir}/jvm.options", 'ES_PATH_CONF' => $configdir, diff --git a/spec/defines/005_elasticsearch_instance_spec.rb b/spec/defines/005_elasticsearch_instance_spec.rb index 57a1d93c6..679625cb1 100644 --- a/spec/defines/005_elasticsearch_instance_spec.rb +++ b/spec/defines/005_elasticsearch_instance_spec.rb @@ -85,6 +85,7 @@ "elasticsearch/etc/init.d/elasticsearch.#{initscript}.erb", :init_defaults => { 'CONF_DIR' => '/etc/elasticsearch/es-instance', + 'ES_PATH_DIR' => '/etc/elasticsearch/es-instance', 'ES_PATH_CONF' => '/etc/elasticsearch/es-instance', 'DATA_DIR' => '/var/lib/elasticsearch', 'ES_JVM_OPTIONS' => '/etc/elasticsearch/es-instance/jvm.options', @@ -799,21 +800,21 @@ class { 'elasticsearch': -Dlog4j2.disable.jmx=true. -XX:\+AlwaysPreTouch. -XX:\+HeapDumpOnOutOfMemoryError. - -XX:\+PrintGCDateStamps. - -XX:\+PrintGCDetails. - -XX:\+PrintTenuringDistribution. -XX:\+UseCMSInitiatingOccupancyOnly. -XX:\+UseConcMarkSweepGC. - -XX:\+UseGCLogFileRotation. -XX:-OmitStackTraceInFastThrow. -XX:CMSInitiatingOccupancyFraction=75. - -XX:GCLogFileSize=64m. - -XX:NumberOfGCLogFiles=32. - -Xloggc:\/var\/log\/elasticsearch\/es-instance\/gc.log. -Xms4g. -Xmx4g. -Xss1m. -server. + 8:-XX:\+PrintGCDateStamps. + 8:-XX:\+PrintGCDetails. + 8:-XX:\+PrintTenuringDistribution. + 8:-XX:\+UseGCLogFileRotation. + 8:-XX:GCLogFileSize=64m. + 8:-XX:NumberOfGCLogFiles=32. + 8:-Xloggc:\/var\/log\/elasticsearch\/es-instance\/gc.log. }xm) end end @@ -841,21 +842,21 @@ class { 'elasticsearch': -Dlog4j2.disable.jmx=true. -XX:\+AlwaysPreTouch. -XX:\+HeapDumpOnOutOfMemoryError. - -XX:\+PrintGCDateStamps. - -XX:\+PrintGCDetails. - -XX:\+PrintTenuringDistribution. -XX:\+UseCMSInitiatingOccupancyOnly. -XX:\+UseConcMarkSweepGC. - -XX:\+UseGCLogFileRotation. -XX:-OmitStackTraceInFastThrow. -XX:CMSInitiatingOccupancyFraction=75. - -XX:GCLogFileSize=64m. - -XX:NumberOfGCLogFiles=32. - -Xloggc:\/var\/log\/elasticsearch\/es-instance\/gc.log. -Xms8g. -Xmx8g. -Xss1m. -server. + 8:-XX:\+PrintGCDateStamps. + 8:-XX:\+PrintGCDetails. + 8:-XX:\+PrintTenuringDistribution. + 8:-XX:\+UseGCLogFileRotation. + 8:-XX:GCLogFileSize=64m. + 8:-XX:NumberOfGCLogFiles=32. + 8:-Xloggc:\/var\/log\/elasticsearch\/es-instance\/gc.log. }xm) end end diff --git a/templates/etc/elasticsearch/jvm.options.erb b/templates/etc/elasticsearch/jvm.options.erb index c9b0dded9..d50625216 100644 --- a/templates/etc/elasticsearch/jvm.options.erb +++ b/templates/etc/elasticsearch/jvm.options.erb @@ -25,14 +25,27 @@ defaults = { '-Dlog4j.shutdownHookEnabled' => '-Dlog4j.shutdownHookEnabled=false', '-Dlog4j2.disable.jmx' => '-Dlog4j2.disable.jmx=true', 'HeapDumpOnOutOfMemoryError' => '-XX:+HeapDumpOnOutOfMemoryError', - 'PrintGCDetails' => '-XX:+PrintGCDetails', - 'PrintGCDateStamps' => '-XX:+PrintGCDateStamps', - 'PrintTenuringDistribution' => '-XX:+PrintTenuringDistribution', - 'Xloggc' => "-Xloggc:#{@logdir}/gc.log", - 'UseGCLogFileRotation' => '-XX:+UseGCLogFileRotation', - 'NumberOfGCLogFiles' => '-XX:NumberOfGCLogFiles=32', - 'GCLogFileSize' => '-XX:GCLogFileSize=64m', + 'PrintGCDetails' => '8:-XX:+PrintGCDetails', + 'PrintGCDateStamps' => '8:-XX:+PrintGCDateStamps', + 'PrintTenuringDistribution' => '8:-XX:+PrintTenuringDistribution', + 'Xloggc' => "8:-Xloggc:#{@logdir}/gc.log", + 'UseGCLogFileRotation' => '8:-XX:+UseGCLogFileRotation', + 'NumberOfGCLogFiles' => '8:-XX:NumberOfGCLogFiles=32', + 'GCLogFileSize' => '8:-XX:GCLogFileSize=64m', } +defaults_7x = { + '-Des.networkaddress.cache.ttl' => '-Des.networkaddress.cache.ttl=60', + '-Des.networkaddress.cache.negative.ttl' => '-Des.networkaddress.cache.negative.ttl=10', + '-Djava.io.tmpdir' => '-Djava.io.tmpdir=${ES_TMPDIR}', + 'HeapDumpPath' => '-XX:HeapDumpPath=/var/lib/elasticsearch', + 'ErrorFile' => "-XX:ErrorFile=#{@logdir}/hs_err_pid%p.log", + 'PrintGCApplicationStoppedTime' => '8:-XX:+PrintGCApplicationStoppedTime', + 'Xlog' => "9-:-Xlog:gc*,gc+age=trace,safepoint:file=#{@logdir}/gc.log:utctime,pid,tags:filecount=32,filesize=64m", + '-Djava.locale.providers' => '9-:-Djava.locale.providers=COMPAT', +} + +if @_is_7_min then defaults.merge!( defaults_7x ) end + defaults.each {|k,v| set_default(@jvm_options, k, v)} -%> diff --git a/templates/etc/elasticsearch/log4j2.properties.erb b/templates/etc/elasticsearch/log4j2.properties.erb index 4e4d831f7..df2211033 100644 --- a/templates/etc/elasticsearch/log4j2.properties.erb +++ b/templates/etc/elasticsearch/log4j2.properties.erb @@ -1,3 +1,4 @@ +<%- @node_marker = @_is_7_min ? '[%node_name]%marker' : '%marker' -%> status = <%= @logging_level.downcase %> # log action execution errors for easier debugging @@ -7,20 +8,20 @@ logger.action.level = debug appender.console.type = Console appender.console.name = console appender.console.layout.type = PatternLayout -appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n +appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] <%= @node_marker %>%m%n <%- if @file_rolling_type == 'file' -%> appender.fixed.type = File appender.fixed.name = fixed appender.fixed.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log appender.fixed.layout.type = PatternLayout -appender.fixed.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.-10000m%n +appender.fixed.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] <%= @node_marker %>%.-10000m%n <%- else -%> appender.rolling.type = RollingFile appender.rolling.name = rolling appender.rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}.log appender.rolling.layout.type = PatternLayout -appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.-10000m%n +appender.rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] <%= @node_marker %>%.-10000m%n <%- if @file_rolling_type == 'dailyRollingFile' -%> appender.rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}-%d{yyyy-MM-dd}-%i.log.gz appender.rolling.policies.type = Policies @@ -49,7 +50,7 @@ appender.deprecation_rolling.type = RollingFile appender.deprecation_rolling.name = deprecation_rolling appender.deprecation_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.log appender.deprecation_rolling.layout.type = PatternLayout -appender.deprecation_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%.-10000m%n +appender.deprecation_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] <%= @node_marker %>%.-10000m%n appender.deprecation_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation-%i.log.gz appender.deprecation_rolling.policies.type = Policies appender.deprecation_rolling.policies.size.type = SizeBasedTriggeringPolicy @@ -70,7 +71,7 @@ appender.index_search_slowlog_rolling.type = RollingFile appender.index_search_slowlog_rolling.name = index_search_slowlog_rolling appender.index_search_slowlog_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_search_slowlog.log appender.index_search_slowlog_rolling.layout.type = PatternLayout -appender.index_search_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%.-10000m%n +appender.index_search_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] <%= @node_marker %>%.-10000m%n appender.index_search_slowlog_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_search_slowlog-%d{yyyy-MM-dd}.log appender.index_search_slowlog_rolling.policies.type = Policies appender.index_search_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy @@ -86,7 +87,7 @@ appender.index_indexing_slowlog_rolling.type = RollingFile appender.index_indexing_slowlog_rolling.name = index_indexing_slowlog_rolling appender.index_indexing_slowlog_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_indexing_slowlog.log appender.index_indexing_slowlog_rolling.layout.type = PatternLayout -appender.index_indexing_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] %marker%.-10000m%n +appender.index_indexing_slowlog_rolling.layout.pattern = [%d{ISO8601}][%-5p][%-25c] <%= @node_marker %>%.-10000m%n appender.index_indexing_slowlog_rolling.filePattern = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_index_indexing_slowlog-%d{yyyy-MM-dd}.log appender.index_indexing_slowlog_rolling.policies.type = Policies appender.index_indexing_slowlog_rolling.policies.time.type = TimeBasedTriggeringPolicy