You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "Alanxtl (via GitHub)" <gi...@apache.org> on 2025/04/20 09:14:26 UTC
[PR] fix: Fix ignoring the domains field #667 & feat: supports tcp/http/https for health check [dubbo-go-pixiu]
Alanxtl opened a new pull request, #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668
<!-- Thanks for sending a pull request!
-->
**What this PR does**:
- fix #667: now can specify the domains field in the conf file as endpoint address.
- feat: Now can specify the protocol field in the conf file as the target protocol to be checked by health_checks, previewsly protocol only supports for tcp and the ```protocol``` field is neglected. Currently only supports tcp/http/https, for example:
```yaml
health_checks:
- protocol: "https"
timeout: 1s
interval: 2s
healthy_threshold: 4
unhealthy_threshold: 4
```
The new implmented health check also support specifying the domains field.
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2055841301
##########
pkg/cluster/healthcheck/tcp.go:
##########
@@ -14,30 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package healthcheck
import (
- "net"
"time"
)
-import (
- "github.com/apache/dubbo-go-pixiu/pkg/logger"
-)
-
type TCPChecker struct {
- addr string
+ address string
Review Comment:
在```pkg/model/base.go```里面和其他model里面定义的ip地址也都是使用address,我想的是和model里面定义的保持一致
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2831839826
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate failed**
Failed conditions
 [2 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "No-SilverBullet (via GitHub)" <gi...@apache.org>.
No-SilverBullet commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2059969511
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func TcpConn(address string, port string, timeout time.Duration) bool {
Review Comment:
这里的命名不好,返回bool类型,是个检查连接的动作,但是名字叫TcpConn,CheckXXX这种会更清楚一点,
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2061132901
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func CheckTcpConn(address string, port string, timeout time.Duration) bool {
Review Comment:
func CheckTcpConn(address, port string, timeout time.Duration) error {
normalizedAddress, err := normalizeAddress(address, port)
if err != nil {
return fmt.Errorf("[health check] address error: %w", err)
}
conn, err := net.DialTimeout("tcp", normalizedAddress, timeout)
if err != nil {
return fmt.Errorf("[health check] TCP connection to %s failed: %w", normalizedAddress, err)
}
defer conn.Close()
return nil
}
func normalizeAddress(address, port string) (string, error) {
host, parsedPort, err := net.SplitHostPort(address)
if err == nil {
if port != "" && parsedPort != port {
return net.JoinHostPort(host, port), nil
}
return address, nil
}
// 解析失败,可能是因为缺少端口
if port == "" {
return "", fmt.Errorf("no port specified and address is missing port: %s", address)
}
// 如果是缺少端口的错误
if strings.Contains(err.Error(), "missing port in address") {
return net.JoinHostPort(address, port), nil
}
return "", fmt.Errorf("invalid address format: %s", address)
}
你这个函数写的比较绕,我用个 gpt 重构了下,你看着改进下,新函数还支持 ipv6
测试代码1:
err := CheckTcpConn("qq.com", "80", 3*time.Second)
if err != nil {
logger.Warnf("TCP check failed: %v", err)
} else {
logger.Infof("TCP check succeeded")
}
测试代码2:
err := CheckTcpConn("[::1]", "8080", 2*time.Second)
可以把测试代码改成单测
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2826015395
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2057191419
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func TcpConn(tarAddr string, tarPort string, timeout time.Duration) bool {
Review Comment:
那就去掉这个前缀吧,无意义
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2055638314
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func TcpConn(tarAddr string, tarPort string, timeout time.Duration) bool {
Review Comment:
前缀 tar 嘛意思?
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2061159765
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func CheckTcpConn(address string, port string, timeout time.Duration) bool {
Review Comment:
单测已添加,但是这个gpt重构的逻辑不太合理,我改成这样了。
```go
func CheckTcpConn(address string, port string, timeout time.Duration) bool {
normalizedAddress, err := normalizeAddress(address, port)
if err != nil {
logger.Infof("[health check] address format for address \"%s\" failed, %s", address, err.Error())
return false
}
conn, err := net.DialTimeout("tcp", normalizedAddress, timeout)
if err != nil {
logger.Infof("[health check] health check for address \"%s\" failed, %s", normalizedAddress, err.Error())
return false
}
defer conn.Close()
return true
}
// normalizeAddress normalizes the address by ensuring it has the correct port.
// If the port field is empty, it will check if the address already has a port.
// - If the address has a port, it will return the address as is.
// - If the address does not have a port, it will return err.
//
// If the port field is not empty, it will check if the address's port matches the provided port.
// - If it matches, it will return the address as is.
// - If it does not match, it will return the address with the new port.
func normalizeAddress(address string, port string) (string, error) {
if port == "" {
_, _, err := net.SplitHostPort(address)
if err != nil {
return "", err
}
return address, nil
}
host, existingPort, err := net.SplitHostPort(address)
if err != nil {
if strings.Contains(err.Error(), "missing port in address") {
return net.JoinHostPort(strings.Trim(address, "[]"), port), nil
}
return "", err
}
if existingPort != port {
return net.JoinHostPort(host, port), nil
}
return address, nil
}
```
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: Fix ignoring the domains field #667 & feat: supports tcp/http/https for health check [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2817078976
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [21.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2052026559
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -20,25 +20,43 @@ package healthcheck
import (
"github.com/apache/dubbo-go-pixiu/pkg/logger"
Review Comment:
done
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2823418510
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2060121087
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func TcpConn(address string, port string, timeout time.Duration) bool {
Review Comment:
done, 改成了CheckTcpConn
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2823463620
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2051984759
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -20,25 +20,43 @@ package healthcheck
import (
"github.com/apache/dubbo-go-pixiu/pkg/logger"
Review Comment:
重新 format 下
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2817575792
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2817756146
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2055311206
##########
pkg/cluster/healthcheck/healthcheck_test.go:
##########
@@ -0,0 +1,88 @@
+/*
+ * 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 healthcheck
+
+import (
+ "log"
+ "net"
+ "strconv"
+ "sync"
+ "testing"
+ "time"
+)
+
+func TestTcpConn(t *testing.T) {
+
+ go func() {
+ listener, err := net.Listen("tcp", ":12347")
+ if err != nil {
+ log.Fatalf("listen failed: %v", err)
+ }
+
+ for {
+ client, err := listener.Accept()
+ if err != nil {
+ log.Printf("accept new client failed: %v", err)
+ continue
+ }
+
+ client.Close()
+ }
+ }()
+
+ time.Sleep(100 * time.Millisecond) // Give the server some time to start
+
+ type TestCase struct {
+ name string
+ addr string
+ port int
+ timeout time.Duration
+ shouldListen bool
+ expected bool
+ }
+
+ testCases := []TestCase{
+ {
+ name: "12347",
+ addr: "127.0.0.1",
+ port: 12347,
+ timeout: 100 * time.Millisecond,
+ expected: true,
+ },
+ {
+ name: "12348",
+ addr: "127.0.0.1",
+ port: 12348,
+ timeout: 100 * time.Millisecond,
+ expected: false,
+ },
+ }
+
+ var wg sync.WaitGroup
+
+ for _, tc := range testCases {
+ t.Run(tc.name, func(t *testing.T) {
+ actual := TcpConn(tc.addr, strconv.Itoa(tc.port), tc.timeout)
+ if actual != tc.expected {
+ t.Fail()
+ }
+ })
+ }
+
+ wg.Wait()
Review Comment:
The declared WaitGroup 'wg' is never used (no wg.Add or wg.Done calls) and is redundant in this test. Removing it would simplify the test code.
```suggestion
// Removed the redundant wg.Wait() call
```
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2057249939
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func TcpConn(tarAddr string, tarPort string, timeout time.Duration) bool {
Review Comment:
done
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix: Fix ignoring the domains field #667 & feat: supports tcp/http/https for health check [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2817113151
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2055637349
##########
pkg/cluster/healthcheck/tcp.go:
##########
@@ -14,30 +14,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package healthcheck
import (
- "net"
"time"
)
-import (
- "github.com/apache/dubbo-go-pixiu/pkg/logger"
-)
-
type TCPChecker struct {
- addr string
+ address string
Review Comment:
改这个变量名字有啥意义呢?addr也能望文生义呀
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2055841863
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func TcpConn(tarAddr string, tarPort string, timeout time.Duration) bool {
Review Comment:
target
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2830245144
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2061132901
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func CheckTcpConn(address string, port string, timeout time.Duration) bool {
Review Comment:
```go
func CheckTcpConn(address, port string, timeout time.Duration) error {
normalizedAddress, err := normalizeAddress(address, port)
if err != nil {
return fmt.Errorf("[health check] address error: %w", err)
}
conn, err := net.DialTimeout("tcp", normalizedAddress, timeout)
if err != nil {
return fmt.Errorf("[health check] TCP connection to %s failed: %w", normalizedAddress, err)
}
defer conn.Close()
return nil
}
func normalizeAddress(address, port string) (string, error) {
host, parsedPort, err := net.SplitHostPort(address)
if err == nil {
if port != "" && parsedPort != port {
return net.JoinHostPort(host, port), nil
}
return address, nil
}
// 解析失败,可能是因为缺少端口
if port == "" {
return "", fmt.Errorf("no port specified and address is missing port: %s", address)
}
// 如果是缺少端口的错误
if strings.Contains(err.Error(), "missing port in address") {
return net.JoinHostPort(address, port), nil
}
return "", fmt.Errorf("invalid address format: %s", address)
}
```
你这个函数写的比较绕,我用个 gpt 重构了下,你看着改进下,新函数还支持 ipv6
测试代码1:
err := CheckTcpConn("qq.com", "80", 3*time.Second)
if err != nil {
logger.Warnf("TCP check failed: %v", err)
} else {
logger.Infof("TCP check succeeded")
}
测试代码2:
err := CheckTcpConn("[::1]", "8080", 2*time.Second)
可以把测试代码改成单测
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2061159765
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func CheckTcpConn(address string, port string, timeout time.Duration) bool {
Review Comment:
单测已添加,但是这个改之后的逻辑不太合理,我改成这样了。
```go
func CheckTcpConn(address string, port string, timeout time.Duration) bool {
normalizedAddress, err := normalizeAddress(address, port)
if err != nil {
logger.Infof("[health check] address format for address \"%s\" failed, %s", address, err.Error())
return false
}
conn, err := net.DialTimeout("tcp", normalizedAddress, timeout)
if err != nil {
logger.Infof("[health check] health check for address \"%s\" failed, %s", normalizedAddress, err.Error())
return false
}
defer conn.Close()
return true
}
// normalizeAddress normalizes the address by ensuring it has the correct port.
// If the port field is empty, it will check if the address already has a port.
// - If the address has a port, it will return the address as is.
// - If the address does not have a port, it will return err.
//
// If the port field is not empty, it will check if the address's port matches the provided port.
// - If it matches, it will return the address as is.
// - If it does not match, it will return the address with the new port.
func normalizeAddress(address string, port string) (string, error) {
if port == "" {
_, _, err := net.SplitHostPort(address)
if err != nil {
return "", err
}
return address, nil
}
host, existingPort, err := net.SplitHostPort(address)
if err != nil {
if strings.Contains(err.Error(), "missing port in address") {
return net.JoinHostPort(strings.Trim(address, "[]"), port), nil
}
return "", err
}
if existingPort != port {
return net.JoinHostPort(host, port), nil
}
return address, nil
}
```
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2817477562
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2817118466
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [3 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#discussion_r2055507278
##########
pkg/cluster/healthcheck/utils.go:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 healthcheck
+
+import (
+ "net"
+ "strings"
+ "time"
+)
+
+import (
+ "github.com/apache/dubbo-go-pixiu/pkg/logger"
+)
+
+func TcpConn(tarAddr string, tarPort string, timeout time.Duration) bool {
+
+ if tarPort == "" {
+ // if tarPort is empty, tarAddr must has port
+ _, _, err := net.SplitHostPort(tarAddr)
+ if err != nil {
+ logger.Infof("[health check] no port specified, invalid address format: %s", tarAddr)
+ return false
+ }
+ } else {
+ // if tarPort is not empty, check tarAddr has port or not
+ realAddress, realPort, err := net.SplitHostPort(tarAddr)
+ if err != nil {
+ // if tarAddr has no port, add tarPort to tarAddr
+ if strings.Contains(err.Error(), "missing port in address") {
+ tarAddr = net.JoinHostPort(tarAddr, tarPort)
+ } else {
+ logger.Infof("[health check] invalid address format: %s", tarAddr)
+ return false
+ }
+ } else {
+ // if tarAddr has port, check if it is the same as tarPort
+ if realPort != tarPort {
+ tarAddr = net.JoinHostPort(realAddress, tarPort)
+ }
+ }
+ }
+
+ conn, err := net.DialTimeout("tcp", tarAddr, timeout)
+ if err != nil {
+ logger.Infof("[health check] http checker for host %s error: %v", tarAddr, err)
Review Comment:
Consider updating this log message to be protocol-agnostic since TcpConn is used for TCP, HTTP, and HTTPS checks. For example, use a generic message like "[health check] connection error for host %s: %v".
```suggestion
logger.Infof("[health check] connection error for host %s: %v", tarAddr, err)
```
##########
pkg/cluster/healthcheck/healthcheck.go:
##########
@@ -162,8 +167,33 @@ func (hc *HealthChecker) stopCheck(endpoint *model.Endpoint) {
}
func newChecker(endpoint *model.Endpoint, hc *HealthChecker) *EndpointChecker {
+ var checker Checker
+ switch hc.protocol {
Review Comment:
[nitpick] Consider normalizing the protocol string (e.g., converting it to lower case) before the switch to handle potential case variations in the configuration.
```suggestion
protocol := strings.ToLower(hc.protocol)
switch protocol {
```
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668#issuecomment-2831844187
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668) **Quality Gate passed**
Issues
 [7 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go-pixiu&pullRequest=668&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_coverage&view=list)
 [24.3% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go-pixiu&pullRequest=668&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go-pixiu&pullRequest=668)
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] feat: supports tcp/http/https for health check & fix: Fix ignoring the domains field #667 [dubbo-go-pixiu]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks merged PR #668:
URL: https://github.com/apache/dubbo-go-pixiu/pull/668
--
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: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org