mirror of
				https://github.com/TeaOSLab/EdgeCommon.git
				synced 2025-11-04 05:00:24 +08:00 
			
		
		
		
	优化源站调度
This commit is contained in:
		@@ -48,6 +48,9 @@ type NodeConfig struct {
 | 
			
		||||
 | 
			
		||||
	// metrics
 | 
			
		||||
	hasHTTPConnectionMetrics bool
 | 
			
		||||
 | 
			
		||||
	// 源站集合
 | 
			
		||||
	originMap map[int64]*serverconfigs.OriginConfig
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SharedNodeConfig 取得当前节点配置单例
 | 
			
		||||
@@ -130,6 +133,9 @@ func (this *NodeConfig) Init() error {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// 源站
 | 
			
		||||
	this.originMap = map[int64]*serverconfigs.OriginConfig{}
 | 
			
		||||
 | 
			
		||||
	// 查找FirewallPolicy
 | 
			
		||||
	this.firewallPolicies = []*firewallconfigs.HTTPFirewallPolicy{}
 | 
			
		||||
	for _, policy := range this.HTTPFirewallPolicies {
 | 
			
		||||
@@ -161,6 +167,20 @@ func (this *NodeConfig) Init() error {
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		// 源站
 | 
			
		||||
		if server.ReverseProxyRef != nil && server.ReverseProxyRef.IsOn && server.ReverseProxy != nil && server.ReverseProxy.IsOn {
 | 
			
		||||
			for _, origin := range server.ReverseProxy.PrimaryOrigins {
 | 
			
		||||
				if origin.IsOn {
 | 
			
		||||
					this.originMap[origin.Id] = origin
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
			for _, origin := range server.ReverseProxy.BackupOrigins {
 | 
			
		||||
				if origin.IsOn {
 | 
			
		||||
					this.originMap[origin.Id] = origin
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if server.Web != nil {
 | 
			
		||||
			this.lookupWeb(server, server.Web)
 | 
			
		||||
		}
 | 
			
		||||
@@ -242,6 +262,18 @@ func (this *NodeConfig) HasHTTPConnectionMetrics() bool {
 | 
			
		||||
	return this.hasHTTPConnectionMetrics
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindOrigin 读取源站配置
 | 
			
		||||
func (this *NodeConfig) FindOrigin(originId int64) *serverconfigs.OriginConfig {
 | 
			
		||||
	if this.originMap == nil {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	config, ok := this.originMap[originId]
 | 
			
		||||
	if ok {
 | 
			
		||||
		return config
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 搜索WAF策略
 | 
			
		||||
func (this *NodeConfig) lookupWeb(server *serverconfigs.ServerConfig, web *serverconfigs.HTTPWebConfig) {
 | 
			
		||||
	if web == nil || !web.IsOn {
 | 
			
		||||
@@ -256,6 +288,21 @@ func (this *NodeConfig) lookupWeb(server *serverconfigs.ServerConfig, web *serve
 | 
			
		||||
	}
 | 
			
		||||
	if len(web.Locations) > 0 {
 | 
			
		||||
		for _, location := range web.Locations {
 | 
			
		||||
			// 源站
 | 
			
		||||
			if location.IsOn && location.ReverseProxyRef != nil && location.ReverseProxyRef.IsOn && location.ReverseProxy != nil && location.ReverseProxy.IsOn {
 | 
			
		||||
				for _, origin := range location.ReverseProxy.PrimaryOrigins {
 | 
			
		||||
					if origin.IsOn {
 | 
			
		||||
						this.originMap[origin.Id] = origin
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
				for _, origin := range location.ReverseProxy.BackupOrigins {
 | 
			
		||||
					if origin.IsOn {
 | 
			
		||||
						this.originMap[origin.Id] = origin
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			// Web
 | 
			
		||||
			if location.Web != nil && location.Web.IsOn {
 | 
			
		||||
				this.lookupWeb(server, location.Web)
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
@@ -40,6 +40,7 @@ type NodeLog struct {
 | 
			
		||||
	Count       int32  `protobuf:"varint,8,opt,name=count,proto3" json:"count,omitempty"`
 | 
			
		||||
	ServerId    int64  `protobuf:"varint,9,opt,name=serverId,proto3" json:"serverId,omitempty"`
 | 
			
		||||
	IsFixed     bool   `protobuf:"varint,10,opt,name=isFixed,proto3" json:"isFixed,omitempty"`
 | 
			
		||||
	OriginId    int64  `protobuf:"varint,11,opt,name=originId,proto3" json:"originId,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (x *NodeLog) Reset() {
 | 
			
		||||
@@ -144,12 +145,19 @@ func (x *NodeLog) GetIsFixed() bool {
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (x *NodeLog) GetOriginId() int64 {
 | 
			
		||||
	if x != nil {
 | 
			
		||||
		return x.OriginId
 | 
			
		||||
	}
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var File_models_model_node_log_proto protoreflect.FileDescriptor
 | 
			
		||||
 | 
			
		||||
var file_models_model_node_log_proto_rawDesc = []byte{
 | 
			
		||||
	0x0a, 0x1b, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x73, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x5f, 0x6e,
 | 
			
		||||
	0x6f, 0x64, 0x65, 0x5f, 0x6c, 0x6f, 0x67, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x02, 0x70,
 | 
			
		||||
	0x62, 0x22, 0xf9, 0x01, 0x0a, 0x07, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x12, 0x0e, 0x0a,
 | 
			
		||||
	0x62, 0x22, 0x95, 0x02, 0x0a, 0x07, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x12, 0x0e, 0x0a,
 | 
			
		||||
	0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x02, 0x69, 0x64, 0x12, 0x12, 0x0a,
 | 
			
		||||
	0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f, 0x6c,
 | 
			
		||||
	0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
 | 
			
		||||
@@ -164,8 +172,10 @@ var file_models_model_node_log_proto_rawDesc = []byte{
 | 
			
		||||
	0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65,
 | 
			
		||||
	0x72, 0x49, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65,
 | 
			
		||||
	0x72, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x69, 0x73, 0x46, 0x69, 0x78, 0x65, 0x64, 0x18, 0x0a,
 | 
			
		||||
	0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x46, 0x69, 0x78, 0x65, 0x64, 0x42, 0x06, 0x5a,
 | 
			
		||||
	0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 | 
			
		||||
	0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x69, 0x73, 0x46, 0x69, 0x78, 0x65, 0x64, 0x12, 0x1a, 0x0a,
 | 
			
		||||
	0x08, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x49, 0x64, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x03, 0x52,
 | 
			
		||||
	0x08, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x49, 0x64, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70,
 | 
			
		||||
	0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
 
 | 
			
		||||
@@ -128,6 +128,7 @@ type CountNodeLogsRequest struct {
 | 
			
		||||
	Keyword  string `protobuf:"bytes,5,opt,name=keyword,proto3" json:"keyword,omitempty"`
 | 
			
		||||
	Level    string `protobuf:"bytes,6,opt,name=level,proto3" json:"level,omitempty"`
 | 
			
		||||
	ServerId int64  `protobuf:"varint,7,opt,name=serverId,proto3" json:"serverId,omitempty"`
 | 
			
		||||
	OriginId int64  `protobuf:"varint,8,opt,name=originId,proto3" json:"originId,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (x *CountNodeLogsRequest) Reset() {
 | 
			
		||||
@@ -211,6 +212,13 @@ func (x *CountNodeLogsRequest) GetServerId() int64 {
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (x *CountNodeLogsRequest) GetOriginId() int64 {
 | 
			
		||||
	if x != nil {
 | 
			
		||||
		return x.OriginId
 | 
			
		||||
	}
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 列出单页日志
 | 
			
		||||
type ListNodeLogsRequest struct {
 | 
			
		||||
	state         protoimpl.MessageState
 | 
			
		||||
@@ -228,6 +236,7 @@ type ListNodeLogsRequest struct {
 | 
			
		||||
	ServerId   int64  `protobuf:"varint,9,opt,name=serverId,proto3" json:"serverId,omitempty"`
 | 
			
		||||
	FixedState int32  `protobuf:"varint,10,opt,name=fixedState,proto3" json:"fixedState,omitempty"`
 | 
			
		||||
	AllServers bool   `protobuf:"varint,11,opt,name=allServers,proto3" json:"allServers,omitempty"` // 是否获取所有服务相关的日志
 | 
			
		||||
	OriginId   int64  `protobuf:"varint,12,opt,name=originId,proto3" json:"originId,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (x *ListNodeLogsRequest) Reset() {
 | 
			
		||||
@@ -339,6 +348,13 @@ func (x *ListNodeLogsRequest) GetAllServers() bool {
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (x *ListNodeLogsRequest) GetOriginId() int64 {
 | 
			
		||||
	if x != nil {
 | 
			
		||||
		return x.OriginId
 | 
			
		||||
	}
 | 
			
		||||
	return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ListNodeLogsResponse struct {
 | 
			
		||||
	state         protoimpl.MessageState
 | 
			
		||||
	sizeCache     protoimpl.SizeCache
 | 
			
		||||
@@ -448,7 +464,7 @@ var file_service_node_log_proto_rawDesc = []byte{
 | 
			
		||||
	0x0b, 0x2e, 0x70, 0x62, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x52, 0x08, 0x6e, 0x6f,
 | 
			
		||||
	0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x18, 0x0a, 0x16, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
 | 
			
		||||
	0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
 | 
			
		||||
	0x22, 0xbe, 0x01, 0x0a, 0x14, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f,
 | 
			
		||||
	0x22, 0xda, 0x01, 0x0a, 0x14, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f,
 | 
			
		||||
	0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64,
 | 
			
		||||
	0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49,
 | 
			
		||||
	0x64, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
 | 
			
		||||
@@ -460,51 +476,54 @@ var file_service_node_log_proto_rawDesc = []byte{
 | 
			
		||||
	0x14, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05,
 | 
			
		||||
	0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49,
 | 
			
		||||
	0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49,
 | 
			
		||||
	0x64, 0x22, 0xa9, 0x02, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f,
 | 
			
		||||
	0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64,
 | 
			
		||||
	0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49,
 | 
			
		||||
	0x64, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
 | 
			
		||||
	0x04, 0x72, 0x6f, 0x6c, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18,
 | 
			
		||||
	0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x12, 0x0a,
 | 
			
		||||
	0x04, 0x73, 0x69, 0x7a, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, 0x69, 0x7a,
 | 
			
		||||
	0x65, 0x12, 0x18, 0x0a, 0x07, 0x64, 0x61, 0x79, 0x46, 0x72, 0x6f, 0x6d, 0x18, 0x05, 0x20, 0x01,
 | 
			
		||||
	0x28, 0x09, 0x52, 0x07, 0x64, 0x61, 0x79, 0x46, 0x72, 0x6f, 0x6d, 0x12, 0x14, 0x0a, 0x05, 0x64,
 | 
			
		||||
	0x61, 0x79, 0x54, 0x6f, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x64, 0x61, 0x79, 0x54,
 | 
			
		||||
	0x6f, 0x12, 0x18, 0x0a, 0x07, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x07, 0x20, 0x01,
 | 
			
		||||
	0x28, 0x09, 0x52, 0x07, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6c,
 | 
			
		||||
	0x65, 0x76, 0x65, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65,
 | 
			
		||||
	0x6c, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x18, 0x09, 0x20,
 | 
			
		||||
	0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a,
 | 
			
		||||
	0x0a, 0x66, 0x69, 0x78, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28,
 | 
			
		||||
	0x05, 0x52, 0x0a, 0x66, 0x69, 0x78, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1e, 0x0a,
 | 
			
		||||
	0x0a, 0x61, 0x6c, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x18, 0x0b, 0x20, 0x01, 0x28,
 | 
			
		||||
	0x08, 0x52, 0x0a, 0x61, 0x6c, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x22, 0x3f, 0x0a,
 | 
			
		||||
	0x14, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73,
 | 
			
		||||
	0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67,
 | 
			
		||||
	0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x70, 0x62, 0x2e, 0x4e, 0x6f, 0x64,
 | 
			
		||||
	0x65, 0x4c, 0x6f, 0x67, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x31,
 | 
			
		||||
	0x0a, 0x11, 0x46, 0x69, 0x78, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x75,
 | 
			
		||||
	0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x49, 0x64,
 | 
			
		||||
	0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x49,
 | 
			
		||||
	0x64, 0x32, 0x92, 0x02, 0x0a, 0x0e, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x53, 0x65, 0x72,
 | 
			
		||||
	0x76, 0x69, 0x63, 0x65, 0x12, 0x47, 0x0a, 0x0e, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4e, 0x6f,
 | 
			
		||||
	0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x19, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61,
 | 
			
		||||
	0x74, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
 | 
			
		||||
	0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4e, 0x6f, 0x64,
 | 
			
		||||
	0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3f, 0x0a,
 | 
			
		||||
	0x0d, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x18,
 | 
			
		||||
	0x2e, 0x70, 0x62, 0x2e, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67,
 | 
			
		||||
	0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x50,
 | 
			
		||||
	0x43, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41,
 | 
			
		||||
	0x0a, 0x0c, 0x6c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x17,
 | 
			
		||||
	0x2e, 0x70, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73,
 | 
			
		||||
	0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, 0x62, 0x2e, 0x4c, 0x69, 0x73,
 | 
			
		||||
	0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
 | 
			
		||||
	0x65, 0x12, 0x33, 0x0a, 0x0a, 0x66, 0x69, 0x78, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x12,
 | 
			
		||||
	0x15, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x78, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x52,
 | 
			
		||||
	0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x50, 0x43, 0x53,
 | 
			
		||||
	0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06,
 | 
			
		||||
	0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 | 
			
		||||
	0x64, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x49, 0x64, 0x18, 0x08, 0x20,
 | 
			
		||||
	0x01, 0x28, 0x03, 0x52, 0x08, 0x6f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x49, 0x64, 0x22, 0xc5, 0x02,
 | 
			
		||||
	0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65,
 | 
			
		||||
	0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x18,
 | 
			
		||||
	0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x06, 0x6e, 0x6f, 0x64, 0x65, 0x49, 0x64, 0x12, 0x12, 0x0a,
 | 
			
		||||
	0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f, 0x6c,
 | 
			
		||||
	0x65, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28,
 | 
			
		||||
	0x03, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x73, 0x65, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x73, 0x69, 0x7a,
 | 
			
		||||
	0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x04, 0x73, 0x69, 0x7a, 0x65, 0x12, 0x18, 0x0a,
 | 
			
		||||
	0x07, 0x64, 0x61, 0x79, 0x46, 0x72, 0x6f, 0x6d, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
 | 
			
		||||
	0x64, 0x61, 0x79, 0x46, 0x72, 0x6f, 0x6d, 0x12, 0x14, 0x0a, 0x05, 0x64, 0x61, 0x79, 0x54, 0x6f,
 | 
			
		||||
	0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x64, 0x61, 0x79, 0x54, 0x6f, 0x12, 0x18, 0x0a,
 | 
			
		||||
	0x07, 0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
 | 
			
		||||
	0x6b, 0x65, 0x79, 0x77, 0x6f, 0x72, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c,
 | 
			
		||||
	0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x1a, 0x0a,
 | 
			
		||||
	0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52,
 | 
			
		||||
	0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x66, 0x69, 0x78,
 | 
			
		||||
	0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x66,
 | 
			
		||||
	0x69, 0x78, 0x65, 0x64, 0x53, 0x74, 0x61, 0x74, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x61, 0x6c, 0x6c,
 | 
			
		||||
	0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x61,
 | 
			
		||||
	0x6c, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x72, 0x69,
 | 
			
		||||
	0x67, 0x69, 0x6e, 0x49, 0x64, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x6f, 0x72, 0x69,
 | 
			
		||||
	0x67, 0x69, 0x6e, 0x49, 0x64, 0x22, 0x3f, 0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x64,
 | 
			
		||||
	0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x27, 0x0a,
 | 
			
		||||
	0x08, 0x6e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32,
 | 
			
		||||
	0x0b, 0x2e, 0x70, 0x62, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x52, 0x08, 0x6e, 0x6f,
 | 
			
		||||
	0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x22, 0x31, 0x0a, 0x11, 0x46, 0x69, 0x78, 0x4e, 0x6f, 0x64,
 | 
			
		||||
	0x65, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1c, 0x0a, 0x09, 0x6e,
 | 
			
		||||
	0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09,
 | 
			
		||||
	0x6e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x49, 0x64, 0x32, 0x92, 0x02, 0x0a, 0x0e, 0x4e, 0x6f,
 | 
			
		||||
	0x64, 0x65, 0x4c, 0x6f, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x47, 0x0a, 0x0e,
 | 
			
		||||
	0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x19,
 | 
			
		||||
	0x2e, 0x70, 0x62, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f,
 | 
			
		||||
	0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x70, 0x62, 0x2e, 0x43,
 | 
			
		||||
	0x72, 0x65, 0x61, 0x74, 0x65, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x73,
 | 
			
		||||
	0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3f, 0x0a, 0x0d, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x4e, 0x6f,
 | 
			
		||||
	0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x18, 0x2e, 0x70, 0x62, 0x2e, 0x43, 0x6f, 0x75, 0x6e,
 | 
			
		||||
	0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
 | 
			
		||||
	0x1a, 0x14, 0x2e, 0x70, 0x62, 0x2e, 0x52, 0x50, 0x43, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65,
 | 
			
		||||
	0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x41, 0x0a, 0x0c, 0x6c, 0x69, 0x73, 0x74, 0x4e, 0x6f,
 | 
			
		||||
	0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x12, 0x17, 0x2e, 0x70, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74,
 | 
			
		||||
	0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
 | 
			
		||||
	0x18, 0x2e, 0x70, 0x62, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67,
 | 
			
		||||
	0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x33, 0x0a, 0x0a, 0x66, 0x69, 0x78,
 | 
			
		||||
	0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x12, 0x15, 0x2e, 0x70, 0x62, 0x2e, 0x46, 0x69, 0x78,
 | 
			
		||||
	0x4e, 0x6f, 0x64, 0x65, 0x4c, 0x6f, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x0e,
 | 
			
		||||
	0x2e, 0x70, 0x62, 0x2e, 0x52, 0x50, 0x43, 0x53, 0x75, 0x63, 0x63, 0x65, 0x73, 0x73, 0x42, 0x06,
 | 
			
		||||
	0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
 
 | 
			
		||||
@@ -14,4 +14,5 @@ message NodeLog {
 | 
			
		||||
	int32 count = 8;
 | 
			
		||||
	int64 serverId = 9;
 | 
			
		||||
	bool isFixed = 10;
 | 
			
		||||
	int64 originId = 11;
 | 
			
		||||
}
 | 
			
		||||
@@ -39,6 +39,7 @@ message CountNodeLogsRequest {
 | 
			
		||||
	string keyword = 5;
 | 
			
		||||
	string level = 6;
 | 
			
		||||
	int64 serverId = 7;
 | 
			
		||||
	int64 originId = 8;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 列出单页日志
 | 
			
		||||
@@ -55,6 +56,7 @@ message ListNodeLogsRequest {
 | 
			
		||||
	int64 serverId = 9;
 | 
			
		||||
	int32 fixedState = 10;
 | 
			
		||||
	bool allServers = 11; // 是否获取所有服务相关的日志
 | 
			
		||||
	int64 originId = 12;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
message ListNodeLogsResponse {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 源站服务配置
 | 
			
		||||
// OriginConfig 源站服务配置
 | 
			
		||||
type OriginConfig struct {
 | 
			
		||||
	Id          int64                 `yaml:"id" json:"id"`                   // ID
 | 
			
		||||
	IsOn        bool                  `yaml:"isOn" json:"isOn"`               // 是否启用
 | 
			
		||||
@@ -48,6 +48,8 @@ type OriginConfig struct {
 | 
			
		||||
	FTPServerRef *FTPServerRef    `yaml:"ftpServerRef" json:"ftpServerRef"` // TODO
 | 
			
		||||
	FTPServer    *FTPServerConfig `yaml:"ftpServer" json:"ftpServer"`       // TODO
 | 
			
		||||
 | 
			
		||||
	IsOk bool `yaml:"isOk" json:"isOk"` // 是否可以正常访问
 | 
			
		||||
 | 
			
		||||
	connTimeoutDuration time.Duration
 | 
			
		||||
	readTimeoutDuration time.Duration
 | 
			
		||||
	idleTimeoutDuration time.Duration
 | 
			
		||||
@@ -65,8 +67,10 @@ type OriginConfig struct {
 | 
			
		||||
	requestURIHasVariables  bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 校验
 | 
			
		||||
// Init 校验
 | 
			
		||||
func (this *OriginConfig) Init() error {
 | 
			
		||||
	this.IsOk = true
 | 
			
		||||
 | 
			
		||||
	// URL
 | 
			
		||||
	this.requestHostHasVariables = configutils.HasVariables(this.RequestHost)
 | 
			
		||||
	this.requestURIHasVariables = configutils.HasVariables(this.RequestURI)
 | 
			
		||||
@@ -157,7 +161,7 @@ func (this *OriginConfig) Init() error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 候选对象代号
 | 
			
		||||
// CandidateCodes 候选对象代号
 | 
			
		||||
func (this *OriginConfig) CandidateCodes() []string {
 | 
			
		||||
	codes := []string{strconv.FormatInt(this.Id, 10)}
 | 
			
		||||
	if len(this.Code) > 0 {
 | 
			
		||||
@@ -166,37 +170,37 @@ func (this *OriginConfig) CandidateCodes() []string {
 | 
			
		||||
	return codes
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 候选对象权重
 | 
			
		||||
// CandidateWeight 候选对象权重
 | 
			
		||||
func (this *OriginConfig) CandidateWeight() uint {
 | 
			
		||||
	return this.Weight
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 连接超时时间
 | 
			
		||||
// ConnTimeoutDuration 连接超时时间
 | 
			
		||||
func (this *OriginConfig) ConnTimeoutDuration() time.Duration {
 | 
			
		||||
	return this.connTimeoutDuration
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 读取超时时间
 | 
			
		||||
// ReadTimeoutDuration 读取超时时间
 | 
			
		||||
func (this *OriginConfig) ReadTimeoutDuration() time.Duration {
 | 
			
		||||
	return this.readTimeoutDuration
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 休眠超时时间
 | 
			
		||||
// IdleTimeoutDuration 休眠超时时间
 | 
			
		||||
func (this *OriginConfig) IdleTimeoutDuration() time.Duration {
 | 
			
		||||
	return this.idleTimeoutDuration
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 判断RequestHost是否有变量
 | 
			
		||||
// RequestHostHasVariables 判断RequestHost是否有变量
 | 
			
		||||
func (this *OriginConfig) RequestHostHasVariables() bool {
 | 
			
		||||
	return this.requestHostHasVariables
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 判断RequestURI是否有变量
 | 
			
		||||
// RequestURIHasVariables 判断RequestURI是否有变量
 | 
			
		||||
func (this *OriginConfig) RequestURIHasVariables() bool {
 | 
			
		||||
	return this.requestURIHasVariables
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 唯一Key
 | 
			
		||||
// UniqueKey 唯一Key
 | 
			
		||||
func (this *OriginConfig) UniqueKey() string {
 | 
			
		||||
	return this.uniqueKey
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,7 +16,7 @@ const (
 | 
			
		||||
	RequestHostTypeCustomized  RequestHostType = 2
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// 反向代理设置
 | 
			
		||||
// ReverseProxyConfig 反向代理设置
 | 
			
		||||
type ReverseProxyConfig struct {
 | 
			
		||||
	Id                int64             `yaml:"id" json:"id"`                               // ID
 | 
			
		||||
	IsOn              bool              `yaml:"isOn" json:"isOn"`                           // 是否启用
 | 
			
		||||
@@ -59,7 +59,7 @@ type ReverseProxyConfig struct {
 | 
			
		||||
	addXForwardedProtoHeader bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 初始化
 | 
			
		||||
// Init 初始化
 | 
			
		||||
func (this *ReverseProxyConfig) Init() error {
 | 
			
		||||
	this.requestHostHasVariables = configutils.HasVariables(this.RequestHost)
 | 
			
		||||
	this.requestURIHasVariables = configutils.HasVariables(this.RequestURI)
 | 
			
		||||
@@ -98,7 +98,7 @@ func (this *ReverseProxyConfig) Init() error {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// scheduling
 | 
			
		||||
	this.SetupScheduling(false)
 | 
			
		||||
	this.SetupScheduling(false, false, true)
 | 
			
		||||
 | 
			
		||||
	// Header
 | 
			
		||||
	if len(this.AddHeaders) == 0 {
 | 
			
		||||
@@ -119,17 +119,17 @@ func (this *ReverseProxyConfig) Init() error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 添加主源站配置
 | 
			
		||||
// AddPrimaryOrigin 添加主源站配置
 | 
			
		||||
func (this *ReverseProxyConfig) AddPrimaryOrigin(origin *OriginConfig) {
 | 
			
		||||
	this.PrimaryOrigins = append(this.PrimaryOrigins, origin)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 添加备用源站配置
 | 
			
		||||
// AddBackupOrigin 添加备用源站配置
 | 
			
		||||
func (this *ReverseProxyConfig) AddBackupOrigin(origin *OriginConfig) {
 | 
			
		||||
	this.BackupOrigins = append(this.BackupOrigins, origin)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 取得下一个可用的后端服务
 | 
			
		||||
// NextOrigin 取得下一个可用的后端服务
 | 
			
		||||
func (this *ReverseProxyConfig) NextOrigin(call *shared.RequestCall) *OriginConfig {
 | 
			
		||||
	this.schedulingLocker.Lock()
 | 
			
		||||
	defer this.schedulingLocker.Unlock()
 | 
			
		||||
@@ -145,16 +145,33 @@ func (this *ReverseProxyConfig) NextOrigin(call *shared.RequestCall) *OriginConf
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	candidate := this.schedulingObject.Next(call)
 | 
			
		||||
 | 
			
		||||
	// 末了重置状态
 | 
			
		||||
	defer func() {
 | 
			
		||||
		if candidate == nil {
 | 
			
		||||
			this.schedulingIsBackup = false
 | 
			
		||||
		}
 | 
			
		||||
	}()
 | 
			
		||||
 | 
			
		||||
	if candidate == nil {
 | 
			
		||||
		// 启用备用服务器
 | 
			
		||||
		if !this.schedulingIsBackup {
 | 
			
		||||
			this.SetupScheduling(true)
 | 
			
		||||
 | 
			
		||||
			this.SetupScheduling(true, true, false)
 | 
			
		||||
			candidate = this.schedulingObject.Next(call)
 | 
			
		||||
			if candidate == nil {
 | 
			
		||||
				// 不检查主要源站
 | 
			
		||||
				this.SetupScheduling(false, false, false)
 | 
			
		||||
				candidate = this.schedulingObject.Next(call)
 | 
			
		||||
				if candidate == nil {
 | 
			
		||||
					// 不检查备用源站
 | 
			
		||||
					this.SetupScheduling(true, false, false)
 | 
			
		||||
					candidate = this.schedulingObject.Next(call)
 | 
			
		||||
					if candidate == nil {
 | 
			
		||||
						return nil
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if candidate == nil {
 | 
			
		||||
			return nil
 | 
			
		||||
@@ -164,12 +181,13 @@ func (this *ReverseProxyConfig) NextOrigin(call *shared.RequestCall) *OriginConf
 | 
			
		||||
	return candidate.(*OriginConfig)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 设置调度算法
 | 
			
		||||
func (this *ReverseProxyConfig) SetupScheduling(isBackup bool) {
 | 
			
		||||
	if !isBackup {
 | 
			
		||||
// SetupScheduling 设置调度算法
 | 
			
		||||
func (this *ReverseProxyConfig) SetupScheduling(isBackup bool, checkOk bool, lock bool) {
 | 
			
		||||
	if lock {
 | 
			
		||||
		this.schedulingLocker.Lock()
 | 
			
		||||
		defer this.schedulingLocker.Unlock()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.schedulingIsBackup = isBackup
 | 
			
		||||
 | 
			
		||||
	if this.Scheduling == nil {
 | 
			
		||||
@@ -187,22 +205,26 @@ func (this *ReverseProxyConfig) SetupScheduling(isBackup bool) {
 | 
			
		||||
 | 
			
		||||
	if !isBackup {
 | 
			
		||||
		for _, origin := range this.PrimaryOrigins {
 | 
			
		||||
			if origin.IsOn {
 | 
			
		||||
			if origin.IsOn && (origin.IsOk || !checkOk) {
 | 
			
		||||
				this.schedulingObject.Add(origin)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		for _, origin := range this.BackupOrigins {
 | 
			
		||||
			if origin.IsOn {
 | 
			
		||||
			if origin.IsOn && (origin.IsOk || !checkOk) {
 | 
			
		||||
				this.schedulingObject.Add(origin)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if !this.schedulingObject.HasCandidates() {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	this.schedulingObject.Start()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 获取调度配置对象
 | 
			
		||||
// FindSchedulingConfig 获取调度配置对象
 | 
			
		||||
func (this *ReverseProxyConfig) FindSchedulingConfig() *SchedulingConfig {
 | 
			
		||||
	if this.Scheduling == nil {
 | 
			
		||||
		this.Scheduling = &SchedulingConfig{Code: "random"}
 | 
			
		||||
@@ -210,37 +232,42 @@ func (this *ReverseProxyConfig) FindSchedulingConfig() *SchedulingConfig {
 | 
			
		||||
	return this.Scheduling
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 判断RequestHost是否有变量
 | 
			
		||||
// RequestHostHasVariables 判断RequestHost是否有变量
 | 
			
		||||
func (this *ReverseProxyConfig) RequestHostHasVariables() bool {
 | 
			
		||||
	return this.requestHostHasVariables
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 判断RequestURI是否有变量
 | 
			
		||||
// RequestURIHasVariables 判断RequestURI是否有变量
 | 
			
		||||
func (this *ReverseProxyConfig) RequestURIHasVariables() bool {
 | 
			
		||||
	return this.requestURIHasVariables
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 是否添加X-Real-IP
 | 
			
		||||
// ShouldAddXRealIPHeader 是否添加X-Real-IP
 | 
			
		||||
func (this *ReverseProxyConfig) ShouldAddXRealIPHeader() bool {
 | 
			
		||||
	return this.addXRealIPHeader
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 是否添加X-Forwarded-For
 | 
			
		||||
// ShouldAddXForwardedForHeader 是否添加X-Forwarded-For
 | 
			
		||||
func (this *ReverseProxyConfig) ShouldAddXForwardedForHeader() bool {
 | 
			
		||||
	return this.addXForwardedForHeader
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 是否添加X-Forwarded-By
 | 
			
		||||
// ShouldAddXForwardedByHeader 是否添加X-Forwarded-By
 | 
			
		||||
func (this *ReverseProxyConfig) ShouldAddXForwardedByHeader() bool {
 | 
			
		||||
	return this.addXForwardedByHeader
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 是否添加X-Forwarded-Host
 | 
			
		||||
// ShouldAddXForwardedHostHeader 是否添加X-Forwarded-Host
 | 
			
		||||
func (this *ReverseProxyConfig) ShouldAddXForwardedHostHeader() bool {
 | 
			
		||||
	return this.addXForwardedHostHeader
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// 是否添加X-Forwarded-Proto
 | 
			
		||||
// ShouldAddXForwardedProtoHeader 是否添加X-Forwarded-Proto
 | 
			
		||||
func (this *ReverseProxyConfig) ShouldAddXForwardedProtoHeader() bool {
 | 
			
		||||
	return this.addXForwardedProtoHeader
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ResetScheduling 重置调度算法
 | 
			
		||||
func (this *ReverseProxyConfig) ResetScheduling() {
 | 
			
		||||
	this.SetupScheduling(false, true, true)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@ package schedulingconfigs
 | 
			
		||||
 | 
			
		||||
import "github.com/iwind/TeaGo/maps"
 | 
			
		||||
 | 
			
		||||
// 所有请求类型
 | 
			
		||||
// AllSchedulingTypes 所有请求类型
 | 
			
		||||
func AllSchedulingTypes() []maps.Map {
 | 
			
		||||
	types := []maps.Map{}
 | 
			
		||||
	for _, s := range []SchedulingInterface{
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								pkg/serverconfigs/schedulingconfigs/utils_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								pkg/serverconfigs/schedulingconfigs/utils_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
 | 
			
		||||
 | 
			
		||||
package schedulingconfigs
 | 
			
		||||
 | 
			
		||||
import "testing"
 | 
			
		||||
 | 
			
		||||
func TestFindSchedulingType(t *testing.T) {
 | 
			
		||||
	t.Logf("%p", FindSchedulingType("roundRobin"))
 | 
			
		||||
	t.Logf("%p", FindSchedulingType("roundRobin"))
 | 
			
		||||
	t.Logf("%p", FindSchedulingType("roundRobin"))
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user