修复参数初始化为空的 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 (
"flag"
"fmt"
sd "github.com/zr-hebo/sniffer-agent/session-dealer"
"github.com/zr-hebo/sniffer-agent/session-dealer/mysql"
"os"
log "github.com/sirupsen/logrus"
"github.com/zr-hebo/sniffer-agent/capture"
"github.com/zr-hebo/sniffer-agent/exporter"
"github.com/zr-hebo/sniffer-agent/communicator"
sd "github.com/zr-hebo/sniffer-agent/session-dealer"
"github.com/zr-hebo/sniffer-agent/exporter"
)
var (
@ -39,8 +40,7 @@ func initLog() {
func main() {
flag.Parse()
initLog()
sd.CheckParams()
prepareEnv()
go communicator.Server()
mainServer()
@ -61,3 +61,9 @@ func mainServer() {
log.Errorf("cannot get network package from %s", capture.DeviceName)
os.Exit(1)
}
func prepareEnv() {
initLog()
sd.CheckParams()
mysql.PrepareEnv()
}

View File

@ -16,11 +16,10 @@ var (
strictMode bool
adminUser string
adminPasswd string
// MaxMysqlPacketLen is the max packet payload length.
MaxMysqlPacketLen int
// MaxMySQLPacketLen is the max packet payload length.
MaxMySQLPacketLen int
coverRangePool = NewCoveragePool()
localStmtCache = util.NewSliceBufferPool("statement cache", MaxMysqlPacketLen)
localStmtCache *util.SliceBufferPool
PrepareStatement = []byte(":prepare")
)
@ -28,7 +27,11 @@ func init() {
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(&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() {

View File

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