dns clickhouse改造
This commit is contained in:
@@ -11,21 +11,23 @@ import (
|
||||
)
|
||||
|
||||
type NSNodeConfig struct {
|
||||
Id int64 `yaml:"id" json:"id"`
|
||||
IsPlus bool `yaml:"isPlus" json:"isPlus"`
|
||||
NodeId string `yaml:"nodeId" json:"nodeId"`
|
||||
Secret string `yaml:"secret" json:"secret"`
|
||||
ClusterId int64 `yaml:"clusterId" json:"clusterId"`
|
||||
AccessLogRef *NSAccessLogRef `yaml:"accessLogRef" json:"accessLogRef"`
|
||||
RecursionConfig *NSRecursionConfig `yaml:"recursionConfig" json:"recursionConfig"`
|
||||
DDoSProtection *ddosconfigs.ProtectionConfig `yaml:"ddosProtection" json:"ddosProtection"`
|
||||
AllowedIPs []string `yaml:"allowedIPs" json:"allowedIPs"`
|
||||
TimeZone string `yaml:"timeZone" json:"timeZone"` // 自动设置时区
|
||||
Hosts []string `yaml:"hosts" json:"hosts"` // 主机名
|
||||
Email string `yaml:"email" json:"email"`
|
||||
SOA *NSSOAConfig `yaml:"soa" json:"soa"` // SOA配置
|
||||
SOASerial uint32 `yaml:"soaSerial" json:"soaSerial"`
|
||||
DetectAgents bool `yaml:"detectAgents" json:"detectAgents"` // 是否实时监测Agents
|
||||
Id int64 `yaml:"id" json:"id"`
|
||||
IsPlus bool `yaml:"isPlus" json:"isPlus"`
|
||||
NodeId string `yaml:"nodeId" json:"nodeId"`
|
||||
Secret string `yaml:"secret" json:"secret"`
|
||||
ClusterId int64 `yaml:"clusterId" json:"clusterId"`
|
||||
AccessLogRef *NSAccessLogRef `yaml:"accessLogRef" json:"accessLogRef"`
|
||||
AccessLogWriteTargets *serverconfigs.AccessLogWriteTargets `yaml:"accessLogWriteTargets" json:"accessLogWriteTargets"`
|
||||
AccessLogFilePath string `yaml:"accessLogFilePath" json:"accessLogFilePath"`
|
||||
RecursionConfig *NSRecursionConfig `yaml:"recursionConfig" json:"recursionConfig"`
|
||||
DDoSProtection *ddosconfigs.ProtectionConfig `yaml:"ddosProtection" json:"ddosProtection"`
|
||||
AllowedIPs []string `yaml:"allowedIPs" json:"allowedIPs"`
|
||||
TimeZone string `yaml:"timeZone" json:"timeZone"` // 自动设置时区
|
||||
Hosts []string `yaml:"hosts" json:"hosts"` // 主机名
|
||||
Email string `yaml:"email" json:"email"`
|
||||
SOA *NSSOAConfig `yaml:"soa" json:"soa"` // SOA配置
|
||||
SOASerial uint32 `yaml:"soaSerial" json:"soaSerial"`
|
||||
DetectAgents bool `yaml:"detectAgents" json:"detectAgents"` // 是否实时监测Agents
|
||||
|
||||
TCP *serverconfigs.TCPProtocolConfig `yaml:"tcp" json:"tcp"` // TCP配置
|
||||
TLS *serverconfigs.TLSProtocolConfig `yaml:"tls" json:"tls"` // TLS配置
|
||||
|
||||
@@ -84,6 +84,33 @@ func ParseStorageTypeAndWriteTargets(selectedType string) (baseType string, writ
|
||||
return baseType, writeTargets
|
||||
}
|
||||
|
||||
// ResolveWriteTargetsByType 仅根据策略类型与 disableDefaultDB 计算写入目标(不依赖 writeTargets 字段)
|
||||
func ResolveWriteTargetsByType(policyType string, disableDefaultDB bool) *AccessLogWriteTargets {
|
||||
t := &AccessLogWriteTargets{}
|
||||
switch policyType {
|
||||
case AccessLogStorageTypeFileMySQL:
|
||||
t.File = true
|
||||
t.MySQL = true
|
||||
case AccessLogStorageTypeFileClickhouse:
|
||||
t.File = true
|
||||
t.ClickHouse = true
|
||||
case AccessLogStorageTypeFileMySQLClickhouse:
|
||||
t.File = true
|
||||
t.MySQL = true
|
||||
t.ClickHouse = true
|
||||
case AccessLogStorageTypeFile:
|
||||
t.File = true
|
||||
t.MySQL = !disableDefaultDB
|
||||
default:
|
||||
t.MySQL = !disableDefaultDB
|
||||
}
|
||||
if !t.File && !t.MySQL && !t.ClickHouse {
|
||||
t.File = true
|
||||
t.MySQL = true
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
// ComposeStorageTypeDisplay 根据策略的 Type + WriteTargets 得到下拉框显示用的类型 code(用于编辑页回显)
|
||||
func ComposeStorageTypeDisplay(policyType string, writeTargets *AccessLogWriteTargets) string {
|
||||
if policyType != AccessLogStorageTypeFile {
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
|
||||
package serverconfigs
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// AccessLogWriteTargets 访问日志写入目标(双写/单写:文件、MySQL、ClickHouse)
|
||||
type AccessLogWriteTargets struct {
|
||||
File bool `yaml:"file" json:"file"` // 写本地 JSON 文件(供 Fluent Bit → ClickHouse 或自用)
|
||||
@@ -27,23 +25,8 @@ func (t *AccessLogWriteTargets) NeedWriteFile() bool {
|
||||
return t.File
|
||||
}
|
||||
|
||||
// ParseWriteTargetsFromPolicy 从策略的 writeTargets JSON 与旧字段解析;无 writeTargets 时按 type + disableDefaultDB 推断
|
||||
// ParseWriteTargetsFromPolicy 兼容入口:当前统一按 type 推导写入目标,不再依赖 writeTargets 字段
|
||||
func ParseWriteTargetsFromPolicy(writeTargetsJSON []byte, policyType string, disableDefaultDB bool) *AccessLogWriteTargets {
|
||||
if len(writeTargetsJSON) > 0 {
|
||||
var t AccessLogWriteTargets
|
||||
if err := json.Unmarshal(writeTargetsJSON, &t); err == nil {
|
||||
return &t
|
||||
}
|
||||
}
|
||||
// 兼容旧策略:type=file 视为写文件,!disableDefaultDB 视为写 MySQL
|
||||
t := &AccessLogWriteTargets{
|
||||
File: policyType == AccessLogStorageTypeFile,
|
||||
MySQL: !disableDefaultDB,
|
||||
ClickHouse: false,
|
||||
}
|
||||
if !t.File && !t.MySQL && !t.ClickHouse {
|
||||
t.File = true
|
||||
t.MySQL = true
|
||||
}
|
||||
return t
|
||||
_ = writeTargetsJSON
|
||||
return ResolveWriteTargetsByType(policyType, disableDefaultDB)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ type GlobalServerConfig struct {
|
||||
EnableCookies bool `yaml:"enableCookies" json:"enableCookies"` // 记录Cookie
|
||||
EnableServerNotFound bool `yaml:"enableServerNotFound" json:"enableServerNotFound"` // 记录服务找不到的日志
|
||||
WriteTargets *AccessLogWriteTargets `yaml:"writeTargets" json:"writeTargets"` // 写入目标:文件/MySQL/ClickHouse(双写/单写)
|
||||
FilePath string `yaml:"filePath" json:"filePath"` // 公用日志策略文件路径(用于节点侧复用)
|
||||
} `yaml:"httpAccessLog" json:"httpAccessLog"` // 访问日志配置
|
||||
|
||||
Stat struct {
|
||||
|
||||
Reference in New Issue
Block a user