Skip to content

Commit

Permalink
Fix networkanalyzer nil pointer if the protocol is NOSUPPORT with nil…
Browse files Browse the repository at this point in the history
… attributes (#416)

Signed-off-by: huxiangyuan <huxiangyuan@harmonycloud.cn>
  • Loading branch information
hocktea214 authored Dec 22, 2022
1 parent b86eb37 commit 400d7ce
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 11 deletions.
4 changes: 2 additions & 2 deletions collector/pkg/component/analyzer/network/network_analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (na *NetworkAnalyzer) distributeTraceMetric(oldPairs *messagePairs, newPair
return nil
}

if oldPairs.checkSend() == false {
if !oldPairs.checkSend() {
// FIX send twice for request/response with 15s delay.
return nil
}
Expand Down Expand Up @@ -545,7 +545,7 @@ func (na *NetworkAnalyzer) getConnectFailRecords(mps *messagePairs) []*model.Dat
func (na *NetworkAnalyzer) getRecords(mps *messagePairs, protocol string, attributes *model.AttributeMap) []*model.DataGroup {
evt := mps.requests.event
// See the issue https://github.com/KindlingProject/kindling/issues/388 for details.
if attributes.HasAttribute(constlabels.HttpContinue) {
if attributes != nil && attributes.HasAttribute(constlabels.HttpContinue) {
if pairInterface, ok := na.requestMonitor.Load(getMessagePairKey(evt)); ok {
var oldPairs = pairInterface.(*messagePairs)
oldPairs.putRequestBack(mps.requests)
Expand Down
25 changes: 16 additions & 9 deletions collector/pkg/component/analyzer/network/network_analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ func TestRocketMQProtocol(t *testing.T) {
"rocketmq/server-trace-error.yml")
}

func TestNoSupportProtocol(t *testing.T) {
testProtocol(t, "nosupport/server-event.yml",
"nosupport/server-trace-normal.yml",
)
}

type NopProcessor struct {
}

Expand Down Expand Up @@ -394,15 +400,16 @@ func (evt *TraceEvent) exchange(common *EventCommon) *model.KindlingEvent {
// getData converts the following format to byte array.
//
// There are the following formats supported:
// 1. {hex number}|{string}
// The first part is a number in hexadecimal which is part of the original data.
// It holds different meanings in different protocols.
// 2. (hex)|{hex value}
// The first part is the constant "hex" and the second part is its value
// 3. (string)|{string value}
// The first part is the constant "string" and the second part is its value
// 4. {string value}
// If there are no the separator "|" existing, the data is considered as a string
// 1. {hex number}|{string}
// The first part is a number in hexadecimal which is part of the original data.
// It holds different meanings in different protocols.
// 2. (hex)|{hex value}
// The first part is the constant "hex" and the second part is its value
// 3. (string)|{string value}
// The first part is the constant "string" and the second part is its value
// 4. {string value}
// If there are no the separator "|" existing, the data is considered as a string
//
// See the files under the "testdata" directory for how to write your data.
func getData(datas []string) ([]byte, error) {
dataBytes := make([]byte, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ analyzers:
slow_threshold: 100
- key: "rocketmq"
slow_threshold: 500
- key: "NOSUPPORT"
ports: [ 1111 ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# localhost:49368 -> localhost:1111
eventCommon:
# SYSCALL_EXIT
source: 2
# CAT_NET
category: 3
ctx:
thread_info:
pid: 100
tid: 101
uid: 1
gid: 1
comm: "test"
fd_info:
num: 4
# FD_IPV4_SOCK
type_fd: 3
# TCP
protocol: 1
# IsServer
role: true
sip: [16777343]
sport: 49368
dip: [16777343]
dport: 1111
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
trace:
key: normal
requests:
-
name: "recvfrom"
timestamp: 100000000
user_attributes:
latency: 2000
res: 15
data:
- "This is a query"
responses:
-
name: "sendto"
timestamp: 100020000
user_attributes:
latency: 15000
res: 18
data:
- "This is a response"
expects:
-
Timestamp: 99998000
Values:
request_total_time: 22000
connect_time: 0
request_sent_time: 2000
waiting_ttfb_time: 5000
content_download_time: 15000
request_io: 15
response_io: 18
Labels:
comm: "test"
pid: 100
request_tid: 101
response_tid: 101
src_ip: "127.0.0.1"
src_port: 49368
dst_ip: "127.0.0.1"
dst_port: 1111
dnat_ip: ""
dnat_port: -1
container_id: ""
is_slow: false
is_server: true
protocol: "NOSUPPORT"
request_payload: "This is a query"
response_payload: "This is a response"
is_error: false
error_type: 0
end_timestamp: 100020000

0 comments on commit 400d7ce

Please sign in to comment.