AlexStocks commented on code in PR #3213:
URL: https://github.com/apache/dubbo-go/pull/3213#discussion_r2899090661


##########
metrics/probe/server.go:
##########
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package probe
+
+import (
+       "context"
+       "net/http"
+       "sync"
+       "time"
+)
+
+import (
+       "github.com/dubbogo/gost/log/logger"
+)
+
+import (
+       "dubbo.apache.org/dubbo-go/v3/common/constant"
+       "dubbo.apache.org/dubbo-go/v3/common/extension"
+       "dubbo.apache.org/dubbo-go/v3/global"
+)
+
+type Config struct {
+       Enabled          bool
+       Port             string
+       LivenessPath     string
+       ReadinessPath    string
+       StartupPath      string
+       UseInternalState bool
+}
+
+var (
+       startOnce sync.Once

Review Comment:
   `startOnce` 是包级全局变量且无法重置。测试文件 `probe_test.go` 中的 `resetProbeState()` 
没有重置它,导致测试 `Init()` 行为的用例无法隔离——只有第一次 `Init()` 真正生效,后续调用全部被 Once 跳过。
   
   建议:将 `startOnce`、server 实例等状态封装进 `ProbeServer` 
struct,通过接口注入;或者至少在测试辅助函数中提供重置能力。



##########
config/metric_config.go:
##########
@@ -95,6 +106,16 @@ func (mc *MetricsConfig) Init(rc *RootConfig) error {
        if *mc.Enable {
                metrics.Init(mc.toURL())
        }
+       if mc.Probe != nil && mc.Probe.Enabled != nil && *mc.Probe.Enabled {
+               probe.Init(&probe.Config{

Review Comment:
   这里直接构造 `probe.Config` 调用 `probe.Init`,绕过了 `server/options.go` 中的 
`BuildProbeConfig`。两条路径的默认值填充逻辑不一致,未来 `BuildProbeConfig` 
加入新逻辑时,这条旧路径不会受益,容易产生行为差异。
   
   建议:统一使用 `BuildProbeConfig`,消除重复逻辑。



-- 
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]

Reply via email to