Fix issue with milliseconds in logs shipped to elastic.

  - Set Nova logs Timestamp based on time record field
  - Change nova_placement_api_wsgi time format with milliseconds.

Related-bug: PROD-36383
Change-Id: I82fd632c8e05562aca93e7a40763df246f0c40d5
diff --git a/nova/files/pike/nova-placement-api.conf b/nova/files/pike/nova-placement-api.conf
index e7cde11..d89e9fc 100644
--- a/nova/files/pike/nova-placement-api.conf
+++ b/nova/files/pike/nova-placement-api.conf
@@ -14,7 +14,9 @@
     </IfVersion>
 
     ErrorLog /var/log/apache2/nova_placement_error.log
-    CustomLog /var/log/apache2/nova_placement_access.log "%v:%p %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\""
+{% raw %}
+    CustomLog /var/log/apache2/nova_placement_access.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/nova/files/queens/nova-placement-api.conf b/nova/files/queens/nova-placement-api.conf
index e7cde11..d89e9fc 100644
--- a/nova/files/queens/nova-placement-api.conf
+++ b/nova/files/queens/nova-placement-api.conf
@@ -14,7 +14,9 @@
     </IfVersion>
 
     ErrorLog /var/log/apache2/nova_placement_error.log
-    CustomLog /var/log/apache2/nova_placement_access.log "%v:%p %h %l %u %t \"%r\" %>s %D %O \"%{Referer}i\" \"%{User-Agent}i\""
+{% raw %}
+    CustomLog /var/log/apache2/nova_placement_access.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/nova/meta/fluentd.yml b/nova/meta/fluentd.yml
index 48cf241..6dabef4 100644
--- a/nova/meta/fluentd.yml
+++ b/nova/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 access log custom format: https://regex101.com/r/WeCT7s/5
+              time_format: '%d/%b/%Y %H:%M:%S.%N %z'
+              keep_time_key: true
+              # Apache access log custom 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_nova_palcement_wsgi_record_fields:
@@ -92,6 +92,8 @@
                 value: ${ record['name'] }
               - name: programname
                 value: '${ record["programname"] ? record["programname"] : "nova" }'
+              - name: Timestamp
+                value: ${ DateTime.parse(record['time']).strftime('%Y-%m-%dT%H:%M:%S.%N%z') }
           parse_http_stats:
             tag: openstack.nova
             type: parser