v1.5.1 增强程序稳定性
This commit is contained in:
@@ -39,6 +39,7 @@ type LogsIngestRow struct {
|
||||
RequestBody string
|
||||
ResponseHeaders string
|
||||
ResponseBody string
|
||||
Attrs string
|
||||
}
|
||||
|
||||
// ListFilter 列表查询条件(与 ListHTTPAccessLogsRequest 对齐)
|
||||
@@ -178,7 +179,7 @@ func (s *LogsIngestStore) List(ctx context.Context, f ListFilter) (rows []*LogsI
|
||||
|
||||
// 列表查询不 SELECT 大字段(request_headers / request_body / response_headers / response_body),
|
||||
// 避免每次翻页读取 GB 级数据。详情查看时通过 FindByTraceId 单独获取。
|
||||
query := fmt.Sprintf("SELECT timestamp, node_id, cluster_id, server_id, host, ip, method, path, status, bytes_in, bytes_out, cost_ms, ua, referer, log_type, trace_id, firewall_policy_id, firewall_rule_group_id, firewall_rule_set_id, firewall_rule_id FROM %s WHERE %s ORDER BY %s LIMIT %d",
|
||||
query := fmt.Sprintf("SELECT timestamp, node_id, cluster_id, server_id, host, ip, method, path, status, bytes_in, bytes_out, cost_ms, ua, referer, log_type, trace_id, firewall_policy_id, firewall_rule_group_id, firewall_rule_set_id, firewall_rule_id, attrs FROM %s WHERE %s ORDER BY %s LIMIT %d",
|
||||
table, where, orderBy, limit+1)
|
||||
|
||||
var rawRows []map[string]interface{}
|
||||
@@ -225,7 +226,7 @@ func (s *LogsIngestStore) FindByTraceId(ctx context.Context, traceId string) (*L
|
||||
}
|
||||
|
||||
table := quoteIdent("logs_ingest")
|
||||
query := fmt.Sprintf("SELECT timestamp, node_id, cluster_id, server_id, host, ip, method, path, status, bytes_in, bytes_out, cost_ms, ua, referer, log_type, trace_id, firewall_policy_id, firewall_rule_group_id, firewall_rule_set_id, firewall_rule_id, request_headers, request_body, response_headers, response_body FROM %s WHERE trace_id = '%s' LIMIT 1",
|
||||
query := fmt.Sprintf("SELECT timestamp, node_id, cluster_id, server_id, host, ip, method, path, status, bytes_in, bytes_out, cost_ms, ua, referer, log_type, trace_id, firewall_policy_id, firewall_rule_group_id, firewall_rule_set_id, firewall_rule_id, request_headers, request_body, response_headers, response_body, attrs FROM %s WHERE trace_id = '%s' LIMIT 1",
|
||||
table, escapeString(traceId))
|
||||
|
||||
var rawRows []map[string]interface{}
|
||||
@@ -333,6 +334,7 @@ func mapToLogsIngestRow(m map[string]interface{}) *LogsIngestRow {
|
||||
r.RequestBody = str("request_body")
|
||||
r.ResponseHeaders = str("response_headers")
|
||||
r.ResponseBody = str("response_body")
|
||||
r.Attrs = str("attrs")
|
||||
return r
|
||||
}
|
||||
|
||||
@@ -401,6 +403,14 @@ func RowToPB(r *LogsIngestRow) *pb.HTTPAccessLog {
|
||||
a.RequestBody = []byte(r.RequestBody)
|
||||
}
|
||||
|
||||
// 扩展属性(cache.status 等)
|
||||
if r.Attrs != "" {
|
||||
var attrs map[string]string
|
||||
if err := json.Unmarshal([]byte(r.Attrs), &attrs); err == nil && len(attrs) > 0 {
|
||||
a.Attrs = attrs
|
||||
}
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package teaconst
|
||||
|
||||
const (
|
||||
Version = "1.5.0" //1.3.9
|
||||
Version = "1.5.1" //1.3.9
|
||||
|
||||
ProductName = "Edge API"
|
||||
ProcessName = "edge-api"
|
||||
@@ -17,6 +17,6 @@ const (
|
||||
|
||||
// 其他节点版本号,用来检测是否有需要升级的节点
|
||||
|
||||
NodeVersion = "1.5.0" //1.3.8.2
|
||||
NodeVersion = "1.5.1" //1.3.8.2
|
||||
)
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
package teaconst
|
||||
|
||||
const (
|
||||
DNSNodeVersion = "1.5.0" //1.3.8.2
|
||||
UserNodeVersion = "1.5.0" //1.3.8.2
|
||||
ReportNodeVersion = "1.5.0"
|
||||
DNSNodeVersion = "1.5.1" //1.3.8.2
|
||||
UserNodeVersion = "1.5.1" //1.3.8.2
|
||||
ReportNodeVersion = "1.5.1"
|
||||
|
||||
DefaultMaxNodes int32 = 50
|
||||
)
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestDB_Env(t *testing.T) {
|
||||
|
||||
func TestDB_Instance(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
db, err := sql.Open("mysql", "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s")
|
||||
db, err := sql.Open("mysql", "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s")
|
||||
if err != nil {
|
||||
t.Fatal(i, "open:", err)
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
func TestNewHTTPAccessLogManager(t *testing.T) {
|
||||
var config = &dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
Connections: struct {
|
||||
Pool int `yaml:"pool"`
|
||||
@@ -45,7 +45,7 @@ func TestNewHTTPAccessLogManager(t *testing.T) {
|
||||
func TestHTTPAccessLogManager_FindTableNames(t *testing.T) {
|
||||
var config = &dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
Connections: struct {
|
||||
Pool int `yaml:"pool"`
|
||||
@@ -84,7 +84,7 @@ func TestHTTPAccessLogManager_FindTableNames(t *testing.T) {
|
||||
func TestHTTPAccessLogManager_FindTables(t *testing.T) {
|
||||
var config = &dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
Connections: struct {
|
||||
Pool int `yaml:"pool"`
|
||||
@@ -123,7 +123,7 @@ func TestHTTPAccessLogManager_FindTables(t *testing.T) {
|
||||
func TestHTTPAccessLogManager_FindLastTable(t *testing.T) {
|
||||
var config = &dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
Connections: struct {
|
||||
Pool int `yaml:"pool"`
|
||||
@@ -162,7 +162,7 @@ func TestHTTPAccessLogManager_FindLastTable(t *testing.T) {
|
||||
func TestHTTPAccessLogManager_FindPartitionTable(t *testing.T) {
|
||||
var config = &dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_log?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
Connections: struct {
|
||||
Pool int `yaml:"pool"`
|
||||
|
||||
@@ -6,15 +6,15 @@ import "github.com/iwind/TeaGo/dbs"
|
||||
type HTTPDNSCluster struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
Name string `field:"name"` // 集群名称
|
||||
IsOn bool `field:"isOn"` // 是否启用
|
||||
IsDefault bool `field:"isDefault"` // 默认集群
|
||||
IsOn uint8 `field:"isOn"` // 是否启用(tinyint unsigned)
|
||||
IsDefault uint8 `field:"isDefault"` // 默认集群(tinyint unsigned)
|
||||
ServiceDomain string `field:"serviceDomain"` // 服务域名
|
||||
DefaultTTL int32 `field:"defaultTTL"` // 默认TTL
|
||||
FallbackTimeoutMs int32 `field:"fallbackTimeoutMs"` // 降级超时
|
||||
InstallDir string `field:"installDir"` // 安装目录
|
||||
TLSPolicy dbs.JSON `field:"tlsPolicy"` // TLS策略
|
||||
AutoRemoteStart bool `field:"autoRemoteStart"` // 自动远程启动
|
||||
AccessLogIsOn bool `field:"accessLogIsOn"` // 访问日志是否开启
|
||||
AutoRemoteStart uint8 `field:"autoRemoteStart"` // 自动远程启动(tinyint unsigned)
|
||||
AccessLogIsOn uint8 `field:"accessLogIsOn"` // 访问日志是否开启(tinyint unsigned)
|
||||
TimeZone string `field:"timeZone"` // 时区
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
UpdatedAt uint64 `field:"updatedAt"` // 修改时间
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestIsLocalAddr(t *testing.T) {
|
||||
a.IsTrue(dbutils.IsLocalAddr("127.0.0.1"))
|
||||
a.IsTrue(dbutils.IsLocalAddr("localhost"))
|
||||
a.IsTrue(dbutils.IsLocalAddr("::1"))
|
||||
a.IsTrue(dbutils.IsLocalAddr("127.0.0.1:3306"))
|
||||
a.IsTrue(dbutils.IsLocalAddr("127.0.0.1:3308"))
|
||||
a.IsFalse(dbutils.IsLocalAddr("192.168.2.200"))
|
||||
a.IsFalse(dbutils.IsLocalAddr("192.168.2.200:3306"))
|
||||
}
|
||||
|
||||
@@ -198,6 +198,21 @@ func (this *DeployManager) FindHTTPDNSNodeFile(os string, arch string) *DeployFi
|
||||
return nil
|
||||
}
|
||||
|
||||
// LatestNodeVersion 获取部署目录中边缘节点的最新版本号
|
||||
func (this *DeployManager) LatestNodeVersion() string {
|
||||
return latestVersion(this.LoadNodeFiles())
|
||||
}
|
||||
|
||||
// LatestNSNodeVersion 获取部署目录中DNS节点的最新版本号
|
||||
func (this *DeployManager) LatestNSNodeVersion() string {
|
||||
return latestVersion(this.LoadNSNodeFiles())
|
||||
}
|
||||
|
||||
// LatestHTTPDNSNodeVersion 获取部署目录中HTTPDNS节点的最新版本号
|
||||
func (this *DeployManager) LatestHTTPDNSNodeVersion() string {
|
||||
return latestVersion(this.LoadHTTPDNSNodeFiles())
|
||||
}
|
||||
|
||||
// Reload 重置缓存
|
||||
func (this *DeployManager) Reload() {
|
||||
this.locker.Lock()
|
||||
@@ -207,3 +222,13 @@ func (this *DeployManager) Reload() {
|
||||
this.nsNodeFiles = nil
|
||||
this.httpdnsNodeFiles = nil
|
||||
}
|
||||
|
||||
func latestVersion(files []*DeployFile) string {
|
||||
var latest string
|
||||
for _, f := range files {
|
||||
if len(latest) == 0 || stringutil.VersionCompare(f.Version, latest) > 0 {
|
||||
latest = f.Version
|
||||
}
|
||||
}
|
||||
return latest
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@ func toPBCluster(cluster *models.HTTPDNSCluster) *pb.HTTPDNSCluster {
|
||||
}
|
||||
return &pb.HTTPDNSCluster{
|
||||
Id: int64(cluster.Id),
|
||||
IsOn: cluster.IsOn,
|
||||
IsDefault: cluster.IsDefault,
|
||||
IsOn: cluster.IsOn > 0,
|
||||
IsDefault: cluster.IsDefault > 0,
|
||||
Name: cluster.Name,
|
||||
ServiceDomain: cluster.ServiceDomain,
|
||||
DefaultTTL: cluster.DefaultTTL,
|
||||
@@ -26,8 +26,8 @@ func toPBCluster(cluster *models.HTTPDNSCluster) *pb.HTTPDNSCluster {
|
||||
TlsPolicyJSON: cluster.TLSPolicy,
|
||||
CreatedAt: int64(cluster.CreatedAt),
|
||||
UpdatedAt: int64(cluster.UpdatedAt),
|
||||
AutoRemoteStart: cluster.AutoRemoteStart,
|
||||
AccessLogIsOn: cluster.AccessLogIsOn,
|
||||
AutoRemoteStart: cluster.AutoRemoteStart > 0,
|
||||
AccessLogIsOn: cluster.AccessLogIsOn > 0,
|
||||
TimeZone: cluster.TimeZone,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ func readHTTPDNSDefaultClusterIdList(tx *dbs.Tx) ([]int64, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cluster != nil && cluster.IsOn {
|
||||
if cluster != nil && cluster.IsOn > 0 {
|
||||
validIds = append(validIds, id)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ func (this *HTTPDNSClusterService) FindHTTPDNSCluster(ctx context.Context, req *
|
||||
}
|
||||
if cluster != nil {
|
||||
_ = grpc.SetHeader(ctx, metadata.Pairs(
|
||||
"x-httpdns-auto-remote-start", fmt.Sprintf("%t", cluster.AutoRemoteStart),
|
||||
"x-httpdns-access-log-is-on", fmt.Sprintf("%t", cluster.AccessLogIsOn),
|
||||
"x-httpdns-auto-remote-start", fmt.Sprintf("%t", cluster.AutoRemoteStart > 0),
|
||||
"x-httpdns-access-log-is-on", fmt.Sprintf("%t", cluster.AccessLogIsOn > 0),
|
||||
"x-httpdns-time-zone", cluster.TimeZone,
|
||||
))
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ package nameservers
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
@@ -475,7 +474,7 @@ func (this *NSNodeService) FindLatestNSNodeVersion(ctx context.Context, req *pb.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &pb.FindLatestNSNodeVersionResponse{Version: teaconst.DNSNodeVersion}, nil
|
||||
return &pb.FindLatestNSNodeVersionResponse{Version: installers.SharedDeployManager.LatestNSNodeVersion()}, nil
|
||||
}
|
||||
|
||||
// DownloadNSNodeInstallationFile 下载最新DNS节点安装文件
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/errors"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/installers"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/rpc/tasks"
|
||||
rpcutils "github.com/TeaOSLab/EdgeAPI/internal/rpc/utils"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
||||
@@ -689,17 +690,20 @@ func (this *AdminService) ComposeAdminDashboard(ctx context.Context, req *pb.Com
|
||||
|
||||
// 边缘节点升级信息
|
||||
{
|
||||
upgradeInfo := &pb.ComposeAdminDashboardResponse_UpgradeInfo{
|
||||
NewVersion: teaconst.NodeVersion,
|
||||
var nodeVersion = installers.SharedDeployManager.LatestNodeVersion()
|
||||
if len(nodeVersion) > 0 {
|
||||
upgradeInfo := &pb.ComposeAdminDashboardResponse_UpgradeInfo{
|
||||
NewVersion: nodeVersion,
|
||||
}
|
||||
this.BeginTag(ctx, "SharedNodeDAO.CountAllLowerVersionNodes")
|
||||
countNodes, err := models.SharedNodeDAO.CountAllLowerVersionNodes(tx, upgradeInfo.NewVersion)
|
||||
this.EndTag(ctx, "SharedNodeDAO.CountAllLowerVersionNodes")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
upgradeInfo.CountNodes = countNodes
|
||||
result.NodeUpgradeInfo = upgradeInfo
|
||||
}
|
||||
this.BeginTag(ctx, "SharedNodeDAO.CountAllLowerVersionNodes")
|
||||
countNodes, err := models.SharedNodeDAO.CountAllLowerVersionNodes(tx, upgradeInfo.NewVersion)
|
||||
this.EndTag(ctx, "SharedNodeDAO.CountAllLowerVersionNodes")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
upgradeInfo.CountNodes = countNodes
|
||||
result.NodeUpgradeInfo = upgradeInfo
|
||||
}
|
||||
|
||||
// API节点升级信息
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
teaconst "github.com/TeaOSLab/EdgeAPI/internal/const"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/installers"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/regions"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models/stats"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
@@ -36,17 +37,20 @@ func (this *AdminService) composeAdminDashboardExt(tx *dbs.Tx, ctx context.Conte
|
||||
|
||||
// DNS节点升级信息
|
||||
if isPlus {
|
||||
upgradeInfo := &pb.ComposeAdminDashboardResponse_UpgradeInfo{
|
||||
NewVersion: teaconst.DNSNodeVersion,
|
||||
var dnsNodeVersion = installers.SharedDeployManager.LatestNSNodeVersion()
|
||||
if len(dnsNodeVersion) > 0 {
|
||||
upgradeInfo := &pb.ComposeAdminDashboardResponse_UpgradeInfo{
|
||||
NewVersion: dnsNodeVersion,
|
||||
}
|
||||
this.BeginTag(ctx, "SharedNSNodeDAO.CountAllLowerVersionNodes")
|
||||
countNodes, err := models.SharedNSNodeDAO.CountAllLowerVersionNodes(tx, upgradeInfo.NewVersion)
|
||||
this.EndTag(ctx, "SharedNSNodeDAO.CountAllLowerVersionNodes")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
upgradeInfo.CountNodes = countNodes
|
||||
result.NsNodeUpgradeInfo = upgradeInfo
|
||||
}
|
||||
this.BeginTag(ctx, "SharedNSNodeDAO.CountAllLowerVersionNodes")
|
||||
countNodes, err := models.SharedNSNodeDAO.CountAllLowerVersionNodes(tx, upgradeInfo.NewVersion)
|
||||
this.EndTag(ctx, "SharedNSNodeDAO.CountAllLowerVersionNodes")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
upgradeInfo.CountNodes = countNodes
|
||||
result.NsNodeUpgradeInfo = upgradeInfo
|
||||
}
|
||||
|
||||
// Report节点升级信息
|
||||
|
||||
@@ -46,6 +46,7 @@ func EnsureClickHouseTables() error {
|
||||
request_body String DEFAULT '' CODEC(ZSTD(3)),
|
||||
response_headers String DEFAULT '' CODEC(ZSTD(3)),
|
||||
response_body String DEFAULT '' CODEC(ZSTD(3)),
|
||||
attrs String DEFAULT '' CODEC(ZSTD(3)),
|
||||
INDEX idx_trace_id trace_id TYPE bloom_filter(0.01) GRANULARITY 4,
|
||||
INDEX idx_ip ip TYPE bloom_filter(0.01) GRANULARITY 4,
|
||||
INDEX idx_host host TYPE tokenbf_v1(10240, 3, 0) GRANULARITY 4,
|
||||
@@ -128,5 +129,19 @@ SETTINGS index_granularity = 8192`,
|
||||
}
|
||||
}
|
||||
|
||||
// v1.5.1: 为 logs_ingest 添加 attrs 列(存储 cache.status 等扩展属性)
|
||||
upgradeSQLs := []string{
|
||||
`ALTER TABLE logs_ingest ADD COLUMN IF NOT EXISTS attrs String DEFAULT '' CODEC(ZSTD(3)) AFTER response_body`,
|
||||
}
|
||||
for _, sql := range upgradeSQLs {
|
||||
stmt := strings.TrimSpace(sql)
|
||||
if len(stmt) == 0 {
|
||||
continue
|
||||
}
|
||||
if err := client.Execute(ctx, stmt); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -10,7 +10,7 @@ import (
|
||||
func TestSQLDump_Dump(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -53,7 +53,7 @@ func TestSQLDump_Dump(t *testing.T) {
|
||||
func TestSQLDump_Apply(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -9,7 +9,7 @@ func TestSQLExecutor_Run(t *testing.T) {
|
||||
var executor = NewSQLExecutor(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Prefix: "edge",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_new?charset=utf8mb4&multiStatements=true",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_new?charset=utf8mb4&multiStatements=true",
|
||||
})
|
||||
err := executor.Run(false)
|
||||
if err != nil {
|
||||
@@ -22,7 +22,7 @@ func TestSQLExecutor_checkCluster(t *testing.T) {
|
||||
var executor = NewSQLExecutor(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Prefix: "edge",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_new?charset=utf8mb4&multiStatements=true",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_new?charset=utf8mb4&multiStatements=true",
|
||||
})
|
||||
db, err := dbs.NewInstanceFromConfig(executor.dbConfig)
|
||||
if err != nil {
|
||||
@@ -43,7 +43,7 @@ func TestSQLExecutor_checkMetricItems(t *testing.T) {
|
||||
var executor = NewSQLExecutor(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Prefix: "edge",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_new?charset=utf8mb4&multiStatements=true",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_new?charset=utf8mb4&multiStatements=true",
|
||||
})
|
||||
db, err := dbs.NewInstanceFromConfig(executor.dbConfig)
|
||||
if err != nil {
|
||||
@@ -64,7 +64,7 @@ func TestSQLExecutor_checkNS(t *testing.T) {
|
||||
var executor = NewSQLExecutor(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Prefix: "edge",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_new?charset=utf8mb4&multiStatements=true",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_new?charset=utf8mb4&multiStatements=true",
|
||||
})
|
||||
db, err := dbs.NewInstanceFromConfig(executor.dbConfig)
|
||||
if err != nil {
|
||||
@@ -85,7 +85,7 @@ func TestSQLExecutor_checkClientAgents(t *testing.T) {
|
||||
var executor = NewSQLExecutor(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Prefix: "edge",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&multiStatements=true",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&multiStatements=true",
|
||||
})
|
||||
db, err := dbs.NewInstanceFromConfig(executor.dbConfig)
|
||||
if err != nil {
|
||||
|
||||
@@ -116,6 +116,9 @@ var upgradeFuncs = []*upgradeVersion{
|
||||
{
|
||||
"1.4.9", upgradeV1_4_9,
|
||||
},
|
||||
{
|
||||
"1.5.1", upgradeV1_5_1,
|
||||
},
|
||||
}
|
||||
|
||||
// UpgradeSQLData 升级SQL数据
|
||||
@@ -1292,6 +1295,27 @@ func upgradeV1_4_9(db *dbs.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// v1.5.1
|
||||
func upgradeV1_5_1(db *dbs.DB) error {
|
||||
// 补充 httpdnsClusterIds 字段(1.4.8 升级可能因版本号跳过未执行)
|
||||
_, err := db.Exec("ALTER TABLE `edgeUsers` ADD COLUMN `httpdnsClusterIds` text DEFAULT NULL COMMENT 'HTTPDNS关联集群ID列表'")
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "Duplicate column") {
|
||||
// 字段已存在,忽略
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 确保 HTTPDNS 相关表存在
|
||||
err = createHTTPDNSTables(db)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func createHTTPDNSTables(db *dbs.DB) error {
|
||||
sqls := []string{
|
||||
"CREATE TABLE IF NOT EXISTS `edgeHTTPDNSClusters` (`id` bigint unsigned NOT NULL AUTO_INCREMENT,`name` varchar(255) DEFAULT NULL,`isOn` tinyint unsigned DEFAULT '1',`isDefault` tinyint unsigned DEFAULT '0',`serviceDomain` varchar(255) DEFAULT NULL,`defaultTTL` int unsigned DEFAULT '30',`fallbackTimeoutMs` int unsigned DEFAULT '300',`installDir` varchar(255) DEFAULT '/root/edge-httpdns',`tlsPolicy` json DEFAULT NULL,`autoRemoteStart` tinyint unsigned DEFAULT '0',`accessLogIsOn` tinyint unsigned DEFAULT '0',`timeZone` varchar(128) NOT NULL DEFAULT '',`createdAt` bigint unsigned DEFAULT '0',`updatedAt` bigint unsigned DEFAULT '0',`state` tinyint unsigned DEFAULT '1',PRIMARY KEY (`id`),KEY `name` (`name`),KEY `isDefault` (`isDefault`),KEY `state` (`state`)) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='HTTPDNS集群配置表(默认TTL、回退超时、服务域名等)'",
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
func TestUpgradeSQLData_v0_5_6(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -31,7 +31,7 @@ func TestUpgradeSQLData_v0_5_6(t *testing.T) {
|
||||
func TestUpgradeSQLData_v1_3_4(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
func TestUpgradeSQLData_v0_5_6(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -29,7 +29,7 @@ func TestUpgradeSQLData_v0_5_6(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_5_8(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -48,7 +48,7 @@ func TestUpgradeSQLData_v0_5_8(t *testing.T) {
|
||||
func TestUpgradeSQLData_v1_2_9(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
func TestUpgradeSQLData(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_new?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_new?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -27,7 +27,7 @@ func TestUpgradeSQLData(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_3_1(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge_new?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge_new?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -46,7 +46,7 @@ func TestUpgradeSQLData_v0_3_1(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_3_2(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -65,7 +65,7 @@ func TestUpgradeSQLData_v0_3_2(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_3_3(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -84,7 +84,7 @@ func TestUpgradeSQLData_v0_3_3(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_3_7(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -103,7 +103,7 @@ func TestUpgradeSQLData_v0_3_7(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_4_0(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -122,7 +122,7 @@ func TestUpgradeSQLData_v0_4_0(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_4_1(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -141,7 +141,7 @@ func TestUpgradeSQLData_v0_4_1(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_4_5(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -160,7 +160,7 @@ func TestUpgradeSQLData_v0_4_5(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_4_7(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -179,7 +179,7 @@ func TestUpgradeSQLData_v0_4_7(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_4_8(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -198,7 +198,7 @@ func TestUpgradeSQLData_v0_4_8(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_4_9(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -217,7 +217,7 @@ func TestUpgradeSQLData_v0_4_9(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_4_11(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -236,7 +236,7 @@ func TestUpgradeSQLData_v0_4_11(t *testing.T) {
|
||||
func TestUpgradeSQLData_v0_5_3(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -255,7 +255,7 @@ func TestUpgradeSQLData_v0_5_3(t *testing.T) {
|
||||
func TestUpgradeSQLData_v1_2_1(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -274,7 +274,7 @@ func TestUpgradeSQLData_v1_2_1(t *testing.T) {
|
||||
func TestUpgradeSQLData_v1_2_10(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -293,7 +293,7 @@ func TestUpgradeSQLData_v1_2_10(t *testing.T) {
|
||||
func TestUpgradeSQLData_v1_3_2(t *testing.T) {
|
||||
db, err := dbs.NewInstanceFromConfig(&dbs.DBConfig{
|
||||
Driver: "mysql",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3306)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Dsn: "root:123456@tcp(127.0.0.1:3308)/db_edge?charset=utf8mb4&timeout=30s",
|
||||
Prefix: "edge",
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@@ -59,7 +59,7 @@ func (t *HTTPDNSNodeMonitorTask) Loop() error {
|
||||
}
|
||||
|
||||
for _, cluster := range clusters {
|
||||
if cluster == nil || !cluster.IsOn || !cluster.AutoRemoteStart {
|
||||
if cluster == nil || cluster.IsOn == 0 || cluster.AutoRemoteStart == 0 {
|
||||
continue
|
||||
}
|
||||
clusterID := int64(cluster.Id)
|
||||
|
||||
Reference in New Issue
Block a user