mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-02 23:06:36 +08:00
[优化] 添加 Relay frps 连接和代理计数字段,重构相关逻辑以支持监控和可观测性
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// v20 records low-frequency Relay frps counters on nodes so the management UI
|
||||
// can show whether the relay runtime is alive and reporting tunnel load.
|
||||
package migrate
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type nodeV20 struct {
|
||||
ID uint `gorm:"primaryKey"`
|
||||
RelayFrpsConnections int `gorm:"column:relay_frps_connections"`
|
||||
RelayFrpsProxyCount int `gorm:"column:relay_frps_proxy_count"`
|
||||
}
|
||||
|
||||
func (nodeV20) TableName() string {
|
||||
return "nodes"
|
||||
}
|
||||
|
||||
func init() {
|
||||
Register(V20())
|
||||
}
|
||||
|
||||
func V20() Migration {
|
||||
return Migration{
|
||||
FromVersion: 19,
|
||||
ToVersion: 20,
|
||||
Migrate: migrateV20,
|
||||
Validate: validateV20,
|
||||
}
|
||||
}
|
||||
|
||||
func migrateV20(ctx Context, db *gorm.DB, backend string) error {
|
||||
if err := ctx.ApplyCurrentSchema(db, backend); err != nil {
|
||||
return err
|
||||
}
|
||||
return validateV20(ctx, db, backend)
|
||||
}
|
||||
|
||||
func validateV20(ctx Context, db *gorm.DB, backend string) error {
|
||||
if err := ctx.ValidateDatabaseSchemaVersion(db, backend, 19); err != nil {
|
||||
return err
|
||||
}
|
||||
if !db.Migrator().HasColumn(&nodeV20{}, "relay_frps_connections") {
|
||||
return fmt.Errorf("column nodes.relay_frps_connections is missing")
|
||||
}
|
||||
if !db.Migrator().HasColumn(&nodeV20{}, "relay_frps_proxy_count") {
|
||||
return fmt.Errorf("column nodes.relay_frps_proxy_count is missing")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -84,6 +84,8 @@ func (databaseSchemaMigrationContext) ValidateDatabaseSchemaVersion(db *gorm.DB,
|
||||
return validateDatabaseSchemaV18(db, backend)
|
||||
case 19:
|
||||
return validateDatabaseSchemaV19(db, backend)
|
||||
case 20:
|
||||
return validateDatabaseSchemaV20(db, backend)
|
||||
default:
|
||||
return fmt.Errorf("database schema validation for v%d is not defined", version)
|
||||
}
|
||||
@@ -1225,6 +1227,19 @@ func validateDatabaseSchemaV19(db *gorm.DB, backend string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateDatabaseSchemaV20(db *gorm.DB, backend string) error {
|
||||
if err := validateDatabaseSchemaV19(db, backend); err != nil {
|
||||
return err
|
||||
}
|
||||
if !db.Migrator().HasColumn(&Node{}, "relay_frps_connections") {
|
||||
return fmt.Errorf("column nodes.relay_frps_connections is missing")
|
||||
}
|
||||
if !db.Migrator().HasColumn(&Node{}, "relay_frps_proxy_count") {
|
||||
return fmt.Errorf("column nodes.relay_frps_proxy_count is missing")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func databaseSchemaMigrations() []databaseSchemaMigration {
|
||||
ctx := databaseSchemaMigrationContext{}
|
||||
migrations := []databaseSchemaMigration{}
|
||||
|
||||
@@ -40,6 +40,8 @@ type Node struct {
|
||||
RelayStatus string `json:"relay_status" gorm:"size:16;not null;default:'unknown'"`
|
||||
RelayFrpVersion string `json:"relay_frp_version" gorm:"size:64"`
|
||||
RelayVersion string `json:"relay_version" gorm:"size:64"`
|
||||
RelayFrpsConnections int `json:"relay_frps_connections" gorm:"not null;default:0"`
|
||||
RelayFrpsProxyCount int `json:"relay_frps_proxy_count" gorm:"not null;default:0"`
|
||||
}
|
||||
|
||||
func ListNodes() (nodes []*Node, err error) {
|
||||
|
||||
Reference in New Issue
Block a user