Skip to content

Commit 3918ff2

Browse files
李红李红
authored andcommitted
update pandora go sdk
1 parent 33cffc6 commit 3918ff2

File tree

11 files changed

+84
-62
lines changed

11 files changed

+84
-62
lines changed

mgr/dataflow.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,21 +378,18 @@ func checkSampleData(sampleData []string, logParser parser.Parser) ([]string, er
378378
}
379379

380380
func getTransformerCreator(transformerConfig map[string]interface{}) (transforms.Creator, error) {
381-
transformKeyType, ok := transformerConfig[KeyType]
381+
transformKeyType, ok := transformerConfig[transforms.KeyType]
382382
if !ok {
383-
err := fmt.Errorf("missing param %s", KeyType)
384-
return nil, err
383+
return nil, fmt.Errorf("missing param %s", transforms.KeyType)
385384
}
386385
transformKeyTypeStr, ok := transformKeyType.(string)
387386
if !ok {
388-
err := fmt.Errorf("param %s must be of type string", KeyType)
389-
return nil, err
387+
return nil, fmt.Errorf("param %s must be of type string", transforms.KeyType)
390388
}
391389

392390
create, ok := transforms.Transformers[transformKeyTypeStr]
393391
if !ok {
394-
err := fmt.Errorf("transformer of type %v not exist", transformKeyTypeStr)
395-
return nil, err
392+
return nil, fmt.Errorf("transformer of type %v not exist", transformKeyTypeStr)
396393
}
397394
return create, nil
398395
}

mgr/runner.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/qiniu/logkit/sender"
2929
_ "github.com/qiniu/logkit/sender/builtin"
3030
"github.com/qiniu/logkit/transforms"
31+
"github.com/qiniu/logkit/transforms/ip"
3132
. "github.com/qiniu/logkit/utils/models"
3233
)
3334

@@ -286,9 +287,7 @@ func NewLogExportRunner(rc RunnerConfig, cleanChan chan<- cleaner.CleanSignal, r
286287
//如果已经开启了,不要重复加
287288
senderConfig[sender.KeyPandoraExtraInfo] = "false"
288289
}
289-
if senderConfig[sender.KeySenderType] == sender.TypePandora {
290-
senderConfig = setSenderConfig(senderConfig, serverConfigs)
291-
}
290+
senderConfig = setSenderConfig(senderConfig, serverConfigs)
292291
s, err := sr.NewSender(senderConfig, meta.FtSaveLogPath())
293292
if err != nil {
294293
return nil, err
@@ -309,7 +308,7 @@ func createTransformers(rc RunnerConfig) ([]transforms.Transformer, error) {
309308
transformers := make([]transforms.Transformer, 0)
310309
for idx := range rc.Transforms {
311310
tConf := rc.Transforms[idx]
312-
tp := tConf[KeyType]
311+
tp := tConf[transforms.KeyType]
313312
if tp == nil {
314313
return nil, fmt.Errorf("transformer config type is empty %v", tConf)
315314
}
@@ -1292,18 +1291,19 @@ func MergeExtraInfoTags(meta *reader.Meta, tags map[string]interface{}) map[stri
12921291
}
12931292

12941293
func setSenderConfig(senderConfig conf.MapConf, serverConfigs []map[string]interface{}) conf.MapConf {
1294+
if senderConfig[sender.KeySenderType] != sender.TypePandora {
1295+
return senderConfig
1296+
}
1297+
12951298
for _, serverConfig := range serverConfigs {
1296-
keyType, ok := serverConfig[KeyType].(string)
1297-
if !ok || keyType != KeyIP {
1298-
continue
1299-
}
1300-
localEnable, ok := serverConfig[LocalEnable].(bool)
1301-
if !ok {
1299+
keyType, ok := serverConfig[transforms.KeyType].(string)
1300+
if !ok || keyType != ip.Name {
13021301
continue
13031302
}
13041303

13051304
autoCreate := senderConfig[sender.KeyPandoraAutoCreate]
1306-
if localEnable {
1305+
localEnable, ok := serverConfig[transforms.LocalEnable].(bool)
1306+
if ok && localEnable {
13071307
schema := fmt.Sprintf(",%v ip", KeyIP)
13081308
if autoCreate == fmt.Sprintf("%v ip", KeyIP) {
13091309
autoCreate = ""

mgr/runner_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ import (
2626
_ "github.com/qiniu/logkit/sender/builtin"
2727
"github.com/qiniu/logkit/sender/mock"
2828
"github.com/qiniu/logkit/sender/pandora"
29+
"github.com/qiniu/logkit/transforms"
2930
_ "github.com/qiniu/logkit/transforms/builtin"
31+
"github.com/qiniu/logkit/transforms/ip"
3032
. "github.com/qiniu/logkit/utils/models"
3133
)
3234

@@ -1896,12 +1898,42 @@ DONE:
18961898
break DONE
18971899
default:
18981900
dft++
1901+
18991902
}
19001903
time.Sleep(50 * time.Millisecond)
19011904
if dft > 60 {
19021905
break
19031906
}
19041907
}
19051908
assert.Equal(t, 1, ret)
1909+
}
1910+
1911+
func Test_setSenderConfig(t *testing.T) {
1912+
senderConfig := conf.MapConf{
1913+
sender.KeySenderType: sender.TypePandora,
1914+
}
1915+
serverConfigs := []map[string]interface{}{
1916+
{
1917+
transforms.KeyType: ip.Name,
1918+
},
1919+
}
1920+
actualConfig := setSenderConfig(senderConfig, serverConfigs)
1921+
assert.Equal(t, "ip ip", actualConfig[sender.KeyPandoraAutoCreate])
19061922

1923+
serverConfigs = []map[string]interface{}{
1924+
{
1925+
transforms.KeyType: ip.Name,
1926+
transforms.LocalEnable: true,
1927+
},
1928+
}
1929+
actualConfig = setSenderConfig(senderConfig, serverConfigs)
1930+
assert.Equal(t, "", actualConfig[sender.KeyPandoraAutoCreate])
1931+
1932+
serverConfigs = []map[string]interface{}{
1933+
{
1934+
transforms.KeyType: "other",
1935+
},
1936+
}
1937+
actualConfig = setSenderConfig(senderConfig, serverConfigs)
1938+
assert.Equal(t, "", actualConfig[sender.KeyPandoraAutoCreate])
19071939
}

sender/pandora/pandora.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ type Sender struct {
4848
microsecondCounter uint64
4949
extraInfo map[string]string
5050
sendType string
51-
EnbleServerIp bool
5251
}
5352

5453
// UserSchema was parsed pandora schema from user's raw schema
@@ -492,7 +491,6 @@ func newPandoraSender(opt *PandoraOption) (s *Sender, err error) {
492491
log.Errorf("Runner[%v] Sender[%v]: auto create pandora repo error: %v, you can create on pandora portal, ignored...", opt.runnerName, opt.name, err)
493492
err = nil
494493
}
495-
log.Infof("`````````````````````````````dsl: %v, schemas: %v, opt.autoCreate: %v", dsl, schemas, opt.autoCreate)
496494
if initErr := s.client.InitOrUpdateWorkflow(&pipeline.InitOrUpdateWorkflowInput{
497495
// 此处要的 schema 为 autoCreate 中用户指定的,所以 SchemaFree 要恒为 true
498496
InitOptionChange: true,

transforms/ip/ip.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (_ *Transformer) SampleConfig() string {
232232
func (_ *Transformer) ConfigOptions() []Option {
233233
return []Option{
234234
{
235-
KeyName: LocalEnable,
235+
KeyName: transforms.LocalEnable,
236236
Element: Radio,
237237
ChooseOnly: true,
238238
ChooseOptions: []interface{}{true, false},
@@ -252,7 +252,7 @@ func (_ *Transformer) ConfigOptions() []Option {
252252
Description: "要进行Transform变化的键(key)",
253253
ToolTip: "对该字段的值进行transform变换",
254254
Type: transforms.TransformTypeString,
255-
AdvanceDepend: LocalEnable,
255+
AdvanceDepend: transforms.LocalEnable,
256256
},
257257
{
258258
KeyName: "data_path",
@@ -263,7 +263,7 @@ func (_ *Transformer) ConfigOptions() []Option {
263263
DefaultNoUse: true,
264264
Description: "IP数据库路径(data_path)",
265265
Type: transforms.TransformTypeString,
266-
AdvanceDepend: LocalEnable,
266+
AdvanceDepend: transforms.LocalEnable,
267267
},
268268
{
269269
KeyName: "key_as_prefix",
@@ -275,7 +275,7 @@ func (_ *Transformer) ConfigOptions() []Option {
275275
Element: Checkbox,
276276
Description: "字段名称作为前缀(key_as_prefix)",
277277
Type: transforms.TransformTypeString,
278-
AdvanceDepend: LocalEnable,
278+
AdvanceDepend: transforms.LocalEnable,
279279
},
280280
{
281281
KeyName: "language",
@@ -287,7 +287,7 @@ func (_ *Transformer) ConfigOptions() []Option {
287287
Description: "mmdb格式库使用的语种",
288288
Advance: true,
289289
Type: transforms.TransformTypeString,
290-
AdvanceDepend: LocalEnable,
290+
AdvanceDepend: transforms.LocalEnable,
291291
},
292292
}
293293
}
@@ -314,8 +314,8 @@ func (t *Transformer) Close() error {
314314

315315
func (t *Transformer) ServerConfig() map[string]interface{} {
316316
config := make(map[string]interface{})
317-
config[KeyType] = Name
318-
config[LocalEnable] = t.LocalEnable
317+
config[transforms.KeyType] = Name
318+
config[transforms.LocalEnable] = t.LocalEnable
319319
return config
320320
}
321321

transforms/registry.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import (
44
. "github.com/qiniu/logkit/utils/models"
55
)
66

7+
const (
8+
KeyType = "type"
9+
10+
LocalEnable = "local_enable"
11+
)
12+
713
const (
814
TransformTypeString = "string"
915
TransformTypeLong = "long"

utils/models/models.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ const (
3636
KeyPandoraStash = "pandora_stash" // 当只有一条数据且 sendError 时候,将其转化为 raw 发送到 pandora_stash 这个字段
3737
KeyPandoraSeparateId = "pandora_separate_id" // 当一条数据大于2M且 sendError 时候,将其切片,切片记录到 pandora_separate_id 这个字段
3838
KeyIP = "ip" // schema ip
39-
KeyType = "type"
4039

4140
SchemaFreeTokensPrefix = "schema_free_tokens_"
4241
LogDBTokensPrefix = "logdb_tokens_"
@@ -60,8 +59,6 @@ const (
6059
Checkbox = "checkbox"
6160
Radio = "radio"
6261
InputNumber = "inputNumber"
63-
64-
LocalEnable = "local_enable"
6562
)
6663

6764
type Option struct {

vendor/github.com/qiniu/pandora-go-sdk/pipeline/api.go

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/qiniu/pandora-go-sdk/pipeline/models.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/qiniu/pandora-go-sdk/pipeline/schemafree.go

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)