Fix issue with milliseconds in logs shiped to elastic.

  - Set Cinder logs Timestamp based on time record field
  - Change cinder_api_wsgi time format with milliseconds.

Related-bug: PROD-36383
Change-Id: I23ef1d6a0db2d91b6d3ca33ae3acb63bb55af05f
diff --git a/cinder/files/pike/cinder-wsgi.conf b/cinder/files/pike/cinder-wsgi.conf
index 486bc19..8d146d2 100644
--- a/cinder/files/pike/cinder-wsgi.conf
+++ b/cinder/files/pike/cinder-wsgi.conf
@@ -12,7 +12,9 @@
     </IfVersion>
 
     ErrorLog /var/log/apache2/cinder_error.log
-    CustomLog /var/log/apache2/cinder.log "%v:%p %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\""
+{% raw %}
+    CustomLog /var/log/apache2/cinder.log "%v:%p %h %l %u [%{%d/%b/%Y %T}t.%{msec_frac}t %{%z}t] \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\""
+{% endraw %}
 
     <Directory /usr/bin>
         <IfVersion >= 2.4>
diff --git a/cinder/files/queens/cinder-wsgi.conf b/cinder/files/queens/cinder-wsgi.conf
index 486bc19..8d146d2 100644
--- a/cinder/files/queens/cinder-wsgi.conf
+++ b/cinder/files/queens/cinder-wsgi.conf
@@ -12,7 +12,9 @@
     </IfVersion>
 
     ErrorLog /var/log/apache2/cinder_error.log
-    CustomLog /var/log/apache2/cinder.log "%v:%p %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\""
+{% raw %}
+    CustomLog /var/log/apache2/cinder.log "%v:%p %h %l %u [%{%d/%b/%Y %T}t.%{msec_frac}t %{%z}t] \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\""
+{% endraw %}
 
     <Directory /usr/bin>
         <IfVersion >= 2.4>
diff --git a/cinder/meta/fluentd.yml b/cinder/meta/fluentd.yml
index a0dbd17..b21ed29 100644
--- a/cinder/meta/fluentd.yml
+++ b/cinder/meta/fluentd.yml
@@ -27,9 +27,9 @@
             parser:
               type: regexp
               time_key: Timestamp
-              time_format: '%d/%b/%Y:%H:%M:%S %z'
-              keep_time_key: false
-              # Apache format: https://regex101.com/r/WeCT7s/5
+              time_format: '%d/%b/%Y %H:%M:%S.%N %z'
+              keep_time_key: true
+              # Apache format: https://regex101.com/r/WeCT7s/8
               format: '/(?<hostname>[\w\.\-]+)\:(?<port>\d+)\s(?<http_client_ip_address>[\d\.]+)\s\-\s\-\s\[(?<Timestamp>.*)\]\s(?<Payload>\"(?<http_method>[A-Z]+)\s(?<http_url>\S+)\s(?<http_version>[.\/\dHTFSP]+)\"\s(?<http_status>\d{3})\s(?<http_response_time>\d+)\s(?<http_response_size>\d+)\s\"(?<http_referer>.*)\"\s\"(?<user_agent>.*)\")/'
         filter:
           add_cinder_wsgi_record_fields:
@@ -92,6 +92,8 @@
                 value: ${ record['name'] }
               - name: programname
                 value: '${ record["programname"] ? record["programname"] : "cinder" }'
+              - name: Timestamp
+                value: ${ DateTime.parse(record['time']).strftime('%Y-%m-%dT%H:%M:%S.%N%z') }
           parse_http_stats:
             tag: openstack.cinder
             type: parser