Skip to content

Commit 6f1b807

Browse files
committed
feat(mysql): mysql元数据巡检 #8666
1 parent 639e93b commit 6f1b807

File tree

17 files changed

+655
-187
lines changed

17 files changed

+655
-187
lines changed

dbm-ui/backend/db_periodic_task/local_tasks/db_meta/db_meta_check/check_cluster_topo.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

dbm-ui/backend/db_periodic_task/local_tasks/db_meta/db_meta_check/check_instance_belong.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

dbm-ui/backend/db_periodic_task/local_tasks/db_meta/db_meta_check/check_replicate_role.py

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
from typing import Optional, Union
12+
13+
from backend.db_meta.models import ProxyInstance, StorageInstance
14+
from backend.db_report.enums import MetaCheckSubType
15+
16+
17+
class CheckResponse:
18+
def __init__(
19+
self,
20+
msg: str,
21+
check_subtype: MetaCheckSubType,
22+
instance: Optional[Union[StorageInstance, ProxyInstance]] = None,
23+
):
24+
self.msg = msg
25+
self.check_subtype = check_subtype
26+
self.instance = instance
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
from typing import List
12+
13+
from backend.db_meta.models import Cluster
14+
from backend.db_periodic_task.local_tasks.db_meta.db_meta_check.mysql_cluster_topo.check_response import CheckResponse
15+
from backend.db_report.models import MetaCheckReport
16+
17+
18+
def checker_wrapper(checker):
19+
def wrapper(c: Cluster) -> List[MetaCheckReport]:
20+
out_reports = []
21+
check_response: List[CheckResponse] = checker(c)
22+
if not check_response:
23+
return out_reports
24+
25+
for cr in check_response:
26+
out_report = MetaCheckReport(
27+
subtype=cr.check_subtype,
28+
bk_biz_id=c.bk_biz_id,
29+
bk_cloud_id=c.bk_cloud_id,
30+
status=False,
31+
msg=cr.msg,
32+
cluster=c.immute_domain,
33+
cluster_type=c.cluster_type,
34+
creator="system",
35+
updater="system",
36+
# create_at=timezone.localtime(timezone.now()),
37+
# update_at=timezone.localtime(timezone.now()),
38+
ip="0.0.0.0",
39+
port=0,
40+
machine_type="",
41+
)
42+
if cr.instance:
43+
out_report.ip = cr.instance.machine.ip
44+
out_report.port = cr.instance.port
45+
out_report.machine_type = cr.instance.machine_type
46+
47+
out_reports.append(out_report)
48+
49+
return out_reports
50+
51+
return wrapper
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
from .check import health_check
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-DB管理系统(BlueKing-BK-DBM) available.
4+
Copyright (C) 2017-2023 THL A29 Limited, a Tencent company. All rights reserved.
5+
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at https://opensource.org/licenses/MIT
7+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
8+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
9+
specific language governing permissions and limitations under the License.
10+
"""
11+
from typing import List
12+
13+
from django.utils.translation import ugettext_lazy as _
14+
15+
from backend.db_meta.enums import InstanceInnerRole
16+
from backend.db_meta.models import Cluster
17+
from backend.db_periodic_task.local_tasks.db_meta.db_meta_check.mysql_cluster_topo.check_response import CheckResponse
18+
from backend.db_periodic_task.local_tasks.db_meta.db_meta_check.mysql_cluster_topo.decorator import checker_wrapper
19+
from backend.db_report.enums import MetaCheckSubType
20+
21+
22+
@checker_wrapper
23+
def _cluster_proxy_access_master(
24+
c: Cluster,
25+
) -> List[CheckResponse]:
26+
"""
27+
proxy 必须且只能关联到 master
28+
"""
29+
bad = []
30+
for pi in c.proxyinstance_set.all():
31+
for si in pi.storageinstance.all():
32+
if si.instance_inner_role != InstanceInnerRole.MASTER:
33+
bad.append(
34+
CheckResponse(
35+
msg=_("proxy 关联到 {}: {}".format(si.instance_inner_role, si.ip_port)),
36+
check_subtype=MetaCheckSubType.ClusterTopo,
37+
instance=pi,
38+
)
39+
)
40+
41+
return bad

0 commit comments

Comments
 (0)