AlexStocks commented on code in PR #3635:
URL: https://github.com/apache/dubbo-go/pull/3635#discussion_r3837948624
##########
remoting/nacos/builder.go:
##########
@@ -43,6 +44,55 @@ var (
newNacosConfigClient = nacosClient.NewNacosConfigClient
)
+// credentialIDs maps each distinct credential set to a small opaque id used
+// in pool keys. The credentials themselves stay in this process-local map and
+// never become part of the key, which may end up in logs.
+var (
+ credentialIDsMu sync.Mutex
+ credentialIDs = make(map[string]string)
+)
+
+func credentialID(url *common.URL) string {
+ tuple := strings.Join([]string{
+ url.GetParam(constant.NacosUsername, ""),
+ url.GetParam(constant.NacosPassword, ""),
+ url.GetParam(constant.NacosAccessKey, ""),
+ url.GetParam(constant.NacosSecretKey, ""),
+ }, "\n")
+ credentialIDsMu.Lock()
+ defer credentialIDsMu.Unlock()
+ id, ok := credentialIDs[tuple]
+ if !ok {
+ id = "cred" + strconv.Itoa(len(credentialIDs))
+ credentialIDs[tuple] = id
+ }
+ return id
+}
+
+// nacosClientPoolKey derives the gost client-pool key from the fields that
+// distinguish one nacos connection from another: server (endpoint/address),
+// namespace and the full credential set. Components pointing at the same
+// cluster (registry, config-center, metadata-report) resolve to the same key
+// and share one SDK client session instead of each opening its own.
+// Role-scoped client names must not be used as the key — they would defeat
+// the sharing.
+func nacosClientPoolKey(kind string, url *common.URL) string {
+ // GetNacosConfig ignores url.Location when an endpoint is set; mirror
+ // that here so URLs resolving to the same server set share one client.
+ server := url.GetParam(constant.NacosEndpoint, "")
Review Comment:
[P1] `url.Path` 只在没有 `NacosEndpoint`、需要从 `url.Location` 构造 `ServerConfig`
时才会成为 `ContextPath`;endpoint 模式下 `GetNacosConfig` 同时忽略 Location 和 Path,只把
endpoint 放进 `ClientConfig`。当前实现却无条件把 Path 加入 key。判别测试中,两个 URL 使用相同
`NacosEndpoint/namespace`、分别为 `/nacos` 和 `/custom`,`GetNacosConfig` 产生完全相同的
`ServerConfigs` 与 `ClientConfig`,但 pool key 不同,因此 config-center 和
metadata-report 仍会创建两个等价 SDK client,核心复用目标在 endpoint 部署下失效。请只在 endpoint 为空时纳入
Path,或直接从规范化后的 `GetNacosConfig` 结果派生池身份,并补 endpoint + 不同 Path 应共享的测试。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]