Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 切分 metadata 访问单独 db --story=115316807 #400

Conversation

dellkeji
Copy link

No description provided.

Copy link

请在 PR 中添加类型标签,例如:fixfeatdocsstylerefactortestchoremerge, perf

Copy link

请在 PR 中添加项目标签,例如:project/monitorproject/apmproject/logproject/public

@dellkeji dellkeji added project/monitor project monitor feat A new feature. Correlates with MINOR in SemVer labels Nov 29, 2023
@@ -33,7 +33,7 @@ class VisibleEnum:

GLOBAL_CONFIG_BK_BIZ_ID = 0
# 获取需要增加事务的DB链接名
DATABASE_CONNECTION_NAME = getattr(settings, "METADATA_DEFAULT_DATABASE_NAME", "monitor_api")
DATABASE_CONNECTION_NAME = getattr(settings, "METADATA_DEFAULT_DATABASE_NAME", "metadata")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要确认是否所有的事务都仅有metadata库发起吗?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

因为当前key,还没有使用,调整 METADATA_DEFAULT_DATABASE_NAME =》 APM_BACKEND_DEFAULT_DATABASE_NAME

@@ -813,6 +824,15 @@
"PORT": GRAFANA_MYSQL_PORT or BACKEND_MYSQL_PORT,
"OPTIONS": {"charset": "utf8mb4"},
},
"metadata": {
"ENGINE": "django.db.backends.mysql",
"NAME": METADATA_MYSQL_NAME,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

参考上面: "PORT": GRAFANA_MYSQL_PORT or BACKEND_MYSQL_PORT,

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在返回的方法中,统一处理

@@ -758,7 +759,7 @@
KAFKA_AUTO_COMMIT = True

DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
DATABASE_ROUTERS = ["bk_dataview.router.DBRouter"]
DATABASE_ROUTERS = ["bk_dataview.router.DBRouter", "metadata.db_router.DBRouter"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

最好判断下是否配置了METADATA_MYSQL_HOST这种变量,如果没有这个变量,可以不用append

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要调整路由,因为backend的默认router中,需要移除 metadata的app标识

@dellkeji
Copy link
Author

暂时不需要切换 DB,先关闭

@dellkeji dellkeji closed this Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat A new feature. Correlates with MINOR in SemVer project/monitor project monitor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants