Browse Source

Convert event metadata timestamps to ISO 8601 format for ES

Change-Id: Ifdb74ae6c9b6ffaed164ed7e338f60165df0a15e
Ildar Svetlov 1 year ago
parent
commit
d9be39758e

+ 23
- 2
deployment_scripts/puppet/modules/telemetry/files/ceilometer_fixes/impl_elasticsearch.py View File

@@ -84,10 +84,31 @@ class Connection(base.Connection):
84 84
         iclient.put_template(name='enable_timestamp', body=ts_template)
85 85
 
86 86
     def record_events(self, events):
87
-
87
+        datetime_trait_fields = [
88
+            'audit_period_beginning',
89
+            'audit_period_ending',
90
+            'deleted_at',
91
+            'created_at',
92
+            'launched_at',
93
+            'modify_at'
94
+        ]
88 95
         def _build_bulk_index(event_list):
89 96
             for ev in event_list:
90
-                traits = {t.name: t.value for t in ev.traits}
97
+                traits = {}
98
+                for t in ev.traits:
99
+                    name = t.name
100
+                    value = t.value
101
+                    if name in datetime_trait_fields:
102
+                        try:
103
+                            ts = timeutils.parse_isotime(value)
104
+                            ts = timeutils.normalize_time(ts)
105
+                            value = timeutils.strtime(ts)
106
+                        except ValueError:
107
+                            LOG.exception(
108
+                                _LE('Could not parse timestamp [%s] from [%s] traits field' % (value, name))
109
+                            )
110
+                            value = t.value
111
+                    traits[name] = value
91 112
                 yield {'_op_type': 'create',
92 113
                        '_index': '%s_%s' % (self.index_name,
93 114
                                             ev.generated.date().isoformat()),

Loading…
Cancel
Save