-
Notifications
You must be signed in to change notification settings - Fork 57
feat: 特性开关使用 redis 存储 --story=130059585 #1195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: 特性开关使用 redis 存储 --story=130059585 #1195
Conversation
| ) | ||
|
|
||
| var ( | ||
| basePath = "bkmonitorv3:unify-query" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个应该是从配置读取的
pkg/unify-query/redis/redis.go
Outdated
| } | ||
|
|
||
| // WatchChange 监听指定 channel,监听触发时,channel将会传出信息(用于特性开关等场景) | ||
| var WatchChange = func(ctx context.Context, channel string) (<-chan any, error) { |
There was a problem hiding this comment.
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 注入进去。
pkg/unify-query/redis/featureFlag.go
Outdated
| } | ||
|
|
||
| // GetFeatureFlagsChannel 获取特性开关变更通知的 Redis channel | ||
| func GetFeatureFlagsChannel() string { |
There was a problem hiding this comment.
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 | ||
|
|
||
| // 根据配置选择数据源 |
There was a problem hiding this comment.
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" { |
There was a problem hiding this comment.
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" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,默认使用 consul,达到最坏情况,改动不影响之前的任何功能
pkg/unify-query/service/http/info.go
Outdated
| var err error | ||
| var dataSource string | ||
|
|
||
| if source == "consul" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,该方案可抽象。
….com:gongzhaolong/bkmonitor-datalink into feat/redis_FeatureFlags/#1010158081130059585
….com:gongzhaolong/bkmonitor-datalink into feat/redis_FeatureFlags/#1010158081130059585
No description provided.