Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support NATS #270

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ jobs:
fi
popd

- name: Test NATS
uses: cilium/little-vm-helper@97c89f004bd0ab4caeacfe92ebc956e13e362e6b # v0.0.19
with:
provision: 'false'
cmd: |
set -ex
uname -a
cat /etc/issue
pushd /host
if [ -f "/var/lib/kyanos/btf/current.btf" ]; then
bash /host/testdata/test_nats.sh 'sudo /host/kyanos/kyanos $kyanos_log_option --btf /var/lib/kyanos/btf/current.btf'
else
bash /host/testdata/test_nats.sh 'sudo /host/kyanos/kyanos $kyanos_log_option'
fi
popd

- name: Test filter by comm
uses: cilium/little-vm-helper@97c89f004bd0ab4caeacfe92ebc956e13e362e6b # v0.0.19
with:
Expand Down
2 changes: 1 addition & 1 deletion agent/protocol/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"kyanos/agent/buffer"
)

func matchByTimestamp(reqStream *ParsedMessageQueue, respStream *ParsedMessageQueue) []Record {
func MatchByTimestamp(reqStream *ParsedMessageQueue, respStream *ParsedMessageQueue) []Record {
if len(*reqStream) == 0 || len(*respStream) == 0 {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion agent/protocol/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (h *HTTPStreamParser) Match(reqStreams map[StreamId]*ParsedMessageQueue, re
if !ok1 || !ok2 {
return []Record{}
}
return matchByTimestamp(reqStream, respStream)
return MatchByTimestamp(reqStream, respStream)
}

func (h *HTTPStreamParser) FindBoundary(streamBuffer *buffer.StreamBuffer, messageType MessageType, startPos int) int {
Expand Down
42 changes: 42 additions & 0 deletions agent/protocol/nats/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package nats

import (
"kyanos/agent/protocol"
"kyanos/bpf"
"kyanos/common"
"slices"
Comment on lines +4 to +7

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"kyanos/agent/protocol"
"kyanos/bpf"
"kyanos/common"
"slices"
"slices"
"kyanos/agent/protocol"
"kyanos/bpf"
"kyanos/common"

)

var _ protocol.ProtocolFilter = NatsFilter{}

type NatsFilter struct {
Protocols []string
Subjects []string
}

func (filter NatsFilter) FilterByProtocol(protocol bpf.AgentTrafficProtocolT) bool {
return protocol == bpf.AgentTrafficProtocolTKProtocolNATS
}

func (filter NatsFilter) FilterByRequest() bool {
return len(filter.Protocols) > 0 || len(filter.Subjects) > 0
}

func (filter NatsFilter) FilterByResponse() bool {
return false
}

func (filter NatsFilter) Filter(req protocol.ParsedMessage, rsp protocol.ParsedMessage) bool {
natsReq, ok := req.(*NatsMessage)
if !ok {
common.ProtocolParserLog.Warnf("[NATSFilter] cast to NatsMessage failed: %v\n", req)
return false
}
if len(filter.Protocols) > 0 && !slices.Contains(filter.Protocols, natsReq.ProtocolCode.String()) {
return false
}
if len(filter.Subjects) > 0 && len(natsReq.Subject) > 0 && !slices.Contains(filter.Subjects, natsReq.Subject) {
return false
}
return true
}
Loading
Loading