Skip to content

Commit

Permalink
mysqlclient 替换为pymysql & 文档地前缀添加语言和版本号 (#1616)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayuan929 authored Sep 23, 2024
1 parent 2443fcd commit 2b932b2
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 86 deletions.
36 changes: 18 additions & 18 deletions apiserver/paasng/fixtures/smart_advisor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
title_en: "Guide to building a local Python development environment",
short_description_zh_cn: '',
short_description_en: '',
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/quickstart/python/python_setup_dev',
location: '{paas_doc_url_prefix}/BaseGuide/quickstart/python/python_setup_dev',
affinity_tags: '["app-pl:python","plat-panel:app_created"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -13,7 +13,7 @@
title_en: How to deploy the BlueKing app",
short_description_zh_cn: '',
short_description_en: '',
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/deploy_intro',
location: '{paas_doc_url_prefix}/BaseGuide/topics/paas/deploy_intro',
affinity_tags: '["plat-panel:app_created"]', anti_affinity_tags: '[]', priority: 1,
created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -22,7 +22,7 @@
title_en: "Introduction to app process concepts and how to use",
short_description_zh_cn: "关于应用进程的简单介绍,内容包含 Procfile",
short_description_en: "A brief description of the app process, including the Procfile",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/process_procfile#section',
location: '{paas_doc_url_prefix}/BaseGuide/topics/paas/process_procfile#section',
affinity_tags: '["plat-panel:app_deployment","plat-panel:app_processes", "deploy_phase:prepare"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -31,7 +31,7 @@
title_en: "Guidelines for process communication in app",
short_description_zh_cn: "",
short_description_en: "",
location: "{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/entry_proc_services#进程间如何通信",
location: "{paas_doc_url_prefix}/BaseGuide/topics/paas/entry_proc_services#进程间如何通信",
affinity_tags: '["plat-panel:app_deployment","plat-panel:app_processes"]',
anti_affinity_tags: '[]', priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -40,7 +40,7 @@
title_en: "Example: How to add a celery backend task to a Python app",
short_description_zh_cn: "",
short_description_en: "",
location: "{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/process_procfile#什么是procfile",
location: "{paas_doc_url_prefix}/BaseGuide/topics/paas/process_procfile#什么是procfile",
affinity_tags: '["app-pl:python","plat-panel:app_deployment","plat-panel:app_processes", "deploy_phase:prepare"]',
anti_affinity_tags: '[]', priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -49,7 +49,7 @@
title_en: "Quick start: developing apps in Go",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/quickstart/golang/golang_preparations',
location: '{paas_doc_url_prefix}/BaseGuide/quickstart/golang/golang_preparations',
affinity_tags: '["app-pl:go","plat-panel:app_deployment","plat-panel:app_created"]',
anti_affinity_tags: '[]', priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -58,7 +58,7 @@
title_en: "Fix Procfile related errors",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/deploy#修复%20Procfile%20报错(fix-procfile)',
location: '{paas_doc_url_prefix}/BaseGuide/faq/deploy#修复%20Procfile%20报错(fix-procfile)',
affinity_tags: '["deploy-failure:fix-procfile"]', anti_affinity_tags: '[]', priority: 1,
created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -67,7 +67,7 @@
title_en: "Fix Python MySQL installation error",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/deploy#修复%20python%20mysql%20模块安装时报错(fix-pkg-install-mysql-python)',
location: '{paas_doc_url_prefix}/BaseGuide/faq/deploy#修复%20python%20mysql%20模块安装时报错(fix-pkg-install-mysql-python)',
affinity_tags: '["deploy-failure:fix-pkg-install-mysql-python"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -76,7 +76,7 @@
title_en: "App cannot start building",
short_description_zh_cn: '',
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/deploy#应用无法开始构建(fix-unable-select-buildpack)',
location: '{paas_doc_url_prefix}/BaseGuide/faq/deploy#应用无法开始构建(fix-unable-select-buildpack)',
affinity_tags: '["deploy-failure:fix-unable-select-buildpack"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -85,7 +85,7 @@
title_en: "Fix collectstatic phase error",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/deploy#修复 collectstatic 阶段报错(fix-py-collect-static)',
location: '{paas_doc_url_prefix}/BaseGuide/faq/deploy#修复 collectstatic 阶段报错(fix-py-collect-static)',
affinity_tags: '["deploy-failure:fix-py-collect-static"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -94,7 +94,7 @@
title_en: "Fix Python app runtime errors",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/deploy#修复 Python 应用 runtime 报错问题(fix-py-runtime-error)',
location: '{paas_doc_url_prefix}/BaseGuide/faq/deploy#修复 Python 应用 runtime 报错问题(fix-py-runtime-error)',
affinity_tags: '["deploy-failure:fix-py-runtime-error"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -103,7 +103,7 @@
title_en: "Fixing deployment taking too long",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/deploy#部署发布阶段耗时过长(fix-release-polling-timeout)',
location: '{paas_doc_url_prefix}/BaseGuide/faq/deploy#部署发布阶段耗时过长(fix-release-polling-timeout)',
affinity_tags: '["deploy-failure:fix-release-polling-timeout"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-08-20 11:08:51+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -112,7 +112,7 @@
title_en: "Python cannot install packages with . in the package name",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/deploy#Python 无法安装带.的包',
location: '{paas_doc_url_prefix}/BaseGuide/faq/deploy#Python 无法安装带.的包',
affinity_tags: '["deploy-failure:fix-python-package-with-dot"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-09-23 04:09:18+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -121,7 +121,7 @@
title_en: "How to use the pre-release command",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/release_hooks',
location: '{paas_doc_url_prefix}/BaseGuide/topics/paas/release_hooks',
affinity_tags: '["deploy_phase:build"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-09-23 04:09:18+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -130,7 +130,7 @@
title_en: "Configure BlueKing app access entry",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/app_entry_intro',
location: '{paas_doc_url_prefix}/BaseGuide/topics/paas/app_entry_intro',
affinity_tags: '["deploy_phase:release"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2020-09-23 04:09:18+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -139,7 +139,7 @@
title_en: "Python installs dependencies with missing setuptools_rust module",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/deploy#Python 安装依赖时提示缺少 setuptools_rust 模块',
location: '{paas_doc_url_prefix}/BaseGuide/faq/deploy#Python 安装依赖时提示缺少 setuptools_rust 模块',
affinity_tags: '["deploy-failure:fix-pip-setuptools-rust"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2021-06-01 04:09:18+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -148,7 +148,7 @@
title_en: "npm install dependencies prompted no matching version found",
short_description_zh_cn: "",
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/frame_node#npm安装依赖包提示找不到匹配的版本',
location: '{paas_doc_url_prefix}/BaseGuide/faq/frame_node#npm安装依赖包提示找不到匹配的版本',
affinity_tags: '["deploy-failure:fix-npm-no-match-version"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2021-06-01 04:09:18+00:00' }
- model: smart_advisor.documentarylink
Expand All @@ -157,7 +157,7 @@
title_en: "Why are some processes unable to use WebConsole?",
short_description_zh_cn: '因应用"环境配置"未满足要求,控制台功能无法启动,请参考文档,修改应用配置后重试。',
short_description_en: "",
location: '{doc_url_prefix}/markdown/PaaS/DevelopTools/BaseGuide/faq/platform#为什么有的进程无法使用访问控制台功能',
location: '{paas_doc_url_prefix}/BaseGuide/faq/platform#为什么有的进程无法使用访问控制台功能',
affinity_tags: '["app-feature:web-console"]', anti_affinity_tags: '[]',
priority: 1, created: !!timestamp '2021-08-31 00:00:00+00:00' }
- model: smart_advisor.deployfailurepattern
Expand Down
4 changes: 2 additions & 2 deletions apiserver/paasng/paas_wl/workloads/tracing/instrumentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def _instrument(self, **kwargs):
CeleryInstrumentor().instrument()

if getattr(settings, "OTEL_INSTRUMENT_DB_API", False):
import MySQLdb
import pymysql

dbapi.wrap_connect(
__name__,
MySQLdb,
pymysql.connect,
"connect",
"mysql",
{"database": "db", "port": "port", "host": "host", "user": "user"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"""
import logging

import MySQLdb
import pymysql

from paasng.accessories.services.utils import gen_unique_id, generate_password

Expand Down Expand Up @@ -56,11 +56,11 @@ def __init__(self, config):
self.auth_ip_list = config["auth_ip_list"]

def _get_connection(self):
connection = MySQLdb.connect(host=self.host, port=self.port, user=self.user, password=self.password)
connection = pymysql.connect(host=self.host, port=self.port, user=self.user, password=self.password)
return connection

def _get_app_connection(self, host, port, user, password):
connection = MySQLdb.connect(host=host, port=port, user=user, password=password)
connection = pymysql.connect(host=host, port=port, user=user, password=password)
return connection

def _change_auth_ips(self, connection, ip_list, database_name, database_user, database_password, auth_type):
Expand Down
5 changes: 2 additions & 3 deletions apiserver/paasng/paasng/accessories/smart_advisor/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
We undertake not to change the open source license (MIT license) applicable
to the current version of the project delivered to anyone in the future.
"""
from django.conf import settings
from django.db import models
from django.utils import timezone
from jsonfield import JSONField
from translated_fields import TranslatedFieldWithFallback

from paasng.accessories.publish.entrance.preallocated import get_bk_doc_url_prefix

from .constants import DeployFailurePatternType
from .tags import get_default_tagset, get_dynamic_tag

Expand Down Expand Up @@ -89,7 +88,7 @@ def get_affinity_tags_by_type(self, tag_type):

@property
def format_location(self) -> str:
return self.location.format(doc_url_prefix=get_bk_doc_url_prefix())
return self.location.format(paas_doc_url_prefix=settings.PAAS_DOCS_URL_PREFIX)


class DeployFailurePattern(models.Model):
Expand Down
4 changes: 2 additions & 2 deletions apiserver/paasng/paasng/core/core/storages/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
logger = logging.getLogger()


def make_sa_conn_string(config_dict, driver_type="mysqldb"):
def make_sa_conn_string(config_dict, driver_type="pymysql"):
"""Convert a django db dict to sqlalchemy string"""
return "mysql+%(driver_type)s://%(user)s:%(password)s@%(host)s:%(port)s/%(db)s?charset=utf8" % {
"driver_type": driver_type,
Expand Down Expand Up @@ -145,7 +145,7 @@ def _prepare_models(self):
def _create_engine(db_config) -> Engine:
echo = logger.level == logging.DEBUG
try:
dbstr = make_sa_conn_string(db_config, driver_type="mysqldb")
dbstr = make_sa_conn_string(db_config, driver_type="pymysql")
pool_options = db_config.get("POOL_OPTIONS") or DEFAULT_POOL_OPTIONS
return create_engine(dbstr, echo=echo, **pool_options)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions apiserver/paasng/paasng/misc/tracing/instrumentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def _instrument(self, **kwargs):
CeleryInstrumentor().instrument()

if getattr(settings, "OTEL_INSTRUMENT_DB_API", False):
import MySQLdb
import pymysql

dbapi.wrap_connect(
__name__,
MySQLdb,
pymysql.connect,
"connect",
"mysql",
{"database": "db", "port": "port", "host": "host", "user": "user"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@

{% block main_script %}
<script>
const bkDocsUrlPrefix = "{{ bk_docs_url_prefix }}"
const bkDocsUrlPrefix = "{{ paas_doc_url_prefix }}"
const bkPaaSUrl = "{{ bk_paas_url }}"
const specClsChoices = {{ spec_cls_choices | to_json }}

Expand Down Expand Up @@ -380,10 +380,10 @@
this.dialog.form.redirect_uri = bkPaaSUrl + "/backend/api/oauth/complete/github"
this.dialog.form.token_base_url = "https://github.com/login/oauth/access_token"
this.dialog.form.oauth_display_info_zh_cn = {
"auth_docs": bkDocsUrlPrefix + "/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/github_oauth"
"auth_docs": bkDocsUrlPrefix + "/BaseGuide/topics/paas/github_oauth"
}
this.dialog.form.oauth_display_info_en = {
"auth_docs": bkDocsUrlPrefix + "/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/github_oauth"
"auth_docs": bkDocsUrlPrefix + "/BaseGuide/topics/paas/github_oauth"
}
} else if (kind === "gitee") {
this.dialog.form.name = "gitee"
Expand All @@ -399,10 +399,10 @@
this.dialog.form.redirect_uri = bkPaaSUrl + "/backend/api/oauth/complete/gitee"
this.dialog.form.token_base_url = "https://gitee.com/oauth/token"
this.dialog.form.oauth_display_info_zh_cn = {
"auth_docs": bkDocsUrlPrefix + "/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/gitee_oauth"
"auth_docs": bkDocsUrlPrefix + "/BaseGuide/topics/paas/gitee_oauth"
}
this.dialog.form.oauth_display_info_en = {
"auth_docs": bkDocsUrlPrefix + "/markdown/PaaS/DevelopTools/BaseGuide/topics/paas/gitee_oauth"
"auth_docs": bkDocsUrlPrefix + "/BaseGuide/topics/paas/gitee_oauth"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from rest_framework.permissions import IsAuthenticated
from rest_framework.viewsets import GenericViewSet

from paasng.accessories.publish.entrance.preallocated import get_bk_doc_url_prefix
from paasng.infras.accounts.permissions.constants import SiteAction
from paasng.infras.accounts.permissions.global_site import site_perm_class
from paasng.plat_admin.admin42.serializers.sourcectl import SourceTypeSpecConfigSLZ
Expand Down Expand Up @@ -57,7 +56,7 @@ def get_context_data(self, **kwargs):

kwargs.update(
{
"bk_docs_url_prefix": get_bk_doc_url_prefix(),
"paas_doc_url_prefix": settings.PAAS_DOCS_URL_PREFIX,
"bk_paas_url": settings.BKPAAS_URL,
"spec_cls_choices": {
f"paasng.platform.sourcectl.type_specs.{spec_cls}": spec_cls for spec_cls in available_spec_cls
Expand Down
12 changes: 8 additions & 4 deletions apiserver/paasng/paasng/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,12 +1203,16 @@ def _build_file_handler(log_path: Path, filename: str, format: str) -> Dict:
BK_DOC_APP_ID = settings.get("BK_DOC_APP_ID", "bk_docs_center")

# 蓝鲸官网文档中心地址
BK_DOCS_URL_PREFIX = settings.get(
"BK_DOCS_URL_PREFIX", "https://bk.tencent.com/docs/markdown/PaaS/DevelopTools/BaseGuide"
)
BK_DOCS_URL_PREFIX = settings.get("BK_DOCS_URL_PREFIX", "https://bk.tencent.com/docs")

# PaaS 产品文档版本号,社区版年度大版本更新后需要更新对应的文档版本号
BK_PAAS_DOCS_VER = settings.get("BK_PAAS_DOCS_VER", "1.5")

# PaaS 产品文档前缀,蓝鲸文档中心最新的方案需要各个产品自己添加语言、版本号
PAAS_DOCS_URL_PREFIX = f"{BK_DOCS_URL_PREFIX}/markdown/ZH/PaaS/{BK_PAAS_DOCS_VER}"

# 平台FAQ 地址
PLATFORM_FAQ_URL = settings.get("PLATFORM_FAQ_URL", f"{BK_DOCS_URL_PREFIX}/markdown/PaaS/DevelopTools/BaseGuide/faq")
PLATFORM_FAQ_URL = settings.get("PLATFORM_FAQ_URL", f"{PAAS_DOCS_URL_PREFIX}/BaseGuide/faq")

# 是否有人工客服
SUPPORT_LIVE_AGENT = settings.get("SUPPORT_LIVE_AGENT", False)
Expand Down
4 changes: 2 additions & 2 deletions apiserver/paasng/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pathlib import Path
from typing import Dict, List, Union

import MySQLdb
import pymysql
import pytest
import sqlalchemy as sa
from blue_krill.monitoring.probe.mysql import transfer_django_db_settings
Expand Down Expand Up @@ -124,7 +124,7 @@ def _drop_legacy_db(request, django_db_keepdb: bool):
def drop_legacy_db_core():
mysql_config = asdict(transfer_django_db_settings(settings.PAAS_LEGACY_DBCONF))
db = mysql_config.pop("database")
connection = MySQLdb.connect(charset="utf8", **mysql_config)
connection = pymysql.connect(charset="utf8", **mysql_config)
with suppress(Exception), connection.cursor() as cursor:
cursor.execute(f"drop database {db}")

Expand Down
Loading

0 comments on commit 2b932b2

Please sign in to comment.