From 8901c0724b3cbba47a42f166004507462b3ad8f0 Mon Sep 17 00:00:00 2001 From: crayon <873217631@qq.com> Date: Thu, 15 Dec 2022 18:17:23 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=202.0=20Proxy=20data=20file=20endpoint?= =?UTF-8?q?=20=E6=B8=B2=E6=9F=93=E5=80=BC=E6=9C=89=E8=AF=AF=20(fixed=20#13?= =?UTF-8?q?40)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/backend/agent/tools.py | 12 +++++++++--- .../subscription/steps/agent_adapter/adapter.py | 7 ++++++- .../config_context/context_dataclass.py | 4 ++-- .../agent_adapter/config_context/context_helper.py | 6 ++++-- .../steps/agent_adapter/config_templates.py | 4 ++-- dev_log/2.2.32/crayon_202212151817.yaml | 3 +++ script_tools/agent_tools/agent2/setup_proxy.sh | 7 ++++--- 7 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 dev_log/2.2.32/crayon_202212151817.yaml diff --git a/apps/backend/agent/tools.py b/apps/backend/agent/tools.py index 9b829e915..4d54b0a64 100644 --- a/apps/backend/agent/tools.py +++ b/apps/backend/agent/tools.py @@ -76,6 +76,7 @@ def gen_nginx_download_url(nginx_ip: str) -> str: def fetch_gse_servers_info( + agent_setup_info: AgentSetupInfo, host: models.Host, host_ap: models.AccessPoint, proxies: List[models.Host], @@ -103,9 +104,14 @@ def fetch_gse_servers_info( # 优先使用接入点配置的内网回调地址 callback_url = host_ap.callback_url or settings.BKAPP_NODEMAN_CALLBACK_URL elif host.node_type == constants.NodeType.PROXY: - bt_file_server_hosts = host_ap.file_endpoint_info.outer_hosts - data_server_hosts = host_ap.data_endpoint_info.outer_hosts task_server_hosts = host_ap.cluster_endpoint_info.outer_hosts + if agent_setup_info.is_legacy: + data_server_hosts = host_ap.data_endpoint_info.outer_hosts + bt_file_server_hosts = host_ap.file_endpoint_info.outer_hosts + else: + # 对于新版本的 Agent,file data 的 endpoint 链接 proxy(可以是同台或同云区域内其他 proxy 的 file data) + data_server_hosts = [host.inner_ip or host.inner_ipv6] + bt_file_server_hosts = [host.inner_ip or host.inner_ipv6] package_url = host_ap.package_outer_url # 不同接入点使用不同的callback_url默认情况下接入点callback_url为空,先取接入点,为空的情况下使用原来的配置 callback_url = host_ap.outer_callback_url or settings.BKAPP_NODEMAN_OUTER_CALLBACK_URL @@ -168,7 +174,7 @@ def gen_commands( install_channel = install_channel or host.install_channel proxies = proxies if proxies is not None else host.proxies gse_servers_info: Dict[str, Any] = fetch_gse_servers_info( - host=host, host_ap=host_ap, proxies=proxies, install_channel=install_channel + agent_setup_info=agent_setup_info, host=host, host_ap=host_ap, proxies=proxies, install_channel=install_channel ) dest_dir: str = basic.suffix_slash(host.os_type, host_ap.get_agent_config(host.os_type)["temp_path"]) diff --git a/apps/backend/subscription/steps/agent_adapter/adapter.py b/apps/backend/subscription/steps/agent_adapter/adapter.py index dbedac7af..18c01bbd5 100644 --- a/apps/backend/subscription/steps/agent_adapter/adapter.py +++ b/apps/backend/subscription/steps/agent_adapter/adapter.py @@ -122,7 +122,12 @@ def _get_config( # 渲染配置 ch: context_helper.ConfigContextHelper = context_helper.ConfigContextHelper( - host=host, node_type=node_type, ap=ap, proxies=proxies, install_channel=install_channel + agent_setup_info=self.get_setup_info(), + host=host, + node_type=node_type, + ap=ap, + proxies=proxies, + install_channel=install_channel, ) return ch.render(target_config_tmpl_obj.content) diff --git a/apps/backend/subscription/steps/agent_adapter/config_context/context_dataclass.py b/apps/backend/subscription/steps/agent_adapter/config_context/context_dataclass.py index 4efdc37fc..2cd7c313b 100644 --- a/apps/backend/subscription/steps/agent_adapter/config_context/context_dataclass.py +++ b/apps/backend/subscription/steps/agent_adapter/config_context/context_dataclass.py @@ -175,8 +175,8 @@ class LogConfigContext(GseConfigContext): class DataMetricConfigContext(GseConfigContext): MODULE_ID = "DATA_METRIC" - exporter_port: int - exporter_ip: str = "::" + exporter_bind_port: int + exporter_bind_ip: str = "::" @dataclass diff --git a/apps/backend/subscription/steps/agent_adapter/config_context/context_helper.py b/apps/backend/subscription/steps/agent_adapter/config_context/context_helper.py index 4fbb892cd..214a10cd4 100644 --- a/apps/backend/subscription/steps/agent_adapter/config_context/context_helper.py +++ b/apps/backend/subscription/steps/agent_adapter/config_context/context_helper.py @@ -19,11 +19,13 @@ from apps.backend.utils.data_renderer import nested_render_data from apps.node_man import constants, models +from ..base import AgentSetupInfo from . import context_dataclass @dataclass class ConfigContextHelper: + agent_setup_info: AgentSetupInfo host: models.Host node_type: str ap: typing.Optional[models.AccessPoint] = None @@ -41,7 +43,7 @@ def __post_init__(self): agent_config: typing.Dict[str, typing.Any] = self.ap.get_agent_config(self.host.os_type) gse_servers_info: typing.Dict[str, typing.Any] = tools.fetch_gse_servers_info( - self.host, self.ap, self.proxies, self.install_channel + self.agent_setup_info, self.host, self.ap, self.proxies, self.install_channel ) log_path: str = agent_config["log_path"] @@ -112,7 +114,7 @@ def __post_init__(self): context_dataclass.DataConfigContext(ipc=agent_config.get("dataipc", "/var/run/ipc.state.report")), context_dataclass.FileConfigContext(), context_dataclass.LogConfigContext(path=log_path), - context_dataclass.DataMetricConfigContext(exporter_port=self.ap.port_config["data_prometheus_port"]), + context_dataclass.DataMetricConfigContext(exporter_bind_port=self.ap.port_config["data_prometheus_port"]), context_dataclass.DataAgentConfigContext( tcp_bind_port=self.ap.port_config["data_port"], tls_ca_file=proxy_tls_ca_file, diff --git a/apps/backend/subscription/steps/agent_adapter/config_templates.py b/apps/backend/subscription/steps/agent_adapter/config_templates.py index 84a211e95..f4bbc1c4f 100644 --- a/apps/backend/subscription/steps/agent_adapter/config_templates.py +++ b/apps/backend/subscription/steps/agent_adapter/config_templates.py @@ -82,8 +82,8 @@ "flush_interval_ms": __BK_GSE_LOG_FLUSH_INTERVAL_MS__ }, "metric": { - "exporter_bind_ip": "__BK_GSE_DATA_METRIC_EXPORTER_IP__", - "exporter_bind_port": __BK_GSE_DATA_METRIC_EXPORTER_PORT__ + "exporter_bind_ip": "__BK_GSE_DATA_METRIC_EXPORTER_BIND_IP__", + "exporter_bind_port": __BK_GSE_DATA_METRIC_EXPORTER_BIND_PORT__ }, "dataflow": { "receiver": [ diff --git a/dev_log/2.2.32/crayon_202212151817.yaml b/dev_log/2.2.32/crayon_202212151817.yaml new file mode 100644 index 000000000..7bc52d1ea --- /dev/null +++ b/dev_log/2.2.32/crayon_202212151817.yaml @@ -0,0 +1,3 @@ +--- +bugfix: + - "2.0 Proxy data file endpoint 渲染值有误 (fixed #1340)" diff --git a/script_tools/agent_tools/agent2/setup_proxy.sh b/script_tools/agent_tools/agent2/setup_proxy.sh index 20123aaec..06c0e399d 100755 --- a/script_tools/agent_tools/agent2/setup_proxy.sh +++ b/script_tools/agent_tools/agent2/setup_proxy.sh @@ -373,7 +373,7 @@ is_base64_command_exist() { fi } -check_heathz_by_gse () { +check_healthz_by_gse () { local result if [ -f "${GSE_AGENT_CONFIG_PATH}" ]; then result=$("${AGENT_SETUP_PATH}"/bin/gse_agent -f "${GSE_AGENT_CONFIG_PATH}" --healthz) @@ -516,10 +516,11 @@ setup_proxy () { register_agent_id - check_heathz_by_gse - start_proxy + # 由于 proxy endpoint 部分通过自身代理,需要等待 proxy 启动后再进行健康检查 + check_healthz_by_gse + log setup_proxy DONE "gse proxy setup successfully" }