dns clickhouse改造
This commit is contained in:
@@ -52,9 +52,60 @@ func IsFileBasedStorageType(code string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// NormalizeAccessLogStorageType 统一存储类型编码(兼容历史别名)。
|
||||
func NormalizeAccessLogStorageType(storageType string) string {
|
||||
switch storageType {
|
||||
case "clickhouse":
|
||||
return AccessLogStorageTypeFileClickhouse
|
||||
case "mysql_clickhouse":
|
||||
return AccessLogStorageTypeFileMySQLClickhouse
|
||||
default:
|
||||
return storageType
|
||||
}
|
||||
}
|
||||
|
||||
// BuildWriteTargetsByStorageType 按 type(唯一真源)构建写入目标。
|
||||
// disableDefaultDB 用于控制是否保留 MySQL 写入。
|
||||
func BuildWriteTargetsByStorageType(storageType string, disableDefaultDB bool) *AccessLogWriteTargets {
|
||||
storageType = NormalizeAccessLogStorageType(storageType)
|
||||
|
||||
targets := &AccessLogWriteTargets{}
|
||||
switch storageType {
|
||||
case AccessLogStorageTypeFile:
|
||||
targets.File = true
|
||||
case AccessLogStorageTypeFileMySQL:
|
||||
targets.File = true
|
||||
targets.MySQL = true
|
||||
case AccessLogStorageTypeFileClickhouse:
|
||||
targets.File = true
|
||||
targets.ClickHouse = true
|
||||
case AccessLogStorageTypeFileMySQLClickhouse:
|
||||
targets.File = true
|
||||
targets.MySQL = true
|
||||
targets.ClickHouse = true
|
||||
case AccessLogStorageTypeES, AccessLogStorageTypeTCP, AccessLogStorageTypeSyslog, AccessLogStorageTypeCommand:
|
||||
// 保持现有兼容语义:非 file 类型默认写 MySQL(除非停用默认数据库)
|
||||
targets.MySQL = true
|
||||
default:
|
||||
// 兜底保持可用
|
||||
targets.File = true
|
||||
targets.MySQL = true
|
||||
}
|
||||
|
||||
if disableDefaultDB {
|
||||
targets.MySQL = false
|
||||
}
|
||||
|
||||
if !targets.File && !targets.MySQL && !targets.ClickHouse {
|
||||
targets.File = true
|
||||
}
|
||||
return targets
|
||||
}
|
||||
|
||||
// ParseStorageTypeAndWriteTargets 从下拉框选中的类型解析出「实际存储类型」与「写入目标」
|
||||
// 用于创建/更新策略:options 按 baseType 填(如 file),writeTargets 按组合填。
|
||||
func ParseStorageTypeAndWriteTargets(selectedType string) (baseType string, writeTargets *AccessLogWriteTargets) {
|
||||
selectedType = NormalizeAccessLogStorageType(selectedType)
|
||||
writeTargets = &AccessLogWriteTargets{}
|
||||
switch selectedType {
|
||||
case AccessLogStorageTypeFile:
|
||||
@@ -84,35 +135,9 @@ 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 {
|
||||
policyType = NormalizeAccessLogStorageType(policyType)
|
||||
if policyType != AccessLogStorageTypeFile {
|
||||
return policyType
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user