fix domain third service health check bug

This commit is contained in:
barnettZQG 2020-02-19 16:32:19 +08:00
parent 61e4b2df4e
commit 51045e9a2b
4 changed files with 19 additions and 6 deletions

View File

@ -167,6 +167,7 @@ func dbInit() error {
if err := begin.Where("class_level=? and prefix=?", "server_source", "/v2/show").Find(&rac).Error; err != nil {
if err == gorm.ErrRecordNotFound {
data := map[string]string{
"/v2/cluster": "server_source",
"/v2/show": "server_source",
"/v2/opentsdb": "server_source",
"/v2/resources": "server_source",
@ -176,7 +177,7 @@ func dbInit() error {
"/v2/port": "server_source",
"/api/v1": "server_source",
"/v2/events": "server_source",
"/v2/gateway/ips": "server_source",
"/v2/gateway/ips": "server_source",
"/v2/gateway/ports": "server_source",
"/v2/nodes": "node_manager",
"/v2/job": "node_manager",

View File

@ -115,7 +115,7 @@ func (h *HTTPProbe) GetHTTPHealth() map[string]string {
}
logrus.Debugf("http probe check address; %s", address)
resp, err := c.Get(addr.String())
if resp.Body != nil {
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
if err != nil {

View File

@ -0,0 +1,8 @@
package prober
import "testing"
func TestParseTCPHostAddress(t *testing.T) {
re := parseTCPHostAddress("rm-2ze0xlsi14xz6q6sz.mysql.rds.aliyuncs.com", 3306)
t.Log(re)
}

View File

@ -415,6 +415,7 @@ func (t *thirdparty) createSubsetForAllEndpoint(as *v1.AppService, rbdep *v1.Rbd
func (t *thirdparty) runUpdate(event discovery.Event) {
updateAddress := func(as *v1.AppService, rbdep *v1.RbdEndpoint, ready bool) {
ad := validation.SplitEndpointAddress(rbdep.IP)
for _, ep := range as.GetEndpoints(true) {
var needUpdate bool
for idx, subset := range ep.Subsets {
@ -424,8 +425,8 @@ func (t *thirdparty) runUpdate(event discovery.Event) {
address = subset.NotReadyAddresses
}
for i, addr := range address {
if fmt.Sprintf("%s_%d", addr.IP, port.Port) == fmt.Sprintf("%s_%d", rbdep.IP, rbdep.Port) {
ad := validation.SplitEndpointAddress(rbdep.IP)
ipequal := fmt.Sprintf("%s_%d", addr.IP, port.Port) == fmt.Sprintf("%s_%d", rbdep.IP, rbdep.Port)
if (addr.IP == "1.1.1.1" && validation.IsDomainNotIP(ad)) || ipequal {
if validation.IsDomainNotIP(ad) {
rbdep.IP = "1.1.1.1"
}
@ -434,6 +435,7 @@ func (t *thirdparty) runUpdate(event discovery.Event) {
break
}
}
logrus.Debugf("not found need update address by %s", fmt.Sprintf("%s_%d", rbdep.IP, rbdep.Port))
}
}
if needUpdate {
@ -445,6 +447,8 @@ func (t *thirdparty) runUpdate(event discovery.Event) {
}
// do not have multiple ports, multiple addresses
removeAddress := func(as *v1.AppService, rbdep *v1.RbdEndpoint) {
ad := validation.SplitEndpointAddress(rbdep.IP)
for _, ep := range as.GetEndpoints(true) {
var needUpdate bool
var newSubsets []corev1.EndpointSubset
@ -453,13 +457,13 @@ func (t *thirdparty) runUpdate(event discovery.Event) {
for i, port := range subset.Ports {
address := append(subset.Addresses, subset.NotReadyAddresses...)
for j, addr := range address {
if fmt.Sprintf("%s_%d", addr.IP, port.Port) == fmt.Sprintf("%s_%d", rbdep.IP, rbdep.Port) {
ipequal := fmt.Sprintf("%s_%d", addr.IP, port.Port) == fmt.Sprintf("%s_%d", rbdep.IP, rbdep.Port)
if (addr.IP == "1.1.1.1" && validation.IsDomainNotIP(ad)) || ipequal {
//multiple port remove port, Instead remove the address
if len(subset.Ports) > 1 {
subset.Ports = append(subset.Ports[:i], subset.Ports[:i]...)
newSubsets = append(newSubsets, subset)
} else {
ad := validation.SplitEndpointAddress(rbdep.IP)
if validation.IsDomainNotIP(ad) {
rbdep.IP = "1.1.1.1"
}