mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-06 01:50:25 +08:00
将健康检查连续下线次数从1升级为3/修复健康检查可能导致DNS不断同步的问题
This commit is contained in:
@@ -301,11 +301,8 @@ func (this *NodeClusterDAO) UpdateClusterHealthCheck(tx *dbs.Tx, clusterId int64
|
||||
op := NewNodeClusterOperator()
|
||||
op.Id = clusterId
|
||||
op.HealthCheck = healthCheckJSON
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return this.NotifyUpdate(tx, clusterId)
|
||||
// 不需要通知更新
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
// CountAllEnabledClustersWithGrantId 计算使用某个认证的集群数量
|
||||
|
||||
@@ -1098,9 +1098,11 @@ func (this *NodeDAO) UpdateNodeUpCount(tx *dbs.Tx, nodeId int64, isUp bool, maxU
|
||||
return false, err
|
||||
}
|
||||
|
||||
if changed {
|
||||
err = this.NotifyDNSUpdate(tx, nodeId)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return true, err
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/dnsconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -45,6 +46,9 @@ var upgradeFuncs = []*upgradeVersion{
|
||||
{
|
||||
"0.2.8.1", upgradeV0_2_8_1,
|
||||
},
|
||||
{
|
||||
"0.3.0", upgradeV0_3_0,
|
||||
},
|
||||
}
|
||||
|
||||
// UpgradeSQLData 升级SQL数据
|
||||
@@ -324,3 +328,36 @@ func upgradeV0_2_8_1(db *dbs.DB) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// v0.3.0
|
||||
func upgradeV0_3_0(db *dbs.DB) error {
|
||||
// 升级健康检查
|
||||
ones, _, err := db.FindOnes("SELECT id,healthCheck FROM edgeNodeClusters WHERE state=1")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, one := range ones {
|
||||
var clusterId = one.GetInt64("id")
|
||||
var healthCheck = one.GetString("healthCheck")
|
||||
if len(healthCheck) == 0 {
|
||||
continue
|
||||
}
|
||||
var config = &serverconfigs.HealthCheckConfig{}
|
||||
err = json.Unmarshal([]byte(healthCheck), config)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if config.CountDown <= 1 {
|
||||
config.CountDown = 3
|
||||
configJSON, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
_, err = db.Exec("UPDATE edgeNodeClusters SET healthCheck=? WHERE id=?", string(configJSON), clusterId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -95,7 +95,7 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) {
|
||||
countTries = 10
|
||||
}
|
||||
if countTries < 1 {
|
||||
countTries = 1
|
||||
countTries = 3
|
||||
}
|
||||
|
||||
tryDelay := 1 * time.Second
|
||||
@@ -134,7 +134,7 @@ func (this *HealthCheckExecutor) Run() ([]*HealthCheckResult, error) {
|
||||
if healthCheckConfig.AutoDown {
|
||||
isChanged, err := models.SharedNodeDAO.UpdateNodeUpCount(nil, int64(result.Node.Id), result.IsOk, healthCheckConfig.CountUp, healthCheckConfig.CountDown)
|
||||
if err != nil {
|
||||
logs.Println("[HEALTH_CHECK]" + err.Error())
|
||||
remotelogs.Error("HEALTH_CHECK", err.Error())
|
||||
} else if isChanged {
|
||||
// 通知恢复或下线
|
||||
if result.IsOk {
|
||||
|
||||
Reference in New Issue
Block a user