From 82264ab7d6d178b6d69c84016997cd4df34f112a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=89ric=20Lemoine?= <elemoine@mirantis.com>
Date: Wed, 17 Feb 2016 14:26:19 +0100
Subject: [PATCH] Make Heka collect Heat logs

Partially implements: blueprint heka
Change-Id: Ie22c4326c6ec2a3426b0c3b8fda4554b1b2541b0
---
 ansible/roles/common/templates/heka-openstack.toml.j2 | 2 +-
 ansible/roles/common/templates/rsyslog.conf.j2        | 9 ---------
 ansible/roles/heat/tasks/bootstrap.yml                | 4 +++-
 ansible/roles/heat/tasks/start.yml                    | 6 +++---
 ansible/roles/heat/templates/heat.conf.j2             | 5 ++---
 docker/heat/heat-api/extend_start.sh                  | 7 +++++++
 docker/heat/heat-base/Dockerfile.j2                   | 9 ++++++---
 docker/heat/heat-base/extend_start.sh                 | 8 ++++++++
 8 files changed, 30 insertions(+), 20 deletions(-)
 create mode 100644 docker/heat/heat-base/extend_start.sh

diff --git a/ansible/roles/common/templates/heka-openstack.toml.j2 b/ansible/roles/common/templates/heka-openstack.toml.j2
index 306904f79..dc35cef18 100644
--- a/ansible/roles/common/templates/heka-openstack.toml.j2
+++ b/ansible/roles/common/templates/heka-openstack.toml.j2
@@ -6,5 +6,5 @@ filename = "lua_decoders/os_openstack_log.lua"
 type = "LogstreamerInput"
 decoder = "openstack_log_decoder"
 log_directory = "/var/log/kolla"
-file_match = '(?P<Service>nova|glance|keystone|neutron|cinder)/(?P<Program>.*)\.log'
+file_match = '(?P<Service>nova|glance|keystone|neutron|cinder|heat)/(?P<Program>.*)\.log'
 differentiator = ["Service", "_", "Program"]
diff --git a/ansible/roles/common/templates/rsyslog.conf.j2 b/ansible/roles/common/templates/rsyslog.conf.j2
index 7c7660024..91c2c4b99 100644
--- a/ansible/roles/common/templates/rsyslog.conf.j2
+++ b/ansible/roles/common/templates/rsyslog.conf.j2
@@ -7,15 +7,6 @@ $KLogPermitNonKernelFacility on
 $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
 $RepeatedMsgReduction on
 
-$template HeatAPIFile,"/var/log/heat/heat-api.log"
-:syslogtag,contains,"heat-api" ?HeatAPIFile
-
-$template HeatAPICfnFile,"/var/log/heat/heat-api-cfn.log"
-:syslogtag,contains,"heat-api-cfn" ?HeatAPICfnFile
-
-$template HeatEngineFile,"/var/log/heat/heat-engine.log"
-:syslogtag,contains,"heat-engine" ?HeatEngineFile
-
 $template MuranoEngineFile,"/var/log/murano/murano-engine.log"
 :syslogtag,contains,"murano-engine" ?MuranoEngineFile
 
diff --git a/ansible/roles/heat/tasks/bootstrap.yml b/ansible/roles/heat/tasks/bootstrap.yml
index fa6fde538..8429c0414 100644
--- a/ansible/roles/heat/tasks/bootstrap.yml
+++ b/ansible/roles/heat/tasks/bootstrap.yml
@@ -53,7 +53,9 @@
     labels:
       BOOTSTRAP:
     name: "bootstrap_heat"
-    volumes: "{{ node_config_directory }}/heat-api/:{{ container_config_directory }}/:ro"
+    volumes:
+      - "{{ node_config_directory }}/heat-api/:{{ container_config_directory }}/:ro"
+      - "kolla_logs:/var/log/kolla/"
   run_once: True
   delegate_to: "{{ groups['heat-api'][0] }}"
   when: database_created
diff --git a/ansible/roles/heat/tasks/start.yml b/ansible/roles/heat/tasks/start.yml
index 6699ab472..7ec4a9fae 100644
--- a/ansible/roles/heat/tasks/start.yml
+++ b/ansible/roles/heat/tasks/start.yml
@@ -7,7 +7,7 @@
     name: "heat_api"
     volumes:
       - "{{ node_config_directory }}/heat-api/:{{ container_config_directory }}/:ro"
-      - "rsyslog_socket:/var/lib/kolla/rsyslog/"
+      - "kolla_logs:/var/log/kolla/"
   when: inventory_hostname in groups['heat-api']
 
 - name: Starting heat-api-cfn container
@@ -18,7 +18,7 @@
     name: "heat_api_cfn"
     volumes:
       - "{{ node_config_directory }}/heat-api-cfn/:{{ container_config_directory }}/:ro"
-      - "rsyslog_socket:/var/lib/kolla/rsyslog/"
+      - "kolla_logs:/var/log/kolla/"
   when: inventory_hostname in groups['heat-api-cfn']
 
 - name: Starting heat-engine container
@@ -29,5 +29,5 @@
     name: "heat_engine"
     volumes:
       - "{{ node_config_directory }}/heat-engine/:{{ container_config_directory }}/:ro"
-      - "rsyslog_socket:/var/lib/kolla/rsyslog/"
+      - "kolla_logs:/var/log/kolla/"
   when: inventory_hostname in groups['heat-engine']
diff --git a/ansible/roles/heat/templates/heat.conf.j2 b/ansible/roles/heat/templates/heat.conf.j2
index 5d8afa05e..b581cec01 100644
--- a/ansible/roles/heat/templates/heat.conf.j2
+++ b/ansible/roles/heat/templates/heat.conf.j2
@@ -1,6 +1,8 @@
 [DEFAULT]
 debug = {{ heat_logging_debug }}
 
+log_dir = /var/log/kolla/heat
+
 heat_watch_server_url = {{ public_protocol }}://{{ kolla_external_address }}:{{ heat_api_cfn_port }}
 heat_metadata_server_url = {{ public_protocol }}://{{ kolla_external_address }}:{{ heat_api_cfn_port }}
 heat_waitcondition_server_url = {{ public_protocol }}://{{ kolla_external_address }}:{{ heat_api_cfn_port }}/v1/waitcondition
@@ -14,9 +16,6 @@ notification_driver = noop
 deferred_auth_method = trusts
 trusts_delegated_role = heat_stack_owner
 
-syslog_log_facility=LOG_LOCAL0
-use_syslog=yes
-
 [oslo_messaging_rabbit]
 rabbit_userid = {{ rabbitmq_user }}
 rabbit_password = {{ rabbitmq_password }}
diff --git a/docker/heat/heat-api/extend_start.sh b/docker/heat/heat-api/extend_start.sh
index ca4f83da5..2eb7468f5 100644
--- a/docker/heat/heat-api/extend_start.sh
+++ b/docker/heat/heat-api/extend_start.sh
@@ -1,5 +1,12 @@
 #!/bin/bash
 
+if [[ ! -d "/var/log/kolla/heat" ]]; then
+    mkdir -p /var/log/kolla/heat
+fi
+if [[ $(stat -c %a /var/log/kolla/heat) != "755" ]]; then
+    chmod 755 /var/log/kolla/heat
+fi
+
 # Bootstrap and exit if KOLLA_BOOTSTRAP variable is set. This catches all cases
 # of the KOLLA_BOOTSTRAP variable being set, including empty.
 if [[ "${!KOLLA_BOOTSTRAP[@]}" ]]; then
diff --git a/docker/heat/heat-base/Dockerfile.j2 b/docker/heat/heat-base/Dockerfile.j2
index ca818b94b..bbdce7e90 100644
--- a/docker/heat/heat-base/Dockerfile.j2
+++ b/docker/heat/heat-base/Dockerfile.j2
@@ -21,10 +21,13 @@ ADD heat-base-archive /heat-base-source
 RUN ln -s heat-base-source/* heat \
     && useradd --user-group heat \
     && /var/lib/kolla/venv/bin/pip --no-cache-dir install --upgrade -c requirements/upper-constraints.txt /heat \
-    && mkdir -p /etc/heat /var/log/heat /home/heat \
+    && mkdir -p /etc/heat /home/heat \
     && cp -r /heat/etc/heat/* /etc/heat/ \
-    && chown -R heat: /etc/heat /var/log/heat /home/heat
+    && chown -R heat: /etc/heat /home/heat
 
 {% endif %}
 
-RUN usermod -a -G kolla heat
+COPY extend_start.sh /usr/local/bin/kolla_extend_start
+
+RUN usermod -a -G kolla heat \
+    && chmod 755 /usr/local/bin/kolla_extend_start
diff --git a/docker/heat/heat-base/extend_start.sh b/docker/heat/heat-base/extend_start.sh
new file mode 100644
index 000000000..9cdefa6ad
--- /dev/null
+++ b/docker/heat/heat-base/extend_start.sh
@@ -0,0 +1,8 @@
+#!/bin/bash
+
+if [[ ! -d "/var/log/kolla/heat" ]]; then
+    mkdir -p /var/log/kolla/heat
+fi
+if [[ $(stat -c %a /var/log/kolla/heat) != "755" ]]; then
+    chmod 755 /var/log/kolla/heat
+fi
-- 
GitLab