Skip to content

Commit

Permalink
fix(backend): 修复flow的时间戳问题 #3921
Browse files Browse the repository at this point in the history
  • Loading branch information
iSecloud authored and zhangzhw8 committed Apr 12, 2024
1 parent 9c36ee2 commit cc88339
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
8 changes: 4 additions & 4 deletions dbm-ui/backend/db_monitor/views/notice_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ class MonitorNoticeGroupViewSet(viewsets.AuditedModelViewSet):
serializer_class = NoticeGroupSerializer
pagination_class = AuditedLimitOffsetPagination
filter_class = MonitorGroupListFilter

default_permission_class = DBManagePermission()
default_permission_class = [DBManagePermission()]

def get_action_permission_map(self):
return {
Expand Down Expand Up @@ -145,8 +144,9 @@ def list_group_name(self, request, *args, **kwargs):
return Response(group_name_infos)

@common_swagger_auto_schema(operation_summary=_("获取默认告警组名称"), tags=[SWAGGER_TAG])
@action(methods=["GET"], detail=False, filter_class=None, pagination_class=None)
@action(methods=["GET"], detail=False, filter_class=MonitorGroupListFilter, pagination_class=None)
def list_default_group(self, request, *args, **kwargs):
default_groups = list(self.get_queryset().exclude(db_type="").values("id", "name", "db_type"))
queryset = self.filter_queryset(self.get_queryset())
default_groups = list(queryset.exclude(db_type="").values("id", "name", "db_type"))
default_group_map = {group.pop("db_type"): group for group in default_groups}
return Response(default_group_map)
6 changes: 3 additions & 3 deletions dbm-ui/backend/flow/engine/bamboo/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ def recursion_nodes_status(self, node: FlowNode, status: str, raw_data: Dict):
for key, values in raw_data.items():
if key == node.node_id:
raw_data[key]["status"] = status
raw_data[key]["created_at"] = datetime2timestamp(node.created_at)
raw_data[key]["started_at"] = datetime2timestamp(node.started_at)
raw_data[key]["updated_at"] = datetime2timestamp(node.updated_at)
raw_data[key]["created_at"] = int(datetime2timestamp(node.created_at))
raw_data[key]["started_at"] = int(datetime2timestamp(node.started_at))
raw_data[key]["updated_at"] = int(datetime2timestamp(node.updated_at))
raw_data[key]["hosts"] = node.hosts
continue

Expand Down
6 changes: 4 additions & 2 deletions dbm-ui/backend/utils/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
specific language governing permissions and limitations under the License.
"""
import datetime
import time
from bisect import bisect_right
from typing import List, Optional, Union

Expand Down Expand Up @@ -91,8 +90,11 @@ def standardized_time_str(datetime_str: str):


def datetime2timestamp(o_datetime: Optional[datetime.datetime]) -> float:
# time.mktime(o_datetime.timetuple())
# 这样转换有问题: time.mktime()函数默认假设时间元组是本地时间,而不是UTC时间。
# 直接用datetime的时间戳转换即可
if o_datetime:
return time.mktime(o_datetime.timetuple())
return o_datetime.timestamp()
return 0.0


Expand Down

0 comments on commit cc88339

Please sign in to comment.