Skip to content

Commit

Permalink
v0.0.16 release~!!
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Aug 21, 2023
1 parent 146e229 commit 14e1b55
Show file tree
Hide file tree
Showing 18 changed files with 535 additions and 49 deletions.
18 changes: 14 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
module github.com/whatap/golib

go 1.14
go 1.17

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/google/uuid v1.3.0
github.com/kr/pretty v0.3.0 // indirect
github.com/magiconair/properties v1.8.7
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/stretchr/testify v1.8.1
golang.org/x/text v0.7.0
)

require (
github.com/BurntSushi/toml v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/text v0.7.0
golang.org/x/sys v0.2.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
11 changes: 11 additions & 0 deletions lang/EventLevel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package lang

const (
EVENT_LEVEL_CRITICAL = 30
EVENT_LEVEL_WARNING = 20
EVENT_LEVEL_INFO = 10
EVENT_LEVEL_NONE = 0
)

var EventLevelName = map[int]string{30: "CRITICAL", 20: "WARNING", 10: "INFO", 0: "NONE"}
var EventLevelValue = map[string]int{"CRITICAL": 30, "WARNING": 20, "INFO": 10, "NONE": 0}
26 changes: 26 additions & 0 deletions lang/MessageConst.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package lang

const (
MESSAGE_FILE_WRITE_OPEN = "FileWriteOpen"
MESSAGE_FILE_READ_OPEN = "FileReadOpen"
MESSAGE_JSP = "JSP"
MESSAGE_CLOSE_CONNECTION = "Close Connection"
MESSAGE_TRANSACTION_BACKSTACK = "TRANSACTION BACKSTACK"
MESSAGE_PREPARED_SQL = "prepare-sql"
MESSAGE_OPEN_CONNECTION_STACK = "Open Connection Stack"
MESSAGE_CAP_ARG = "TraceArgs"
MESSAGE_CAP_RETURN = "TraceReturn"
MESSAGE_CAP_THIS = "TraceConstructor"
MESSAGE_CONN_ALLOC_DUP = "Connection allocated to multi-threads"
MESSAGE_THREAD_START = "Thread-Start"
MESSAGE_SOCKET_OPEN = "SocketOpen"
MESSAGE_CUSTOM_OPEN = "CustomOpen"
MESSAGE_CUSTOM_CLOSE = "CustomClose"
MESSAGE_ASYNC_CTX = "AsyncCtx"
MESSAGE_EXCEPTION = "EXCEPTION"
MESSAGE_THREAD_CHILD = "Child-Thread-Call"
MESSAGE_ORIGIN_URL = "OriginURL"
MESSAGE_MESSAGE = "MESSAGE"
MESSAGE_METHOD_DEBUG = "Debug-Method"
MESSAGE_VIRTUAL_TX = "Virtual-Tx"
)
10 changes: 10 additions & 0 deletions lang/pack/AbstractPack.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ func (this *AbstractPack) SetONODE(onode int32) {
this.Onode = onode
}

// Get Time
func (this *AbstractPack) GetTime() int64 {
return this.Time
}

// Set Time
func (this *AbstractPack) SetTime(t int64) {
this.Time = t
}

func (this *AbstractPack) ToString() string {
return fmt.Sprintln("\nPcode=", this.Pcode, ",Oid=", this.Oid, ",Okind=", this.Okind, ",ONode=", this.Onode, ",Time=", this.Time)
}
103 changes: 103 additions & 0 deletions lang/pack/LogSinkZipPack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package pack

import (
"github.com/whatap/golib/io"
"github.com/whatap/golib/util/compressutil"
"github.com/whatap/golib/util/stringutil"
)

const (
ZIPPED = 1
UN_ZIPPED = 0
)

type LogSinkZipPack struct {
AbstractPack

Records []byte
RecordCount int
Status byte
}

func NewLogSinkZipPack() *LogSinkZipPack {
p := new(LogSinkZipPack)
return p
}

func (this *LogSinkZipPack) GetPackType() int16 {
return PACK_LOGSINK_ZIP
}

func (this *LogSinkZipPack) Write(dout *io.DataOutputX) {
this.AbstractPack.Write(dout)

dout.WriteByte(this.Status)
dout.WriteDecimal(int64(this.RecordCount))
dout.WriteBlob(this.Records)
}
func (this *LogSinkZipPack) Read(din *io.DataInputX) {
this.AbstractPack.Read(din)

this.Status = din.ReadByte()
this.RecordCount = int(din.ReadDecimal())
this.Records = din.ReadBlob()
}

func (this *LogSinkZipPack) SetRecords(records []byte, zipMinSize int) {
this.Records, _ = this.doZip(records, zipMinSize)
}

func (this *LogSinkZipPack) doZip(records []byte, zipMinSize int) ([]byte, error) {
if this.Status != UN_ZIPPED {
return records, nil
}
if len(records) < zipMinSize {
return records, nil
}
this.Status = ZIPPED
return compressutil.DoZip(records)
}

func (this *LogSinkZipPack) doUnZip() ([]byte, error) {
if this.Status != ZIPPED {
return this.Records, nil
}
return compressutil.UnZip(this.Records)
}

func (this *LogSinkZipPack) GetRecords() []*LogSinkPack {
items := make([]*LogSinkPack, 0)
if this.Records == nil {
return items
}
data, err := this.doUnZip()
if err != nil {
return items
}

in := io.NewDataInputX(data)
for i := 0; i < this.RecordCount; i++ {
tmp := ReadPack(in)
if tmp != nil {
if p, ok := tmp.(*LogSinkPack); ok {
p.Pcode = this.Pcode
p.Oid = this.Oid
p.Okind = this.Okind
p.Onode = this.Onode
// time 은 자기시간 사용
items = append(items, p)
}
}
}

return items

}

func (this *LogSinkZipPack) ToString() string {
sb := stringutil.NewStringBuffer()
sb.Append("LogSinkZipPack ")
sb.Append(this.AbstractPack.ToString())
sb.AppendFormat("records=%d bytes", len(this.Records))
return sb.ToString()
}
6 changes: 6 additions & 0 deletions lang/pack/Pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ const (
PACK_WEB_CHECK_COUNT = 0x1707
PACK_LOGSINK = 0x170a
PACK_ZIP = 0x170b
PACK_AGENT_MAPPING = 0x170c
PACK_LOGSINK_ZIP = 0x170d

// // 12288
// PACK_SM_BASE = 0x3000
Expand Down Expand Up @@ -124,6 +126,10 @@ type Pack interface {
GetPCODE() int64
SetOKIND(okind int32)
SetONODE(onode int32)

// Time interface 추가
GetTime() int64
SetTime(t int64)
}

func CreatePack(t int16) Pack {
Expand Down
4 changes: 1 addition & 3 deletions lang/pack/ProfileStepSplitPack.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ func (this *ProfileStepSplitPack) Write(dout *io.DataOutputX) {
dout.WriteBlob(this.Steps)
}

func (this *ProfileStepSplitPack) Read(din *io.DataInputX) *ProfileStepSplitPack {
func (this *ProfileStepSplitPack) Read(din *io.DataInputX) {
this.AbstractPack.Read(din)

// ver
din.ReadByte()
this.Txid = din.ReadLong()
this.Inx = int(din.ReadDecimal())
this.Steps = din.ReadBlob()
return this
}

func (this *ProfileStepSplitPack) SetProfile(steps []step.Step) *ProfileStepSplitPack {
Expand Down
9 changes: 9 additions & 0 deletions lang/pack/udp/UdpTxEndPack.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (this *UdpTxEndPack) Write(dout *io.DataOutputX) {
dout.WriteTextShortLength(this.McallerUrl)
dout.WriteTextShortLength(this.McallerPoidKey)
}

if this.Ver >= 10107 {
dout.WriteTextShortLength(stringutil.ParseStringZeroToEmpty(int64(this.Status)))
}
}
}

Expand Down Expand Up @@ -185,6 +189,11 @@ func (this *UdpTxEndPack) Read(din *io.DataInputX) {
this.McallerUrl = din.ReadTextShortLength()
this.McallerPoidKey = din.ReadTextShortLength()
}

if this.Ver >= 10107 {
// reponse code
this.Status = stringutil.ParseInt32(din.ReadTextShortLength())
}
}
}
func (this *UdpTxEndPack) Process() {
Expand Down
49 changes: 39 additions & 10 deletions lang/service/TxRecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package service

import (
"github.com/whatap/golib/io"
"github.com/whatap/golib/lang/value"
"github.com/whatap/golib/util/hash"
)

Expand Down Expand Up @@ -55,7 +56,7 @@ type TxRecord struct {
HttpMethod byte

Domain int32
Fields []*FIELD
Fields *value.MapValue

Login int32

Expand All @@ -71,6 +72,11 @@ type TxRecord struct {

//20210628 -
Apdex byte

McallerStepId int64
OriginUrl string

StepSplitCount int
}

func NewTxRecord() *TxRecord {
Expand Down Expand Up @@ -145,11 +151,22 @@ func (this *TxRecord) Write(dout *io.DataOutputX) {
if this.Fields == nil {
o.WriteByte(0)
} else {
sz := len(this.Fields)
sz := this.Fields.Size()
o.WriteByte(byte(sz))
for i := 0; i < sz; i++ {
o.WriteByte(byte(this.Fields[i].Id))
o.WriteText(this.Fields[i].Value)
keys := this.Fields.Keys()
for keys.HasMoreElements() {
key := keys.NextString()
tmp := this.Fields.Get(key)
if tmp != nil {
if v, ok := tmp.(value.Value); ok {
o.WriteText(key)
value.WriteValue(o, v)
}
} else {
// empty string
o.WriteText(key)
value.WriteValue(o, value.NewTextValue(""))
}
}
}
o.WriteDecimal(int64(this.Login))
Expand All @@ -171,6 +188,12 @@ func (this *TxRecord) Write(dout *io.DataOutputX) {
// 2021.06.28 , java //2021.05.13
o.WriteByte(this.Apdex)

// 2023.07.17 , java //2021.12.10
o.WriteDecimal(this.McallerStepId)
o.WriteText(this.OriginUrl)

o.WriteDecimal(int64(this.StepSplitCount))

////////////// BLOB ///////////////
dout.WriteBlob(o.ToByteArray())
}
Expand Down Expand Up @@ -252,12 +275,11 @@ func (this *TxRecord) Read(din *io.DataInputX) *TxRecord {

n := int(in.ReadByte())
if n > 0 {
this.Fields = make([]*FIELD, n)
this.Fields = value.NewMapValue()
for i := 0; i < n; i++ {
field := NewFIELD()
field.Id = in.ReadByte()
field.Value = in.ReadText()
this.Fields[i] = field
key := in.ReadText()
v := value.ReadValue(in)
this.Fields.Put(key, v)
}
}
//if in.Available() > 0 {
Expand Down Expand Up @@ -286,6 +308,13 @@ func (this *TxRecord) Read(din *io.DataInputX) *TxRecord {
//if in.Available() > 0 {
this.Apdex = in.ReadByte()

//if (in.available() > 0) {
this.McallerStepId = in.ReadDecimal()
this.OriginUrl = in.ReadText()

//if (in.available() > 0) {
this.StepSplitCount = int(in.ReadDecimal())

return this
}

Expand Down
18 changes: 10 additions & 8 deletions lang/service/WebMethod.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package service

import ()

const (
GET byte = 1
POST byte = 2
PUT byte = 3
DELETE byte = 4
GET byte = 1
POST byte = 2
PUT byte = 3
DELETE byte = 4
PATCH byte = 5
OPTIONS byte = 6
HEAD byte = 7
TRACE byte = 8
)

var WebMethodName = map[string]byte{"GET": 1, "POST": 2, "PUT": 3, "DELETE": 4}
var WebMethodValue = map[byte]string{1: "GET", 2: "POST", 3: "PUT", 4: "DELETE"}
var WebMethodName = map[string]byte{"GET": 1, "POST": 2, "PUT": 3, "DELETE": 4, "PATCH": 5, "OPTIONS": 6, "HEAD": 7, "TRACE": 8}
var WebMethodValue = map[byte]string{1: "GET", 2: "POST", 3: "PUT", 4: "DELETE", 5: "PATCH", 6: "OPTIONS", 7: "HEAD", 8: "TRACE"}
4 changes: 4 additions & 0 deletions lang/step/Step.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Step interface {

// interface 함수 추가
GetStartTime() int32
SetStartTime(t int32)

SetParent(v int32)
GetParent() int32
Expand Down Expand Up @@ -77,6 +78,9 @@ type AbstractStep struct {
func (this *AbstractStep) GetStartTime() int32 {
return this.StartTime
}
func (this *AbstractStep) SetStartTime(t int32) {
this.StartTime = t
}

func (this *AbstractStep) SetParent(v int32) {
this.Parent = v
Expand Down
Loading

0 comments on commit 14e1b55

Please sign in to comment.