From 6ef2a7297f1fe8cfb48082222fe1962de00f16ae Mon Sep 17 00:00:00 2001
From: Vincent SELLIER <vincent.sellier@softwareheritage.org>
Date: Wed, 10 Nov 2021 12:11:16 +0100
Subject: [PATCH] elk: upgrade elasticsearch and kibana nodes

This diff must be applied node per node to avoid a downtime
- each esnode one by one (with shard allocation management)
- kibana

The xpack.security.enabled property is set to false to avoid
a recurring alert popup in grafana.

Fix the upgrade of the prometheus exporter plugin

Related to T3705
---
 data/common/common.yaml                          |  2 ++
 data/deployments/production/common.yaml          |  4 ----
 .../esnode1.internal.softwareheritage.org.yaml   |  4 ++++
 .../esnode2.internal.softwareheritage.org.yaml   |  4 ++++
 .../esnode3.internal.softwareheritage.org.yaml   |  4 ++++
 .../kibana0.internal.softwareheritage.org.yaml   |  1 +
 site-modules/profile/manifests/kibana.pp         |  2 +-
 .../manifests/prometheus/elasticsearch.pp        | 16 +++++++++++-----
 8 files changed, 27 insertions(+), 10 deletions(-)
 create mode 100644 data/hostname/kibana0.internal.softwareheritage.org.yaml

diff --git a/data/common/common.yaml b/data/common/common.yaml
index 155c96ec8..2c36a2c60 100644
--- a/data/common/common.yaml
+++ b/data/common/common.yaml
@@ -3276,6 +3276,8 @@ elasticsearch::config:
   path.logs: "%{alias('elasticsearch::config::path::logs')}"
   http.port: "%{alias('elasticsearch::config::http::port')}"
   prometheus.indices: "%{alias('elasticsearch::config::prometheus::indices')}"
+  indices.memory.index_buffer_size: 50%
+  index.store.type: hybridfs
 
 logstash::listen_network: "%{lookup('internal_network')}"
 logstash::elasticsearch::hosts: "%{alias('elasticsearch::hosts')}"
diff --git a/data/deployments/production/common.yaml b/data/deployments/production/common.yaml
index b559a4a02..4e42e3fcf 100644
--- a/data/deployments/production/common.yaml
+++ b/data/deployments/production/common.yaml
@@ -11,10 +11,6 @@ elasticsearch::config::cluster::initial_master_nodes:
   - esnode2
   - esnode3
 
-elasticsearch::config::extras:
-  indices.memory.index_buffer_size: 50%
-  index.store.type: hybridfs
-
 elasticsearch::jvm_options::heap_size: 16g
 
 swh::postgresql::shared_buffers: 4GB
diff --git a/data/hostname/esnode1.internal.softwareheritage.org.yaml b/data/hostname/esnode1.internal.softwareheritage.org.yaml
index 8fc078d8d..82bde7ba9 100644
--- a/data/hostname/esnode1.internal.softwareheritage.org.yaml
+++ b/data/hostname/esnode1.internal.softwareheritage.org.yaml
@@ -10,3 +10,7 @@ swh::apt_config::backported_packages:
     - zfs-dkms
     - zfsutils-linux
     - zfs-zed
+
+elastic::elk_version: '7.15.2'
+elasticsearch::config::extras:
+  xpack.security.enabled: false
diff --git a/data/hostname/esnode2.internal.softwareheritage.org.yaml b/data/hostname/esnode2.internal.softwareheritage.org.yaml
index 8fc078d8d..82bde7ba9 100644
--- a/data/hostname/esnode2.internal.softwareheritage.org.yaml
+++ b/data/hostname/esnode2.internal.softwareheritage.org.yaml
@@ -10,3 +10,7 @@ swh::apt_config::backported_packages:
     - zfs-dkms
     - zfsutils-linux
     - zfs-zed
+
+elastic::elk_version: '7.15.2'
+elasticsearch::config::extras:
+  xpack.security.enabled: false
diff --git a/data/hostname/esnode3.internal.softwareheritage.org.yaml b/data/hostname/esnode3.internal.softwareheritage.org.yaml
index 8fc078d8d..82bde7ba9 100644
--- a/data/hostname/esnode3.internal.softwareheritage.org.yaml
+++ b/data/hostname/esnode3.internal.softwareheritage.org.yaml
@@ -10,3 +10,7 @@ swh::apt_config::backported_packages:
     - zfs-dkms
     - zfsutils-linux
     - zfs-zed
+
+elastic::elk_version: '7.15.2'
+elasticsearch::config::extras:
+  xpack.security.enabled: false
diff --git a/data/hostname/kibana0.internal.softwareheritage.org.yaml b/data/hostname/kibana0.internal.softwareheritage.org.yaml
new file mode 100644
index 000000000..744aefcfa
--- /dev/null
+++ b/data/hostname/kibana0.internal.softwareheritage.org.yaml
@@ -0,0 +1 @@
+elastic::elk_version: '7.15.2'
diff --git a/site-modules/profile/manifests/kibana.pp b/site-modules/profile/manifests/kibana.pp
index c6a7b9fc0..fa344b409 100644
--- a/site-modules/profile/manifests/kibana.pp
+++ b/site-modules/profile/manifests/kibana.pp
@@ -9,7 +9,7 @@ class profile::kibana {
 
   apt::pin { 'kibana':
     packages => 'kibana',
-    version => $version,
+    version  => $version,
     priority => 1001,
   }
 
diff --git a/site-modules/profile/manifests/prometheus/elasticsearch.pp b/site-modules/profile/manifests/prometheus/elasticsearch.pp
index c17e4c5ad..d10d0dca0 100644
--- a/site-modules/profile/manifests/prometheus/elasticsearch.pp
+++ b/site-modules/profile/manifests/prometheus/elasticsearch.pp
@@ -6,9 +6,12 @@ class profile::prometheus::elasticsearch {
   $version = lookup('prometheus::elasticsearch::exporter::version')
 
   $archive_url = "https://github.com/vvanholl/elasticsearch-prometheus-exporter/releases/download/${version}/prometheus-exporter-${version}.zip"
-  $archive_path = '/usr/share/elasticsearch/plugins/prometheus-exporter'
+  $plugin_path = '/usr/share/elasticsearch/plugins/prometheus-exporter'
 
-  file { $archive_path:
+  exec {'cleanup prometheus exporter plugin':
+    creates => "${plugin_path}/prometheus-exporter-${version}.jar",
+    command => "/usr/bin/rm -rf ${plugin_path}",
+  } -> file { $plugin_path:
     ensure  => directory,
     owner   => 'elasticsearch',
     group   => 'elasticsearch',
@@ -19,13 +22,16 @@ class profile::prometheus::elasticsearch {
     path         => "/tmp/prometheus-exporter-${version}.zip",
     source       => $archive_url,
     extract      => true,
-    extract_path => '/usr/share/elasticsearch/plugins/prometheus-exporter',
-    creates      => "${archive_path}/plugin-descriptor.properties",
+    extract_path => $plugin_path,
+    creates      => "${plugin_path}/prometheus-exporter-${version}.jar",
     cleanup      => true,
     user         => 'root',
     group        => 'root',
-    require      => Package['elasticsearch'],
+    require      => [
+      Package['elasticsearch'],
+    ],
   }
 
+
   Archive['prometheus-elasticsearch-exporter'] ~> Service['elasticsearch']
 }
-- 
GitLab