From 79b59e2c0b43936a12a9c676d8a48cd62c733a0f Mon Sep 17 00:00:00 2001
From: Isaac Prior <isaac@stackhpc.com>
Date: Thu, 24 Jun 2021 14:12:48 +0100
Subject: [PATCH] Fix log rotation for fluentd created files

Overrides default fluentd buffer config to stop log files from using
datestamped filenames, allowing logrotate to manage them.

Closes-Bug: #1940118
Change-Id: I40c4e209470d21e0a02fd447fb628acfdae9fa9d
---
 .../templates/conf/output/00-local.conf.j2    | 53 +++++++++++--------
 .../templates/cron-logrotate-haproxy.conf.j2  |  2 +-
 ...ix-haproxy-logrotate-e299a0000728fd8f.yaml | 12 +++++
 3 files changed, 44 insertions(+), 23 deletions(-)
 create mode 100644 releasenotes/notes/fix-haproxy-logrotate-e299a0000728fd8f.yaml

diff --git a/ansible/roles/common/templates/conf/output/00-local.conf.j2 b/ansible/roles/common/templates/conf/output/00-local.conf.j2
index ba46b519b..4b8067e0d 100644
--- a/ansible/roles/common/templates/conf/output/00-local.conf.j2
+++ b/ansible/roles/common/templates/conf/output/00-local.conf.j2
@@ -3,11 +3,11 @@
   @type copy
   <store>
     @type file
-    path /var/log/kolla/swift/swift_latest.*.log
+    path /var/log/kolla/swift/swift_latest
     append true
-    compress gzip
-    <buffer>
-      timekey_use_utc
+    # Disable timestamp in filename for logs
+    <buffer []>
+      path /var/log/kolla/swift/swift_latest.*.buffer
     </buffer>
   </store>
 {% if log_direct_to_elasticsearch %}
@@ -66,14 +66,17 @@
   @type copy
   <store>
     @type file
-    path /var/log/kolla/haproxy/haproxy_latest.*.log
-    output_tag false
-    output_time false
+    path /var/log/kolla/haproxy/haproxy_latest
     append true
-    compress gzip
-    <buffer>
-      timekey_use_utc
+    # Disable timestamp in filename for logs
+    <buffer []>
+      path /var/log/kolla/haproxy/haproxy_latest.*.buffer
     </buffer>
+    # Don't prepend syslog tag or timestamp to log output
+    <format>
+      output_tag false
+      output_time false
+    </format>
   </store>
 {% if log_direct_to_elasticsearch %}
   <store>
@@ -131,14 +134,17 @@
   @type copy
   <store>
     @type file
-    path /var/log/kolla/glance-tls-proxy/glance-tls-proxy.*.log
-    output_tag false
-    output_time false
+    path /var/log/kolla/glance-tls-proxy/glance-tls-proxy
     append true
-    compress gzip
-    <buffer>
-      timekey_use_utc
+    # Disable timestamp in filename for logs
+    <buffer []>
+      path /var/log/kolla/glance-tls-proxy/glance-tls-proxy.*.buffer
     </buffer>
+    # Don't prepend syslog tag or timestamp to log output
+    <format>
+      output_tag false
+      output_time false
+    </format>
   </store>
 {% if log_direct_to_elasticsearch %}
   <store>
@@ -193,14 +199,17 @@
   @type copy
   <store>
     @type file
-    path /var/log/kolla/neutron-tls-proxy/neutron-tls-proxy.*.log
-    output_tag false
-    output_time false
+    path /var/log/kolla/neutron-tls-proxy/neutron-tls-proxy
     append true
-    compress gzip
-    <buffer>
-      timekey_use_utc
+    # Disable timestamp in filename for logs
+    <buffer []>
+      path /var/log/kolla/neutron-tls-proxy/neutron-tls-proxy.*.buffer
     </buffer>
+    # Don't prepend syslog tag or timestamp to log output
+    <format>
+      output_tag false
+      output_time false
+    </format>
   </store>
 {% if log_direct_to_elasticsearch %}
   <store>
diff --git a/ansible/roles/common/templates/cron-logrotate-haproxy.conf.j2 b/ansible/roles/common/templates/cron-logrotate-haproxy.conf.j2
index 7af26dd38..3e89a2e75 100644
--- a/ansible/roles/common/templates/cron-logrotate-haproxy.conf.j2
+++ b/ansible/roles/common/templates/cron-logrotate-haproxy.conf.j2
@@ -1,3 +1,3 @@
-"/var/log/kolla/haproxy/haproxy.log"
+"/var/log/kolla/haproxy/*.log"
 {
 }
diff --git a/releasenotes/notes/fix-haproxy-logrotate-e299a0000728fd8f.yaml b/releasenotes/notes/fix-haproxy-logrotate-e299a0000728fd8f.yaml
new file mode 100644
index 000000000..d2c1ad605
--- /dev/null
+++ b/releasenotes/notes/fix-haproxy-logrotate-e299a0000728fd8f.yaml
@@ -0,0 +1,12 @@
+---
+issues:
+  - |
+    Existing fluentd log rotation failed to delete old haproxy, swift,
+    glance-tls-proxy and neutron-tls-proxy logs. These will not be
+    deleted by the new logrotate config and will have to be removed
+    manually.
+fixes:
+  - |
+    Existing fluentd log rotation failed to delete old haproxy, swift,
+    glance-tls-proxy and neutron-tls-proxy logs. Standardise rotation
+    and deletion of logs using logrotate.
-- 
GitLab