Skip to content
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

make qiniu log parser more flexiable #715

Merged
merged 1 commit into from
Aug 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions mgr/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/qiniu/logkit/conf"
"github.com/qiniu/logkit/parser"
_ "github.com/qiniu/logkit/parser/builtin"
"github.com/qiniu/logkit/parser/qiniu"
"github.com/qiniu/logkit/reader"
_ "github.com/qiniu/logkit/reader/builtin"
"github.com/qiniu/logkit/reader/cloudtrail"
Expand Down Expand Up @@ -89,7 +90,6 @@ type LogExportRunner struct {
}

const defaultSendIntervalSeconds = 60
const qiniulogHeadPatthern = "[1-9]\\d{3}/[0-1]\\d/[0-3]\\d [0-2]\\d:[0-6]\\d:[0-6]\\d(\\.\\d{6})?"

// NewRunner 创建Runner
func NewRunner(rc RunnerConfig, cleanChan chan<- cleaner.CleanSignal) (runner Runner, err error) {
Expand Down Expand Up @@ -1043,13 +1043,13 @@ func Compatible(rc RunnerConfig) RunnerConfig {
}
pattern, _ := rc.ReaderConfig.GetStringOr(reader.KeyHeadPattern, "")
if parserType == parser.TypeLogv1 && pattern == "" {
prefix, _ := rc.ParserConf.GetStringOr(parser.KeyQiniulogPrefix, "")
prefix, _ := rc.ParserConf.GetStringOr(qiniu.KeyPrefix, "")
prefix = strings.TrimSpace(prefix)
var readpattern string
if len(prefix) > 0 {
readpattern = "^" + prefix + " " + qiniulogHeadPatthern
readpattern = "^" + prefix + " " + qiniu.HeadPatthern
} else {
readpattern = "^" + qiniulogHeadPatthern
readpattern = "^" + qiniu.HeadPatthern
}
rc.ReaderConfig[reader.KeyHeadPattern] = readpattern
}
Expand Down
19 changes: 13 additions & 6 deletions mgr/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/qiniu/logkit/cleaner"
"github.com/qiniu/logkit/conf"
"github.com/qiniu/logkit/parser"
"github.com/qiniu/logkit/parser/qiniu"
"github.com/qiniu/logkit/reader"
"github.com/qiniu/logkit/router"
"github.com/qiniu/logkit/sender"
Expand Down Expand Up @@ -287,7 +288,7 @@ func Test_RunForEnvTag(t *testing.T) {
t.Error(err)
}
senderConfigs := []conf.MapConf{
conf.MapConf{
{
"name": "mock_sender",
"sender_type": "mock",
},
Expand Down Expand Up @@ -517,7 +518,7 @@ func Test_Compatible(t *testing.T) {
"mode": "dir",
"read_from": "oldest",
"datasource_tag": "testtag",
"head_pattern": "^" + qiniulogHeadPatthern,
"head_pattern": "^" + qiniu.HeadPatthern,
},
ParserConf: conf.MapConf{
"type": "qiniulog",
Expand Down Expand Up @@ -545,7 +546,7 @@ func Test_Compatible(t *testing.T) {
"mode": "dir",
"read_from": "oldest",
"datasource_tag": "testtag",
"head_pattern": "^PREX " + qiniulogHeadPatthern,
"head_pattern": "^PREX " + qiniu.HeadPatthern,
},
ParserConf: conf.MapConf{
"type": "qiniulog",
Expand Down Expand Up @@ -593,9 +594,11 @@ func Test_QiniulogRun(t *testing.T) {
2016/10/20 17:20:30.642662 [123][WARN] disk.go:241: github.com/qiniu/logkit/queue/disk.go 1
`
log3 := `2016/10/20 17:20:30.642662 [124][WARN] disk.go:456: xxxxxx`
expfiles := []string{`[REQ_END] 200 0.010k 3.792ms \t\t[WARN][SLdoIrCDZj7pmZsU] disk.go <job.freezeDeamon> pop() failed: not found`,
expfiles := []string{`[REQ_END] 200 0.010k 3.792ms
[WARN][SLdoIrCDZj7pmZsU] disk.go <job.freezeDeamon> pop() failed: not found`,
`Service: POST 10.200.20.25:9100/user/info, Code: 200, Xlog: AC, Time: 1ms`,
`github.com/qiniu/logkit/queue/disk.go:241 \t1234 3243xsaxs`, `github.com/qiniu/logkit/queue/disk.go 1`,
`github.com/qiniu/logkit/queue/disk.go:241
1234 3243xsaxs`, `github.com/qiniu/logkit/queue/disk.go 1`,
`xxxxxx`}
expreqid := []string{"X-ZsU", "2pyKMukqvwSd-ZsU", "", "123", "124"}
if err := ioutil.WriteFile(filepath.Join(logpath, "log1"), []byte(log1), 0666); err != nil {
Expand Down Expand Up @@ -697,7 +700,11 @@ func Test_QiniulogRun(t *testing.T) {
}
for idx, dt := range dts {
assert.Equal(t, expfiles[idx], dt["log"], "equl log test")
assert.Equal(t, expreqid[idx], dt["reqid"], "equal reqid test")
if expreqid[idx] == "" {
assert.Nil(t, dt["reqid"])
} else {
assert.Equal(t, expreqid[idx], dt["reqid"], "equal reqid test")
}
}
ls, err := runner.LagStats()
assert.NoError(t, err)
Expand Down
8 changes: 0 additions & 8 deletions parser/mysql/mysql.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
package mysql

import (
"regexp"
"strings"

"github.com/Preetam/mysqllog"

"github.com/qiniu/logkit/conf"
"github.com/qiniu/logkit/parser"
"github.com/qiniu/logkit/parser/qiniu"
. "github.com/qiniu/logkit/utils/models"
)

func init() {
qiniu.CompliedPatterns = make(map[string]*regexp.Regexp)
for k, v := range qiniu.HeaderPattern {
c, _ := regexp.Compile(v)
qiniu.CompliedPatterns[k] = c
}

parser.RegisterConstructor(parser.TypeMySQL, NewParser)
}

Expand Down
Loading