Skip to content

Commit

Permalink
bugfix: 2.0 Proxy data file endpoint 渲染值有误 (fixed #1340)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhuoZhuoCrayon committed Dec 22, 2022
1 parent acd128c commit 8901c07
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 13 deletions.
12 changes: 9 additions & 3 deletions apps/backend/agent/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"])

Expand Down
7 changes: 6 additions & 1 deletion apps/backend/subscription/steps/agent_adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
3 changes: 3 additions & 0 deletions dev_log/2.2.32/crayon_202212151817.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
bugfix:
- "2.0 Proxy data file endpoint 渲染值有误 (fixed #1340)"
7 changes: 4 additions & 3 deletions script_tools/agent_tools/agent2/setup_proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"
}

Expand Down

0 comments on commit 8901c07

Please sign in to comment.