gorr

package module
v0.0.0-...-9c0a1c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2021 License: MIT Imports: 43 Imported by: 0

README

gorr

set of utilities for recording and replaying golang functions: http/redis/grpc/sql/etc.

Documentation

Index

Constants

View Source
const (
	RegressionNone   = 0
	RegressionRecord = 1
	RegressionReplay = 2
)
View Source
const (
	RegressionResetNone    = 0
	RegressionResetStorage = 0
)
View Source
const (
	RegressionHttpHook    = 100
	RegressionConnHook    = 101
	RegressionRedisHook   = 102
	RegressionGrpcHook    = 103
	RegressionSqlHook     = 104
	RegressionOutputReset = 105
)
View Source
const (
	RecorderDataTypeUnknown  = 23
	RecorderDataTypeJson     = 24
	RecorderDataTypePbText   = 25
	RecorderDataTypePbBinary = 26
	RecorderDataTypeHttpJson = 27
)
View Source
const (
	SqlHookXxxDriver   = "SqlHookXxxDriver"
	SqlHookMysqlDriver = "SqlHookMysqlDriver"
)

Variables

View Source
var (
	GlobalMgr *RegressionMgr

	RegressionRunType               = flag.Int("gorr_run_type", 0, "turn on/off gorr(0 for off, 1 for record, 2 for replay)")
	RegressionDbFile                = flag.String("gorr_db_file", "gorr.db", "file name gorr db")
	RegressionDbDirectory           = flag.String("gorr_db_dir", "/var/data/gorr", "directory to get gorr db")
	RegressionOutputDir             = flag.String("gorr_record_output_dir", "/var/data/conf/gorr", "dir to store auto generated test cases")
	RegressionOutDirRefreshInterval = flag.Int("gorr_output_dir_refresh_interval", 7200, "refresh interval in seconds")
)

Functions

func ConnectViaGorm

func ConnectViaGorm(config *Config) (db *gorm.DB, err error)

func DisableMongoHook

func DisableMongoHook() error

func EnableMongoHook

func EnableMongoHook() error

func GetTimeValAndInc

func GetTimeValAndInc() time.Time

func HookGrpcInvoke

func HookGrpcInvoke() error

func HookHttpFunc

func HookHttpFunc() error

func HookHttpServerHandler

func HookHttpServerHandler() error

func HookKafkaProducer

func HookKafkaProducer() error

func HookMysqlDriver

func HookMysqlDriver() error

func HookRedisFunc

func HookRedisFunc() error

func HookTimeNow

func HookTimeNow() error

func InitRegressionEngine

func InitRegressionEngine() int

func NewAsyncProducerHook

func NewAsyncProducerHook(addrs []string, conf *sarama.Config) (sarama.AsyncProducer, error)

func NewAsyncProducerTramp

func NewAsyncProducerTramp(addrs []string, conf *sarama.Config) (sarama.AsyncProducer, error)

func NewSyncProducerHook

func NewSyncProducerHook(addrs []string, config *sarama.Config) (sarama.SyncProducer, error)

func RecordData

func RecordData(uri, outDir, name string, req []byte, t1 int, rsp []byte, t2 int, desc string, db []string) (string, error)

func RecordGrpc

func RecordGrpc(outDir, desc string, req proto.Message, rsp proto.Message, db []string) (string, error)

func RecordHttp

func RecordHttp(outDir, desc string, req *http.Request, rsp *http.Response, db []string) (string, error)

func RecordHttpExt

func RecordHttpExt(uri, desc, name string, head http.Header, req, rsp []byte, t1, t2 int) (string, error)

func RegisterHttpRecorder

func RegisterHttpRecorder(pattern string, handler HttpRecorderHandler, fix HttpRequestFixer)

func RunTestCaseUploader

func RunTestCaseUploader()

func SetTimeIncDelta

func SetTimeIncDelta(d time.Duration)

func SetUnixTime

func SetUnixTime(val time.Time)

func UnHookGrpcInvoke

func UnHookGrpcInvoke() error

func UnHookHttpFunc

func UnHookHttpFunc() error

func UnHookHttpServerHandler

func UnHookHttpServerHandler() error

func UnHookKafkaProducer

func UnHookKafkaProducer() error

func UnHookMysqlDriver

func UnHookMysqlDriver() error

func UnHookRedisFunc

func UnHookRedisFunc() error

Types

type AsyncProducerHook

type AsyncProducerHook struct {
	// contains filtered or unexported fields
}

func (*AsyncProducerHook) AsyncClose

func (ap *AsyncProducerHook) AsyncClose()

func (*AsyncProducerHook) Close

func (ap *AsyncProducerHook) Close() error

func (*AsyncProducerHook) Errors

func (ap *AsyncProducerHook) Errors() <-chan *sarama.ProducerError

func (*AsyncProducerHook) GetOriginProducer

func (ap *AsyncProducerHook) GetOriginProducer() sarama.AsyncProducer

func (*AsyncProducerHook) Input

func (ap *AsyncProducerHook) Input() chan<- *sarama.ProducerMessage

func (*AsyncProducerHook) Successes

func (ap *AsyncProducerHook) Successes() <-chan *sarama.ProducerMessage

type BoltStorage

type BoltStorage struct {
	// contains filtered or unexported fields
}

func NewBoltStorage

func NewBoltStorage(path string) (*BoltStorage, error)

bolt key/value db

func (*BoltStorage) AllFiles

func (s *BoltStorage) AllFiles() []string

func (*BoltStorage) Clear

func (s *BoltStorage) Clear()

func (*BoltStorage) Close

func (s *BoltStorage) Close()

func (*BoltStorage) Get

func (s *BoltStorage) Get(key string) ([]byte, error)

func (*BoltStorage) GetBigValueFile

func (s *BoltStorage) GetBigValueFile(key string) (string, error)

func (*BoltStorage) Put

func (s *BoltStorage) Put(key string, value []byte) error

type CmdValue

type CmdValue struct {
	// contains filtered or unexported fields
}

type Config

type Config struct {
	Host               string        // 主机或域名
	Port               int32         // 端口
	Username           string        // 用户名
	Password           string        // 密码
	DbName             string        // 数据库名
	Charset            string        // 字符集
	ConnectionSize     int32         // 连接数量
	ConnectionLifetime time.Duration // 连接生命周期
	MaxIdleConnection  int32         // 连接最大空闲时间

	Loc string // 时区
}

type CursorData

type CursorData struct {
	Id   int64
	Err  string
	Data []bson.Raw
}

type DbStorage

type DbStorage struct {
	//TODO:读写分离
	DbConn *gorm.DB
}

func NewDbStorage

func NewDbStorage() *DbStorage

func (*DbStorage) AllFiles

func (s *DbStorage) AllFiles() []string

func (*DbStorage) Clear

func (s *DbStorage) Clear()

func (*DbStorage) Close

func (s *DbStorage) Close()

func (*DbStorage) Get

func (s *DbStorage) Get(key string) ([]byte, error)

func (*DbStorage) Put

func (s *DbStorage) Put(key string, value []byte) error

type GrpcHookRequest

type GrpcHookRequest struct {
	ReqId                int32    `protobuf:"varint,1,opt,name=req_id,json=reqId,proto3" json:"req_id,omitempty"`
	ReqName              string   `protobuf:"bytes,2,opt,name=req_name,json=reqName,proto3" json:"req_name,omitempty"`
	ReqData              string   `protobuf:"bytes,3,opt,name=req_data,json=reqData,proto3" json:"req_data,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*GrpcHookRequest) Descriptor

func (*GrpcHookRequest) Descriptor() ([]byte, []int)

func (*GrpcHookRequest) GetReqData

func (m *GrpcHookRequest) GetReqData() string

func (*GrpcHookRequest) GetReqId

func (m *GrpcHookRequest) GetReqId() int32

func (*GrpcHookRequest) GetReqName

func (m *GrpcHookRequest) GetReqName() string

func (*GrpcHookRequest) ProtoMessage

func (*GrpcHookRequest) ProtoMessage()

func (*GrpcHookRequest) Reset

func (m *GrpcHookRequest) Reset()

func (*GrpcHookRequest) String

func (m *GrpcHookRequest) String() string

func (*GrpcHookRequest) XXX_DiscardUnknown

func (m *GrpcHookRequest) XXX_DiscardUnknown()

func (*GrpcHookRequest) XXX_Marshal

func (m *GrpcHookRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GrpcHookRequest) XXX_Merge

func (m *GrpcHookRequest) XXX_Merge(src proto.Message)

func (*GrpcHookRequest) XXX_Size

func (m *GrpcHookRequest) XXX_Size() int

func (*GrpcHookRequest) XXX_Unmarshal

func (m *GrpcHookRequest) XXX_Unmarshal(b []byte) error

type GrpcHookResponse

type GrpcHookResponse struct {
	RspId                int32    `protobuf:"varint,1,opt,name=rsp_id,json=rspId,proto3" json:"rsp_id,omitempty"`
	ReqId                int32    `protobuf:"varint,2,opt,name=req_id,json=reqId,proto3" json:"req_id,omitempty"`
	RspName              string   `protobuf:"bytes,3,opt,name=rsp_name,json=rspName,proto3" json:"rsp_name,omitempty"`
	RspData              string   `protobuf:"bytes,4,opt,name=rsp_data,json=rspData,proto3" json:"rsp_data,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

func (*GrpcHookResponse) Descriptor

func (*GrpcHookResponse) Descriptor() ([]byte, []int)

func (*GrpcHookResponse) GetReqId

func (m *GrpcHookResponse) GetReqId() int32

func (*GrpcHookResponse) GetRspData

func (m *GrpcHookResponse) GetRspData() string

func (*GrpcHookResponse) GetRspId

func (m *GrpcHookResponse) GetRspId() int32

func (*GrpcHookResponse) GetRspName

func (m *GrpcHookResponse) GetRspName() string

func (*GrpcHookResponse) ProtoMessage

func (*GrpcHookResponse) ProtoMessage()

func (*GrpcHookResponse) Reset

func (m *GrpcHookResponse) Reset()

func (*GrpcHookResponse) String

func (m *GrpcHookResponse) String() string

func (*GrpcHookResponse) XXX_DiscardUnknown

func (m *GrpcHookResponse) XXX_DiscardUnknown()

func (*GrpcHookResponse) XXX_Marshal

func (m *GrpcHookResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*GrpcHookResponse) XXX_Merge

func (m *GrpcHookResponse) XXX_Merge(src proto.Message)

func (*GrpcHookResponse) XXX_Size

func (m *GrpcHookResponse) XXX_Size() int

func (*GrpcHookResponse) XXX_Unmarshal

func (m *GrpcHookResponse) XXX_Unmarshal(b []byte) error

type GrpcHookServiceClient

type GrpcHookServiceClient interface {
	SomeCall(ctx context.Context, in *GrpcHookRequest, opts ...grpc.CallOption) (*GrpcHookResponse, error)
}

GrpcHookServiceClient is the client API for GrpcHookService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewGrpcHookServiceClient

func NewGrpcHookServiceClient(cc *grpc.ClientConn) GrpcHookServiceClient

type GrpcHookServiceServer

type GrpcHookServiceServer interface {
	SomeCall(context.Context, *GrpcHookRequest) (*GrpcHookResponse, error)
}

GrpcHookServiceServer is the server API for GrpcHookService service.

type HttpData

type HttpData struct {
	Status int
	Body   []byte
	Header http.Header
}

type HttpRecorderHandler

type HttpRecorderHandler func(pattern, desc string, req *HttpData, rsp *HttpData)

type HttpRequestFixer

type HttpRequestFixer func(pattern string, data []byte) []byte

type HttpResponseData

type HttpResponseData struct {
	Status        string      `json:"status"`
	StatusCode    int         `json:"code"`
	Proto         string      `json:"proto"`
	ProtoMajor    int         `json:"major"`
	ProtoMinor    int         `json:"minor"`
	Header        http.Header `json:"header"`
	Body          []byte      `json:"body"`
	ContentLength int64       `json:"length"`
}

type HttpSerializedData

type HttpSerializedData struct {
	Body     []byte              `json:"body"`
	BodyType int                 `json:"btype"`
	Header   map[string][]string `json:"header"`
}

type MapStorage

type MapStorage struct {
	// contains filtered or unexported fields
}

func NewMapStorage

func NewMapStorage(capacity int) *MapStorage

func (*MapStorage) AllFiles

func (s *MapStorage) AllFiles() []string

func (*MapStorage) Clear

func (s *MapStorage) Clear()

func (*MapStorage) Close

func (s *MapStorage) Close()

func (*MapStorage) Get

func (s *MapStorage) Get(key string) ([]byte, error)

func (*MapStorage) Put

func (s *MapStorage) Put(key string, value []byte) error

type MiddlewareRecordModel

type MiddlewareRecordModel struct {
	Key   string `gorm:"column:key"`
	Value string `gorm:"column:value"`
}

func (*MiddlewareRecordModel) TableName

func (*MiddlewareRecordModel) TableName() string

type MoveData

type MoveData struct {
	Src string `json:"src"`
	Dst string `json:"dst"`
}

type RegressionMgr

type RegressionMgr struct {
	// contains filtered or unexported fields
}

func (*RegressionMgr) ClearStorage

func (r *RegressionMgr) ClearStorage()

func (*RegressionMgr) DisableHook

func (r *RegressionMgr) DisableHook()

func (*RegressionMgr) EnableGenKey

func (r *RegressionMgr) EnableGenKey()

func (*RegressionMgr) EnableHook

func (r *RegressionMgr) EnableHook() error

func (*RegressionMgr) GetCurTraceId

func (r *RegressionMgr) GetCurTraceId() string

func (*RegressionMgr) GetCurrentTestSuitDir

func (r *RegressionMgr) GetCurrentTestSuitDir() string

func (*RegressionMgr) GetDbFiles

func (r *RegressionMgr) GetDbFiles() []string

func (*RegressionMgr) GetDebugInfo

func (r *RegressionMgr) GetDebugInfo() string

func (*RegressionMgr) GetValue

func (r *RegressionMgr) GetValue(key string) ([]byte, error)

func (*RegressionMgr) IsGenKeyEnabled

func (r *RegressionMgr) IsGenKeyEnabled() bool

func (*RegressionMgr) ResetTestSuitDir

func (r *RegressionMgr) ResetTestSuitDir() string

func (*RegressionMgr) SetBoltStorage

func (r *RegressionMgr) SetBoltStorage(path string) error

func (*RegressionMgr) SetBoltStorageFile

func (r *RegressionMgr) SetBoltStorageFile(file string) error

func (*RegressionMgr) SetCurTraceId

func (r *RegressionMgr) SetCurTraceId() error

func (*RegressionMgr) SetGenKey

func (r *RegressionMgr) SetGenKey(fn func(int, context.Context, interface{}) string)

func (*RegressionMgr) SetNotify

func (r *RegressionMgr) SetNotify(fn func(string, string, []byte))

func (*RegressionMgr) SetReset

func (r *RegressionMgr) SetReset(fn func(int))

func (*RegressionMgr) SetState

func (r *RegressionMgr) SetState(state int)

func (*RegressionMgr) SetStorage

func (r *RegressionMgr) SetStorage(s Storage)

func (*RegressionMgr) ShouldRecord

func (r *RegressionMgr) ShouldRecord() bool

func (*RegressionMgr) StoreValue

func (r *RegressionMgr) StoreValue(key string, data []byte) error

type SingleResultData

type SingleResultData struct {
	Err  string
	Data bson.Raw
}

type Storage

type Storage interface {
	Clear()
	Close()
	AllFiles() []string
	Put(key string, value []byte) error
	Get(key string) ([]byte, error)
}

type SyncProducerHook

type SyncProducerHook struct {
	// contains filtered or unexported fields
}

/////////////////sync producer hook: copyed from sarama.SyncProducer ///////////////////////////

func (*SyncProducerHook) Close

func (sp *SyncProducerHook) Close() error

func (*SyncProducerHook) GetAsyncProducer

func (sp *SyncProducerHook) GetAsyncProducer() sarama.AsyncProducer

func (*SyncProducerHook) SendMessage

func (sp *SyncProducerHook) SendMessage(msg *sarama.ProducerMessage) (partition int32, offset int64, err error)

func (*SyncProducerHook) SendMessages

func (sp *SyncProducerHook) SendMessages(msgs []*sarama.ProducerMessage) error

type TestCase

type TestCase struct {
	Req     string `json:"req"`
	Rsp     string `json:"rsp"`
	ReqType int    `json:"ReqType"`
	RspType int    `json:"RspType"`
	Desc    string `json:"Desc"`
	URI     string `json:"Uri"`
	Runner  string `json:"runner"`
}

type TestItem

type TestItem struct {
	DB          []string    `json:"db"`
	Flags       []string    `json:"flags,omitempty"`
	Input       []MoveData  `json:"input,omitempty"`
	TestCases   []*TestCase `json:"cases"`
	Version     int         `json:"version"`
	EnvFlagFile string      `json:"env_flag_files,omitempty"`
}

type UnimplementedGrpcHookServiceServer

type UnimplementedGrpcHookServiceServer struct {
}

UnimplementedGrpcHookServiceServer can be embedded to have forward compatible implementations.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL