Skip to content

Commit

Permalink
Add request_tid and response_tid for trace labels (#379)
Browse files Browse the repository at this point in the history
Signed-off-by: huxiangyuan <huxiangyuan@harmonycloud.cn>
  • Loading branch information
hocktea214 authored Dec 2, 2022
1 parent d704650 commit 339eefa
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


### Enhancements
- Add request_tid and response_tid for trace labels.([#379](https://github.com/KindlingProject/kindling/pull/379))
- Add no_response_threshold(120s) for No response requests. ([#376](https://github.com/KindlingProject/kindling/pull/376))
- Add payload for all protocols.([#375](https://github.com/KindlingProject/kindling/pull/375))
- Add a new clustering method "blank" that is used to reduce the cardinality of metrics as much as possible. ([#372](https://github.com/KindlingProject/kindling/pull/372))
Expand Down
15 changes: 15 additions & 0 deletions collector/pkg/component/analyzer/network/network_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,8 @@ func (na *NetworkAnalyzer) getConnectFailRecords(mps *messagePairs) []*model.Dat
ret.UpdateAddIntMetric(constvalues.ConnectTime, int64(mps.connects.getDuration()))
ret.UpdateAddIntMetric(constvalues.RequestTotalTime, int64(mps.connects.getDuration()))
ret.Labels.UpdateAddIntValue(constlabels.Pid, int64(evt.GetPid()))
ret.Labels.UpdateAddIntValue(constlabels.RequestTid, 0)
ret.Labels.UpdateAddIntValue(constlabels.ResponseTid, 0)
ret.Labels.UpdateAddStringValue(constlabels.Comm, evt.GetComm())
ret.Labels.UpdateAddStringValue(constlabels.SrcIp, evt.GetSip())
ret.Labels.UpdateAddStringValue(constlabels.DstIp, evt.GetDip())
Expand Down Expand Up @@ -532,6 +534,7 @@ func (na *NetworkAnalyzer) getRecords(mps *messagePairs, protocol string, attrib
ret := na.dataGroupPool.Get()
labels := ret.Labels
labels.UpdateAddIntValue(constlabels.Pid, int64(evt.GetPid()))
addTid(labels, evt, mps.responses)
labels.UpdateAddStringValue(constlabels.Comm, evt.GetComm())
labels.UpdateAddStringValue(constlabels.SrcIp, evt.GetSip())
labels.UpdateAddStringValue(constlabels.DstIp, evt.GetDip())
Expand Down Expand Up @@ -588,6 +591,7 @@ func (na *NetworkAnalyzer) getRecordWithSinglePair(mps *messagePairs, mp *messag
ret := na.dataGroupPool.Get()
labels := ret.Labels
labels.UpdateAddIntValue(constlabels.Pid, int64(evt.GetPid()))
addTid(labels, evt, mps.responses)
labels.UpdateAddStringValue(constlabels.Comm, evt.GetComm())
labels.UpdateAddStringValue(constlabels.SrcIp, evt.GetSip())
labels.UpdateAddStringValue(constlabels.DstIp, evt.GetDip())
Expand Down Expand Up @@ -632,10 +636,21 @@ func (na *NetworkAnalyzer) getRecordWithSinglePair(mps *messagePairs, mp *messag
return ret
}

func addTid(labels *model.AttributeMap, evt *model.KindlingEvent, responses *events) {
labels.UpdateAddIntValue(constlabels.RequestTid, int64(evt.GetTid()))
if responses != nil {
labels.UpdateAddIntValue(constlabels.ResponseTid, int64(responses.event.GetTid()))
} else {
labels.UpdateAddIntValue(constlabels.ResponseTid, 0)
}
}

func addProtocolPayload(protocolName string, labels *model.AttributeMap, request []byte, response []byte) {
labels.UpdateAddStringValue(constlabels.RequestPayload, protocol.GetPayloadString(request, protocolName))
if response != nil {
labels.UpdateAddStringValue(constlabels.ResponsePayload, protocol.GetPayloadString(response, protocolName))
} else {
labels.UpdateAddStringValue(constlabels.ResponsePayload, "")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ trace:
Labels:
comm: "systemd-resolve"
pid: 577
request_tid: 577
response_tid: 577
src_ip: "127.0.0.1"
src_port: 60129
dst_ip: "127.0.0.53"
Expand Down Expand Up @@ -101,6 +103,8 @@ trace:
Labels:
comm: "systemd-resolve"
pid: 577
request_tid: 577
response_tid: 577
src_ip: "127.0.0.1"
src_port: 60129
dst_ip: "127.0.0.53"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ trace:
Labels:
comm: "java"
pid: 942
request_tid: 954
response_tid: 954
src_ip: "127.0.0.1"
src_port: 41458
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ trace:
Labels:
comm: testdemo
pid: 12345
request_tid: 12346
response_tid: 12346
src_ip: "127.0.0.1"
src_port: 56266
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ trace:
Labels:
comm: testdemo
pid: 12345
request_tid: 12346
response_tid: 12346
src_ip: "127.0.0.1"
src_port: 56266
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ trace:
Labels:
comm: testdemo
pid: 12345
request_tid: 12346
response_tid: 12346
src_ip: "127.0.0.1"
src_port: 56266
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ trace:
Labels:
comm: testdemo
pid: 12345
request_tid: 12346
response_tid: 12346
src_ip: "127.0.0.1"
src_port: 56266
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ trace:
Labels:
comm: "rdk:broker1"
pid: 925
request_tid: 937
response_tid: 937
src_ip: "127.0.0.1"
src_port: 38970
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ trace:
Labels:
comm: "rdk:broker1"
pid: 925
request_tid: 937
response_tid: 937
src_ip: "127.0.0.1"
src_port: 38970
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ trace:
Labels:
comm: "rdk:broker1"
pid: 942
request_tid: 954
response_tid: 954
src_ip: "127.0.0.1"
src_port: 38966
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ trace:
Labels:
comm: "mysqld"
pid: 903
request_tid: 2744
response_tid: 2744
src_ip: "127.0.0.1"
src_port: 49368
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ trace:
Labels:
comm: "mysqld"
pid: 903
request_tid: 2744
response_tid: 2744
src_ip: "127.0.0.1"
src_port: 49368
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ trace:
Labels:
comm: "redis-server"
pid: 817
request_tid: 817
response_tid: 817
src_ip: "127.0.0.1"
src_port: 39130
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ trace:
Labels:
comm: "rocketmq-server"
pid: 12346
request_tid: 12347
response_tid: 12347
src_ip: "127.0.0.1"
src_port: 45678
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ trace:
Labels:
comm: "rocketmq-server"
pid: 12346
request_tid: 12347
response_tid: 12347
src_ip: "127.0.0.1"
src_port: 45678
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ trace:
Labels:
comm: "rocketmq-server"
pid: 12346
request_tid: 12347
response_tid: 12347
src_ip: "127.0.0.1"
src_port: 45678
dst_ip: "127.0.0.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ var SpanDicList = []dictionary{
{constlabels.SrcNode, constlabels.SrcNode, String},
{constlabels.SrcPod, constlabels.SrcPod, String},
{constlabels.Pid, constlabels.Pid, Int64},
{constlabels.RequestTid, constlabels.RequestTid, Int64},
{constlabels.ResponseTid, constlabels.ResponseTid, Int64},
{constlabels.Comm, constlabels.Comm, String},
}

Expand Down
2 changes: 2 additions & 0 deletions collector/pkg/model/constlabels/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const (
const (
Comm = "comm"
Pid = "pid"
RequestTid = "request_tid"
ResponseTid = "response_tid"
Tid = "tid"
Protocol = "protocol"
IsError = "is_error"
Expand Down
12 changes: 12 additions & 0 deletions collector/pkg/model/kindling_event_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ func (x *KindlingEvent) GetPid() uint32 {
return threadInfo.Pid
}

func (x *KindlingEvent) GetTid() uint32 {
ctx := x.GetCtx()
if ctx == nil {
return 0
}
threadInfo := ctx.GetThreadInfo()
if threadInfo == nil {
return 0
}
return threadInfo.Tid
}

func (x *KindlingEvent) GetComm() string {
ctx := x.GetCtx()
if ctx == nil {
Expand Down

0 comments on commit 339eefa

Please sign in to comment.