Collect API logs when Cinder runs in Apache

This change configures an additional Heka input/decoder to collect the
Apache logs from the Cinder API. It also adjusts the log format to
derive HTTP response metrics from the logs.

Change-Id: Ifb81a4a3e23778672f93c9d953da011d8ec6bd17
Depends-On: I42833a45aa593114cad330ee2bf2bc3b3d00497e
diff --git a/cinder/files/ocata/cinder-wsgi.conf b/cinder/files/ocata/cinder-wsgi.conf
index 3e4de23..153adde 100644
--- a/cinder/files/ocata/cinder-wsgi.conf
+++ b/cinder/files/ocata/cinder-wsgi.conf
@@ -1,6 +1,5 @@
 {%- from "cinder/map.jinja" import controller with context %}
 Listen {{ controller.osapi.host }}:8776
-LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %D(us)" cinder_combined
 
 <VirtualHost {{ controller.osapi.host }}:8776>
     WSGIDaemonProcess cinder-wsgi processes=5 threads=1 user=cinder display-name=%{GROUP}
@@ -13,10 +12,10 @@
     </IfVersion>
 
     ErrorLog /var/log/apache2/cinder_error.log
-    CustomLog /var/log/apache2/cinder.log cinder_combined
+    CustomLog /var/log/apache2/cinder.log "%v:%p %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\""
 
     <Directory /usr/bin>
-	<IfVersion >= 2.4>
+        <IfVersion >= 2.4>
             Require all granted
         </IfVersion>
         <IfVersion < 2.4>
diff --git a/cinder/meta/heka.yml b/cinder/meta/heka.yml
index 7186c50..5a87914 100644
--- a/cinder/meta/heka.yml
+++ b/cinder/meta/heka.yml
@@ -2,6 +2,7 @@
 {%- from "cinder/map.jinja" import volume as _volume with context %}
 {%- set controller = _controller.get('enabled', False) %}
 {%- set volume = _volume.get('enabled', False) %}
+{%- set apache_wsgi = controller and _controller.version not in ('juno', 'kilo', 'liberty', 'mitaka', 'newton') %}
 log_collector:
   decoder:
     cinder:
@@ -9,6 +10,16 @@
       module_file: /usr/share/lma_collector/decoders/openstack_log.lua
       module_dir: /usr/share/lma_collector/common;/usr/share/heka/lua_modules
       adjust_timezone: true
+{%- if apache_wsgi %}
+    cinder_wsgi:
+      engine: sandbox
+      module_file: /usr/share/lma_collector/decoders/apache_wsgi_log.lua
+      module_dir: /usr/share/lma_collector/common;/usr/share/heka/lua_modules
+      config:
+        logger: openstack.cinder
+        apache_log_pattern: >-
+          %v:%p %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\"
+{%- endif %}
   splitter:
     cinder:
       engine: token
@@ -22,6 +33,16 @@
       priority: ["^Seq"]
       decoder: "cinder_decoder"
       splitter: "cinder_splitter"
+{%- if apache_wsgi %}
+    cinder_wsgi_log:
+      engine: logstreamer
+      log_directory: "/var/log/apache2"
+      file_match: 'cinder\.log'
+      differentiator: ['cinder-wsgi']
+      priority: ["^Seq"]
+      decoder: "cinder_wsgi_decoder"
+      splitter: "TokenSplitter"
+{%- endif %}
 metric_collector:
   trigger:
     {%- if controller or volume %}