mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-08 07:23:34 +00:00
fix(ingest): metabase - fix the datetime parsing issue (#3831)
fixes #3803
This commit is contained in:
parent
480ad24282
commit
9f80e5487d
@ -1,3 +1,4 @@
|
|||||||
|
from datetime import datetime
|
||||||
from functools import lru_cache
|
from functools import lru_cache
|
||||||
from typing import Dict, Iterable, Optional
|
from typing import Dict, Iterable, Optional
|
||||||
|
|
||||||
@ -131,6 +132,17 @@ class MetabaseSource(Source):
|
|||||||
reason=f"Unable to retrieve dashboards. " f"Reason: {str(http_error)}",
|
reason=f"Unable to retrieve dashboards. " f"Reason: {str(http_error)}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get_timestamp_millis_from_ts_string(ts_str: str) -> int:
|
||||||
|
"""
|
||||||
|
Converts the given timestamp string to milliseconds. If parsing fails,
|
||||||
|
returns the utc-now in milliseconds.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
return int(dp.parse(ts_str).timestamp() * 1000)
|
||||||
|
except (dp.ParserError, OverflowError):
|
||||||
|
return int(datetime.utcnow().timestamp() * 1000)
|
||||||
|
|
||||||
def construct_dashboard_from_api_data(
|
def construct_dashboard_from_api_data(
|
||||||
self, dashboard_info: dict
|
self, dashboard_info: dict
|
||||||
) -> Optional[DashboardSnapshot]:
|
) -> Optional[DashboardSnapshot]:
|
||||||
@ -157,8 +169,8 @@ class MetabaseSource(Source):
|
|||||||
)
|
)
|
||||||
last_edit_by = dashboard_details.get("last-edit-info") or {}
|
last_edit_by = dashboard_details.get("last-edit-info") or {}
|
||||||
modified_actor = builder.make_user_urn(last_edit_by.get("email", "unknown"))
|
modified_actor = builder.make_user_urn(last_edit_by.get("email", "unknown"))
|
||||||
modified_ts = int(
|
modified_ts = self.get_timestamp_millis_from_ts_string(
|
||||||
dp.parse(f"{last_edit_by.get('timestamp', 'now')}").timestamp() * 1000
|
f"{last_edit_by.get('timestamp')}"
|
||||||
)
|
)
|
||||||
title = dashboard_details.get("name", "") or ""
|
title = dashboard_details.get("name", "") or ""
|
||||||
description = dashboard_details.get("description", "") or ""
|
description = dashboard_details.get("description", "") or ""
|
||||||
@ -261,8 +273,8 @@ class MetabaseSource(Source):
|
|||||||
|
|
||||||
last_edit_by = card_details.get("last-edit-info") or {}
|
last_edit_by = card_details.get("last-edit-info") or {}
|
||||||
modified_actor = builder.make_user_urn(last_edit_by.get("email", "unknown"))
|
modified_actor = builder.make_user_urn(last_edit_by.get("email", "unknown"))
|
||||||
modified_ts = int(
|
modified_ts = self.get_timestamp_millis_from_ts_string(
|
||||||
dp.parse(f"{last_edit_by.get('timestamp', 'now')}").timestamp() * 1000
|
f"{last_edit_by.get('timestamp')}"
|
||||||
)
|
)
|
||||||
last_modified = ChangeAuditStamps(
|
last_modified = ChangeAuditStamps(
|
||||||
created=AuditStamp(time=modified_ts, actor=modified_actor),
|
created=AuditStamp(time=modified_ts, actor=modified_actor),
|
||||||
|
|||||||
@ -100,8 +100,7 @@
|
|||||||
"id": 1,
|
"id": 1,
|
||||||
"email": "admin@metabase.com",
|
"email": "admin@metabase.com",
|
||||||
"first_name": "FirstName",
|
"first_name": "FirstName",
|
||||||
"last_name": "LastName",
|
"last_name": "LastName"
|
||||||
"timestamp": "2021-12-13T17:48:37.11"
|
|
||||||
},
|
},
|
||||||
"visualization_settings": {
|
"visualization_settings": {
|
||||||
"graph.series_labels": ["number"],
|
"graph.series_labels": ["number"],
|
||||||
@ -112,4 +111,4 @@
|
|||||||
"collection": null,
|
"collection": null,
|
||||||
"created_at": "2021-12-13T17:48:37.102",
|
"created_at": "2021-12-13T17:48:37.102",
|
||||||
"public_uuid": null
|
"public_uuid": null
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user