Skip to content

Conversation

@gongzhaolong
Copy link
Collaborator

No description provided.

)

var (
basePath = "bkmonitorv3:unify-query"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个应该是从配置读取的

}

// WatchChange 监听指定 channel,监听触发时,channel将会传出信息(用于特性开关等场景)
var WatchChange = func(ctx context.Context, channel string) (<-chan any, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch 逻辑应该放到 featureFlag 模块下,另外,redis.go 这个文件,应该在后续的版本更新中逐步弃用了,这种全局定义函数的方式在做单测非常不友好,建议构建一个独立结构体处理 featureFlag 逻辑,redis client 作为入参体现,参考 GetInfluxDBRouter() 中 influxdb.NewRouter(prefix, redis.Client()) 的实现方式,这样 redis 就可以作为整个 mock 注入进去。

}

// GetFeatureFlagsChannel 获取特性开关变更通知的 Redis channel
func GetFeatureFlagsChannel() string {
Copy link
Collaborator

@shamcleren shamcleren Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果涉及到很多的函数调用,建议抽象成一个独立结构体,同时需要明确哪些是对外哪些是对内函数,特别重要的一点,就是外部依赖使用注入的方式获取,尽量不要使用全局变量的方式。

var data []byte
var err error

// 根据配置选择数据源
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果是做向前兼容设计,默认应该是读 consul,通过配置改成 redis,等功能完整整个验收之后,后续才把默认改成 redis


var ch <-chan any
// 根据配置选择监听方式
if DataSource == "consul" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

太多地方做 consul 还是 redis 的判定了,既然同时支持 consul 和 redis 只需要在启动调用的时候做判定就够了,剩下的 redis 和 consul 都可以公共抽象成两个函数来调用。


func LoadConfig() {
DataSource = viper.GetString(DataSourceConfigPath)
if DataSource != "consul" && DataSource != "redis" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,默认使用 consul,达到最坏情况,改动不影响之前的任何功能

var err error
var dataSource string

if source == "consul" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,该方案可抽象。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants