Consistent timestamp format for all datasources
All timestamps in Vitrage should be of the same format: '%Y-%m-%dT%H:%M:%SZ' This is needed so webhooks will know what format to expect. Story: 1776181 Task: 22405 Depends-On: I27624b28e8aa1770d805ee68982509894522b8e6 Change-Id: I9849ce0850de46f928a7c01009c7738976aa3478
This commit is contained in:
parent
a96bc0642b
commit
75fb4d1213
|
@ -27,6 +27,7 @@ from vitrage.datasources import transformer_base as tbase
|
||||||
from vitrage.datasources.transformer_base import build_key
|
from vitrage.datasources.transformer_base import build_key
|
||||||
from vitrage.datasources.transformer_base import extract_field_value
|
from vitrage.datasources.transformer_base import extract_field_value
|
||||||
import vitrage.graph.utils as graph_utils
|
import vitrage.graph.utils as graph_utils
|
||||||
|
from vitrage.utils.datetime import format_timestamp
|
||||||
|
|
||||||
|
|
||||||
class CinderVolumeTransformer(ResourceTransformerBase):
|
class CinderVolumeTransformer(ResourceTransformerBase):
|
||||||
|
@ -121,7 +122,7 @@ class CinderVolumeTransformer(ResourceTransformerBase):
|
||||||
vitrage_sample_timestamp=vitrage_sample_timestamp,
|
vitrage_sample_timestamp=vitrage_sample_timestamp,
|
||||||
entity_id=volume_id,
|
entity_id=volume_id,
|
||||||
entity_state=volume_state,
|
entity_state=volume_state,
|
||||||
update_timestamp=update_timestamp,
|
update_timestamp=format_timestamp(update_timestamp),
|
||||||
metadata=metadata)
|
metadata=metadata)
|
||||||
|
|
||||||
def _create_snapshot_neighbors(self, entity_event):
|
def _create_snapshot_neighbors(self, entity_event):
|
||||||
|
|
|
@ -97,7 +97,7 @@ class DriverBase(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _add_sampling_time(entity):
|
def _add_sampling_time(entity):
|
||||||
entity[DSProps.SAMPLE_DATE] = str(datetime_utils.utcnow())
|
entity[DSProps.SAMPLE_DATE] = datetime_utils.format_utcnow()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _add_datasource_action(entity, datasource_action):
|
def _add_datasource_action(entity, datasource_action):
|
||||||
|
|
|
@ -359,7 +359,9 @@ class TransformerBase(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _format_update_timestamp(update_timestamp, sample_timestamp):
|
def _format_update_timestamp(update_timestamp, sample_timestamp):
|
||||||
return update_timestamp if update_timestamp else sample_timestamp
|
update_timestamp = update_timestamp if update_timestamp \
|
||||||
|
else sample_timestamp
|
||||||
|
return datetime_utils.format_timestamp(update_timestamp)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_enrich_query(event):
|
def get_enrich_query(event):
|
||||||
|
|
|
@ -354,7 +354,7 @@ def simple_static_generators(switch_num=2, host_num=10,
|
||||||
snap_vals = {}
|
snap_vals = {}
|
||||||
snap_vals.update({
|
snap_vals.update({
|
||||||
DSProps.DATASOURCE_ACTION: DatasourceAction.SNAPSHOT,
|
DSProps.DATASOURCE_ACTION: DatasourceAction.SNAPSHOT,
|
||||||
DSProps.SAMPLE_DATE: utcnow()})
|
DSProps.SAMPLE_DATE: str(utcnow())})
|
||||||
test_entity_spec_list.append(
|
test_entity_spec_list.append(
|
||||||
{tg.DYNAMIC_INFO_FKEY: tg.DRIVER_STATIC_SNAPSHOT_D,
|
{tg.DYNAMIC_INFO_FKEY: tg.DRIVER_STATIC_SNAPSHOT_D,
|
||||||
tg.STATIC_INFO_FKEY: tg.DRIVER_STATIC_SNAPSHOT_S,
|
tg.STATIC_INFO_FKEY: tg.DRIVER_STATIC_SNAPSHOT_S,
|
||||||
|
@ -369,7 +369,7 @@ def simple_static_generators(switch_num=2, host_num=10,
|
||||||
update_vals = {}
|
update_vals = {}
|
||||||
update_vals.update({
|
update_vals.update({
|
||||||
DSProps.DATASOURCE_ACTION: DatasourceAction.UPDATE,
|
DSProps.DATASOURCE_ACTION: DatasourceAction.UPDATE,
|
||||||
DSProps.SAMPLE_DATE: utcnow()})
|
DSProps.SAMPLE_DATE: str(utcnow())})
|
||||||
test_entity_spec_list.append(
|
test_entity_spec_list.append(
|
||||||
{tg.DYNAMIC_INFO_FKEY: tg.DRIVER_STATIC_SNAPSHOT_D,
|
{tg.DYNAMIC_INFO_FKEY: tg.DRIVER_STATIC_SNAPSHOT_D,
|
||||||
tg.STATIC_INFO_FKEY: None,
|
tg.STATIC_INFO_FKEY: None,
|
||||||
|
|
|
@ -28,6 +28,10 @@ def utcnow(with_timezone=True):
|
||||||
return timeutils.utcnow(with_timezone)
|
return timeutils.utcnow(with_timezone)
|
||||||
|
|
||||||
|
|
||||||
|
def format_utcnow(with_timezone=True, date_format=TIMESTAMP_FORMAT):
|
||||||
|
return utcnow(with_timezone).strftime(date_format)
|
||||||
|
|
||||||
|
|
||||||
def change_time_str_format(timestamp_str, old_format, new_format):
|
def change_time_str_format(timestamp_str, old_format, new_format):
|
||||||
utc = datetime.strptime(timestamp_str, old_format)
|
utc = datetime.strptime(timestamp_str, old_format)
|
||||||
return utc.strftime(new_format)
|
return utc.strftime(new_format)
|
||||||
|
@ -43,3 +47,8 @@ def change_to_utc_time_and_format(timestamp_str, new_format):
|
||||||
def format_unix_timestamp(timestamp, date_format=TIMESTAMP_FORMAT):
|
def format_unix_timestamp(timestamp, date_format=TIMESTAMP_FORMAT):
|
||||||
return datetime.fromtimestamp(float(timestamp)) \
|
return datetime.fromtimestamp(float(timestamp)) \
|
||||||
.strftime(date_format)
|
.strftime(date_format)
|
||||||
|
|
||||||
|
|
||||||
|
def format_timestamp(timestamp_str, new_format=TIMESTAMP_FORMAT):
|
||||||
|
return parser.parse(timestamp_str).strftime(new_format) if timestamp_str \
|
||||||
|
else None
|
||||||
|
|
Loading…
Reference in New Issue