-
Notifications
You must be signed in to change notification settings - Fork 255
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
ip transformer修改 #730
ip transformer修改 #730
Conversation
已实测 |
transforms/ip/ip.go
Outdated
DefaultNoUse: true, | ||
Description: "IP数据库路径(data_path)", | ||
Type: transforms.TransformTypeString, | ||
AdvanceDepend: transforms.LocalEnable, |
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.
根据前端的功能做对应修改:https://jira.qiniu.io/browse/PDR-7261
transforms/ip/ip.go
Outdated
Required: true, | ||
DefaultNoUse: false, | ||
Description: "使用本地解析", | ||
Type: transforms.TransformTypeBoolean, |
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.
说明一下本地IP解析和服务端解析最大的区别:
- 本地解析是用客户自己的IP库,更为灵活。
- 服务端解析是固定使用七牛IP库,用户无需提供IP库
transforms/ip/ip.go
Outdated
@@ -52,6 +54,13 @@ type Transformer struct { | |||
} | |||
|
|||
func (t *Transformer) Init() error { | |||
if t.Key != "" { | |||
t.LocalEnable = true |
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.
默认还是本地解析好了,不要加这种hack了
09587ff
to
214b7f8
Compare
transforms/ip/ip.go
Outdated
config := make(map[string]interface{}) | ||
config[transforms.KeyType] = Name | ||
config[transforms.LocalEnable] = t.LocalEnable | ||
t.keys = GetKeys(t.Key) |
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.
这里不用GetKeys了,直接原样给出去,在pandora-go-sdk里面去split,然后转成DSL的结构
transforms/ip/ip.go
Outdated
{ | ||
KeyName: "data_path", | ||
KeyName: transforms.LocalEnable, |
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.
这个key的名字不应该叫localEnable了,叫 At
或者 TransformAt
mgr/runner.go
Outdated
@@ -1286,3 +1294,44 @@ func MergeExtraInfoTags(meta *reader.Meta, tags map[string]interface{}) map[stri | |||
} | |||
return tags | |||
} | |||
|
|||
func setSenderConfig(senderConfig conf.MapConf, serverConfigs []map[string]interface{}) conf.MapConf { | |||
if senderConfig[sender.KeySenderType] != sender.TypePandora { |
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.
sender.Type可以作为参数传进来,也许以后别的Sender也要这样
mgr/runner.go
Outdated
} | ||
autoCreate := senderConfig[sender.KeyPandoraAutoCreate] | ||
localEnable, localEnableOk := serverConfig[transforms.LocalEnable].(string) | ||
if localEnableOk && localEnable == ip.Local { |
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.
localEnable == ip.Server
mgr/runner.go
Outdated
} else if index := strings.Index(autoCreate, schema); index != -1 { | ||
autoCreate = autoCreate[:index] + autoCreate[index+len(schema):] | ||
} | ||
senderConfig[sender.KeyPandoraAutoCreate] = autoCreate |
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.
我觉得这块逻辑要单独做个函数,叫inject Ip Transformer config,以后别人再加个类似的函数就行了,不需要理解你这块for循环里的细节逻辑
mgr/runner.go
Outdated
|
||
if !strings.Contains(autoCreate, KeyIP) { | ||
senderConfig[sender.KeyPandoraAutoCreate] += fmt.Sprintf(",%v ip", key) | ||
} |
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.
这里拼接的方式可能要修改,看服务端未来会不会支持嵌套类型指定IP字段
7a75786
to
27078fa
Compare
mgr/runner.go
Outdated
var err error | ||
for _, serverConfig := range serverConfigs { | ||
keyType, ok := serverConfig[transforms.KeyType].(string) | ||
if !ok || keyType != ip.Name { |
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.
不用再pandorakeyType是不是等于ip.Name了,下面会switch
return senderConfig, fmt.Errorf("key: %v ip transform key in server doesn't support dot(.)", key) | ||
} | ||
autoCreate := senderConfig[sender.KeyPandoraAutoCreate] | ||
transformAt, transformAtOk := serverConfig[transforms.TransformAt].(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.
先pandora TransformAtOk为false的情况,直接return
mgr/runner.go
Outdated
return senderConfig, nil | ||
} | ||
|
||
if !strings.Contains(autoCreate, KeyIP) { |
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.
这里不应该判断这个,我可以有多个IP字段通过服务端解析
mgr/runner.go
Outdated
} | ||
|
||
if autoCreate == "" { | ||
senderConfig[sender.KeyPandoraAutoCreate] = fmt.Sprintf("%v ip", key) |
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.
你这里要不直接用字符串拼接更好,而且你专门写了个 KeyIP可以用上。
用fmt的时候,能 %s
尽量不要 %v
哈
207c9ce
to
91da253
Compare
mgr/runner.go
Outdated
@@ -1286,3 +1298,60 @@ func MergeExtraInfoTags(meta *reader.Meta, tags map[string]interface{}) map[stri | |||
} | |||
return tags | |||
} | |||
|
|||
func setSenderConfig(senderConfig conf.MapConf, serverConfigs []map[string]interface{}) (conf.MapConf, 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.
如果只允许Pandora Sender,函数名可以明确的写 setPandoraServerConfig
transforms/ip/ip.go
Outdated
Description: "mmdb格式库使用的语种", | ||
Advance: true, | ||
Description: "要进行Transform变化的键(key)", | ||
ToolTip: "对该字段的值进行transform变换, 服务端不支持嵌套(.)", |
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.
后面加上,“对该字段的值进行transform变换, 服务端转换不支持嵌套(.),请先使用rename,本地转换支持”
comments都修改了 |
LGTM |
@wonderflow
@unknwon
ip transfomer 增加选项 local_enable, 表示是否使用本地ip解析,默认为false,使用服务端解析
如果local_enable,pandora sender处相应修改schema