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
|
||||
}
|
||||
|
||||
@@ -6,15 +6,16 @@ package serverconfigs
|
||||
type AccessLogWriteTargets struct {
|
||||
File bool `yaml:"file" json:"file"` // 写本地 JSON 文件(供 Fluent Bit → ClickHouse 或自用)
|
||||
MySQL bool `yaml:"mysql" json:"mysql"` // 写 MySQL 默认库按日分表
|
||||
ClickHouse bool `yaml:"clickhouse" json:"clickhouse"` // 需要落 ClickHouse(文件+Fluent Bit 或 API 直写)
|
||||
ClickHouse bool `yaml:"clickhouse" json:"clickhouse"` // 标记需要 ClickHouse 查询链路(写入由文件+Fluent Bit 异步完成)
|
||||
}
|
||||
|
||||
// NeedReportToAPI 是否需要上报到 API(写 MySQL 或 API 直写 ClickHouse 时需要)
|
||||
// NeedReportToAPI 是否需要上报到 API。
|
||||
// 与 DNS 语义一致:仅 MySQL 打开时才上报 API,ClickHouse-only 不上报。
|
||||
func (t *AccessLogWriteTargets) NeedReportToAPI() bool {
|
||||
if t == nil {
|
||||
return true // 兼容:未配置时保持原行为,上报
|
||||
}
|
||||
return t.MySQL || t.ClickHouse
|
||||
return t.MySQL
|
||||
}
|
||||
|
||||
// NeedWriteFile 节点是否需要写本地文件
|
||||
@@ -25,8 +26,9 @@ func (t *AccessLogWriteTargets) NeedWriteFile() bool {
|
||||
return t.File
|
||||
}
|
||||
|
||||
// ParseWriteTargetsFromPolicy 兼容入口:当前统一按 type 推导写入目标,不再依赖 writeTargets 字段
|
||||
// ParseWriteTargetsFromPolicy 从策略字段解析写入目标。
|
||||
// 当前以 type 为唯一真源,writeTargetsJSON 参数仅保留函数签名兼容。
|
||||
func ParseWriteTargetsFromPolicy(writeTargetsJSON []byte, policyType string, disableDefaultDB bool) *AccessLogWriteTargets {
|
||||
_ = writeTargetsJSON
|
||||
return ResolveWriteTargetsByType(policyType, disableDefaultDB)
|
||||
return BuildWriteTargetsByStorageType(policyType, disableDefaultDB)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user