修复参数初始化为空的 bug

This commit is contained in:
hebo 2021-01-24 23:10:08 +08:00
parent ddae41dbe2
commit af65b75f03
3 changed files with 22 additions and 13 deletions

14
main.go
View File

@ -3,13 +3,14 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
sd "github.com/zr-hebo/sniffer-agent/session-dealer"
"github.com/zr-hebo/sniffer-agent/session-dealer/mysql"
"os" "os"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/zr-hebo/sniffer-agent/capture" "github.com/zr-hebo/sniffer-agent/capture"
"github.com/zr-hebo/sniffer-agent/exporter"
"github.com/zr-hebo/sniffer-agent/communicator" "github.com/zr-hebo/sniffer-agent/communicator"
sd "github.com/zr-hebo/sniffer-agent/session-dealer" "github.com/zr-hebo/sniffer-agent/exporter"
) )
var ( var (
@ -39,8 +40,7 @@ func initLog() {
func main() { func main() {
flag.Parse() flag.Parse()
initLog() prepareEnv()
sd.CheckParams()
go communicator.Server() go communicator.Server()
mainServer() mainServer()
@ -61,3 +61,9 @@ func mainServer() {
log.Errorf("cannot get network package from %s", capture.DeviceName) log.Errorf("cannot get network package from %s", capture.DeviceName)
os.Exit(1) os.Exit(1)
} }
func prepareEnv() {
initLog()
sd.CheckParams()
mysql.PrepareEnv()
}

View File

@ -16,11 +16,10 @@ var (
strictMode bool strictMode bool
adminUser string adminUser string
adminPasswd string adminPasswd string
// MaxMysqlPacketLen is the max packet payload length. // MaxMySQLPacketLen is the max packet payload length.
MaxMysqlPacketLen int MaxMySQLPacketLen int
coverRangePool = NewCoveragePool() coverRangePool = NewCoveragePool()
localStmtCache = util.NewSliceBufferPool("statement cache", MaxMysqlPacketLen) localStmtCache *util.SliceBufferPool
PrepareStatement = []byte(":prepare") PrepareStatement = []byte(":prepare")
) )
@ -28,7 +27,11 @@ func init() {
flag.BoolVar(&strictMode,"strict_mode", false, "strict mode. Default is false") flag.BoolVar(&strictMode,"strict_mode", false, "strict mode. Default is false")
flag.StringVar(&adminUser,"admin_user", "", "admin user name. When set strict mode, must set admin user to query session info") flag.StringVar(&adminUser,"admin_user", "", "admin user name. When set strict mode, must set admin user to query session info")
flag.StringVar(&adminPasswd,"admin_passwd", "", "admin user passwd. When use strict mode, must set admin user to query session info") flag.StringVar(&adminPasswd,"admin_passwd", "", "admin user passwd. When use strict mode, must set admin user to query session info")
flag.IntVar(&MaxMysqlPacketLen, "max_packet_length", 128 * 1024, "max mysql packet length. Default is 128 * 1024") flag.IntVar(&MaxMySQLPacketLen, "max_packet_length", 128 * 1024, "max mysql packet length. Default is 128 * 1024")
}
func PrepareEnv() {
localStmtCache = util.NewSliceBufferPool("statement cache", MaxMySQLPacketLen)
} }
func CheckParams() { func CheckParams() {

View File

@ -158,8 +158,8 @@ func (ms *MysqlSession) readFromClient(seqID int64, bytes []byte) {
ms.expectReceiveSize = extractMysqlPayloadSize(bytes[:4]) ms.expectReceiveSize = extractMysqlPayloadSize(bytes[:4])
// ignore too big mysql packet // ignore too big mysql packet
if ms.expectReceiveSize >= MaxMysqlPacketLen { if ms.expectReceiveSize >= MaxMySQLPacketLen {
log.Infof("expect receive size is bigger than max deal size: %d", MaxMysqlPacketLen) log.Infof("expect receive size is bigger than max deal size: %d", MaxMySQLPacketLen)
return return
} }
@ -185,7 +185,7 @@ func (ms *MysqlSession) readFromClient(seqID int64, bytes []byte) {
} else { } else {
// ignore too big mysql packet // ignore too big mysql packet
if ms.expectReceiveSize >= MaxMysqlPacketLen { if ms.expectReceiveSize >= MaxMySQLPacketLen {
return return
} }