Skip to content

Commit 5af9b44

Browse files
authored
Merge pull request apache#43 from wanhailong/master
Support RTC audit log
2 parents 8f3e45c + 351d7a8 commit 5af9b44

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

go/src/pili.qiniu.com/dsync.v1/conf.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ import (
1313
)
1414

1515
type Conf struct {
16-
ConfigDir string `json:"config_dir"`
17-
Host string `json:"host"`
18-
IDC string `json:"idc"`
19-
ScanSeconds int64 `json:"scan_seconds"`
20-
OffsetDir string `json:"offset_dir"`
21-
Sinker flume.Config `json:"sinker"`
16+
ConfigDir string `json:"config_dir"`
17+
CustomizedConfigDir string `json:"customized_config_dir"`
18+
Host string `json:"host"`
19+
IDC string `json:"idc"`
20+
ScanSeconds int64 `json:"scan_seconds"`
21+
OffsetDir string `json:"offset_dir"`
22+
Sinker flume.Config `json:"sinker"`
2223
}
2324

2425
type Service struct {
@@ -65,6 +66,10 @@ func LoadConf(path string) (c Conf, err error) {
6566
c.ConfigDir = "/home/qboxserver/logsync/_package/confs"
6667
}
6768

69+
if c.CustomizedConfigDir == "" {
70+
c.CustomizedConfigDir = "/home/qboxserver/pili-dsync/_package/confs"
71+
}
72+
6873
return
6974
}
7075

go/src/pili.qiniu.com/dsync.v1/main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ func Main(configFile string) {
2222
log.Fatalln("LoadServices failed :", err)
2323
}
2424

25+
nowSrvs1, err := LoadServices(conf.CustomizedConfigDir)
26+
if err != nil {
27+
log.Fatalln("LoadServices failed :", err)
28+
}
29+
30+
for k, v := range nowSrvs1 {
31+
nowSrvs[k] = v
32+
}
33+
2534
for k, v := range nowSrvs {
2635
if _, ok := oldSrvs[k]; !ok {
2736
go func(x Service) {

go/src/pili.qiniu.com/dsync.v1/parse.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ var (
3636
StrWs = "WS"
3737
StrDocker = "DOCKER"
3838
StrPili = "PILI"
39+
StrAUDIT = "AUDIT"
3940
BytesReq = []byte("REQ")
4041
)
4142

@@ -65,6 +66,8 @@ func ParseTime(line []byte, typ string) (ts int64, err error) {
6566
t, err = parseOVS(line)
6667
case Str3TEE:
6768
t, err = parseTime3tee(line)
69+
case StrAUDIT:
70+
t, err = parseAudit(line)
6871
default:
6972
panic(typ)
7073
}
@@ -265,6 +268,18 @@ func parsePili(line []byte) (t time.Time, err error) {
265268
return
266269
}
267270

271+
// {"time":1473345370,"duration":5,"room_id":"1378262837-5451333","user_id":"7938805"}
272+
func parseAudit(line []byte) (t time.Time, err error) {
273+
d := struct {
274+
T int64 `json:"time"`
275+
}{}
276+
if err = json.Unmarshal(line, &d); err != nil {
277+
return
278+
}
279+
t = time.Unix(d.T, 0)
280+
return
281+
}
282+
268283
// https://pm.qbox.me/issues/25864
269284
// 2016-03-03T22:55:40.635Z|04473|connmgr|INFO|qcos-br0<->tcp:192.168.63.30:6603: 14 flow_mods in the 57 s starting 59 s ago (14 adds)
270285
func parseOVS(line []byte) (t time.Time, err error) {

go/src/pili.qiniu.com/dsync.v1/parse_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ func TestParseTime(t *testing.T) {
107107
StrApp,
108108
1444432800000000000,
109109
},
110+
{
111+
`{"time":1473345375,"duration":5,"room_id":"1378262837-5451333","user_id":"6583953"}`,
112+
StrAUDIT,
113+
1473345375000000000,
114+
},
110115
{
111116
`2015-10-10 07:20:00.09s [:0000001f DEBUG http req: /rtc/room/create]`,
112117
Str3TEE,

0 commit comments

Comments
 (0)