diff --git a/cmd/server/agentmanager/PAgentMap.go b/cmd/server/agentmanager/PAgentMap.go index 0bcb14cc87515f4e7cfe772403b1b9d56d55093e..33ca15a853a479dbda627f6244862f49f824aaa9 100644 --- a/cmd/server/agentmanager/PAgentMap.go +++ b/cmd/server/agentmanager/PAgentMap.go @@ -86,7 +86,7 @@ func (am *AgentManager) InitMachineList() { func (am *AgentManager) UpdateMachineList() { machine_list, err := pluginclient.Global_Client.MachineList() if err != nil { - err = errors.Errorf(err.Error()) + err = errors.Errorf("%s", err.Error()) global.ERManager.ErrorTransmit("agentmanager", "error", err, true, true) } diff --git a/cmd/server/db/redismanager/redis.go b/cmd/server/db/redismanager/redis.go index 11619a23039ff50a380ac6ba74072f1f1cf97831..2b33dfd56304e407e42bc0c6baf37b61423f1339 100644 --- a/cmd/server/db/redismanager/redis.go +++ b/cmd/server/db/redismanager/redis.go @@ -1,6 +1,6 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. + * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: Wangjunqi123 * Date: Mon Nov 4 14:30:13 2024 +0800 @@ -200,9 +200,7 @@ func (r *RedisClient) UpdateTopoRunningAgentList(uuids []string, updateonce bool return } - if ok, err := global.IsIPandPORTValid(agentp.IP, agentmanager.Global_AgentManager.AgentPort); !ok { - err := errors.Errorf("%s:%s is unreachable (%s) %s", agentp.IP, agentmanager.Global_AgentManager.AgentPort, err.Error(), agentp.UUID) - global.ERManager.ErrorTransmit("db", "warn", err, false, false) + if ok := global.IsIPandPORTValid(agentp.IP, agentmanager.Global_AgentManager.AgentPort); !ok { abort_reason = append(abort_reason, fmt.Sprintf("%s:ip||port不可达", agentvalue.UUID)) return } @@ -296,9 +294,7 @@ func (r *RedisClient) ActiveHeartbeatDetection(uuids []string) { go func(a *agentmanager.Agent) { defer wg.Done() - if ok, _ := global.IsIPandPORTValid(a.IP, agentmanager.Global_AgentManager.AgentPort); !ok { - // err := errors.Errorf("%s:%s is unreachable (%s) %s", a.IP, agentmanager.Topo.AgentPort, err.Error(), a.UUID) - // resourcemanage.ErrorTransmit("db", "warn", err, false, false) + if ok := global.IsIPandPORTValid(a.IP, agentmanager.Global_AgentManager.AgentPort); !ok { return } @@ -322,9 +318,7 @@ func (r *RedisClient) ActiveHeartbeatDetection(uuids []string) { return } - if ok, _ := global.IsIPandPORTValid(agent.IP, agentmanager.Global_AgentManager.AgentPort); !ok { - // err := errors.Errorf("%s:%s is unreachable (%s) %s", agent.IP, agentmanager.Topo.AgentPort, err.Error(), agent.UUID) - // resourcemanage.ErrorTransmit("db", "warn", err, false, false) + if ok := global.IsIPandPORTValid(agent.IP, agentmanager.Global_AgentManager.AgentPort); !ok { return } diff --git a/cmd/server/global/IsIPandPORTValid.go b/cmd/server/global/IsIPandPORTValid.go index b31e67c18acc2905f4bacb9d8f4b59d04eab723f..fde4a64459b1949184443b9fc6fe8200b138b2e8 100644 --- a/cmd/server/global/IsIPandPORTValid.go +++ b/cmd/server/global/IsIPandPORTValid.go @@ -1,6 +1,6 @@ /* * Copyright (c) KylinSoft Co., Ltd. 2024.All rights reserved. - * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. + * PilotGo-plugin-topology licensed under the Mulan Permissive Software License, Version 2. * See LICENSE file for more details. * Author: Wangjunqi123 * Date: Mon Nov 4 14:30:13 2024 +0800 @@ -11,25 +11,29 @@ import ( "fmt" "net" "time" + + "github.com/pkg/errors" ) const ( - req_timeout = 1000 * time.Millisecond + req_timeout = 500 * time.Millisecond ) // 检测IP是否可达 -func IsIPandPORTValid(ip, port string) (bool, error) { +func IsIPandPORTValid(ip, port string) bool { addr, err := net.ResolveIPAddr("ip", ip) if err != nil { - return false, err + ERManager.ErrorTransmit("global", "error", errors.Errorf("fail to judge addr valid: %s", err.Error()), false, false) + return false } // 设置连接超时时间 conn, err := net.DialTimeout("tcp", fmt.Sprintf("%s:%s", addr.String(), port), req_timeout) if err != nil { - return false, err + ERManager.ErrorTransmit("global", "error", errors.Errorf("fail to judge addr valid: %s", err.Error()), false, false) + return false } conn.Close() - return true, nil + return true }