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

Add request/response payload of Redis to span data #325

Merged
merged 4 commits into from
Sep 27, 2022
Merged
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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
2. Records in this file are not identical to the title of their Pull Requests. A detailed description is necessary for understanding what changes are and why they are made.

## Unreleased
## Enhancements
- Add request and response payload of `Redis` protocol message to `Span` data. ([#325](https://github.com/CloudDectective-Harmonycloud/kindling/pull/325))

## v0.4.1 - 2022-09-21
### Enhancements
- When processing Redis' Requests, add additional labels to describe the key information of the message. Check [Metrics Document](https://github.com/CloudDectective-Harmonycloud/kindling/blob/main/docs/prometheus_metrics.md) for more details. ([#321](https://github.com/CloudDectective-Harmonycloud/kindling/pull/321))

### Bug fixes
- Fix the bug when the kernel does not support some kprobe, the probe crashes.
- Fix the bug when the kernel does not support some kprobe, the probe crashes. ([#320](https://github.com/CloudDectective-Harmonycloud/kindling/pull/320))

## v0.4.0 - 2022-09-19
### Enhancements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func parseDubboRequest() protocol.ParsePkgFn {
}

message.AddStringAttribute(constlabels.ContentKey, contentKey)
message.AddStringAttribute(constlabels.DubboRequestPayload, getAsciiString(message.GetData(16, protocol.GetDubboPayLoadLength())))
message.AddStringAttribute(constlabels.RequestPayload, getAsciiString(message.GetData(16, protocol.GetDubboPayLoadLength())))
return true, true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func parseDubboResponse() protocol.ParsePkgFn {
message.AddBoolAttribute(constlabels.IsError, true)
message.AddIntAttribute(constlabels.ErrorType, int64(constlabels.ProtocolError))
}
message.AddStringAttribute(constlabels.DubboResponsePayload, getAsciiString(message.GetData(16, protocol.GetDubboPayLoadLength())))
message.AddStringAttribute(constlabels.ResponsePayload, getAsciiString(message.GetData(16, protocol.GetDubboPayLoadLength())))
return true, true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ func TestParseHttpRequest_GetPayLoad(t *testing.T) {
message := protocol.NewRequestMessage([]byte(httpData))
NewHttpParser("").ParseRequest(message)

if !message.HasAttribute(constlabels.HttpRequestPayload) {
if !message.HasAttribute(constlabels.RequestPayload) {
t.Errorf("Fail to parse HttpRequest()")
}
if got := message.GetStringAttribute(constlabels.HttpRequestPayload); got != tt.want {
if got := message.GetStringAttribute(constlabels.RequestPayload); got != tt.want {
t.Errorf("GetHttpPayload() = %v, want %v", got, tt.want)
}
})
Expand All @@ -130,10 +130,10 @@ func TestParseHttpResponse_GetPayLoad(t *testing.T) {
message := protocol.NewResponseMessage([]byte(httpData), model.NewAttributeMap())
NewHttpParser("").ParseResponse(message)

if !message.HasAttribute(constlabels.HttpResponsePayload) {
if !message.HasAttribute(constlabels.ResponsePayload) {
t.Errorf("Fail to parse HttpResponse()")
}
if got := message.GetStringAttribute(constlabels.HttpResponsePayload); got != tt.want {
if got := message.GetStringAttribute(constlabels.ResponsePayload); got != tt.want {
t.Errorf("GetHttpPayload() = %v, want %v", got, tt.want)
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func parseHttpRequest(urlClusteringMethod urlclustering.ClusteringMethod) protoc

message.AddStringAttribute(constlabels.HttpMethod, string(method))
message.AddByteArrayUtf8Attribute(constlabels.HttpUrl, url)
message.AddByteArrayUtf8Attribute(constlabels.HttpRequestPayload, message.GetData(0, protocol.GetHttpPayLoadLength()))
message.AddByteArrayUtf8Attribute(constlabels.RequestPayload, message.GetData(0, protocol.GetHttpPayLoadLength()))

contentKey := urlClusteringMethod.Clustering(string(url))
if len(contentKey) == 0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func parseHttpResponse() protocol.ParsePkgFn {
}

message.AddIntAttribute(constlabels.HttpStatusCode, statusCodeI)
message.AddByteArrayUtf8Attribute(constlabels.HttpResponsePayload, message.GetData(0, protocol.GetHttpPayLoadLength()))
message.AddByteArrayUtf8Attribute(constlabels.ResponsePayload, message.GetData(0, protocol.GetHttpPayLoadLength()))
if statusCodeI >= 400 {
message.AddBoolAttribute(constlabels.IsError, true)
message.AddIntAttribute(constlabels.ErrorType, int64(constlabels.ProtocolError))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func GetPayLoadLength(protocol string) int {
if length, ok := payloadLength[protocol]; ok {
return length
}
return 80
return 200
}

func GetHttpPayLoadLength() int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redis

import (
"github.com/Kindling-project/kindling/collector/pkg/component/analyzer/network/protocol"
"github.com/Kindling-project/kindling/collector/pkg/model/constlabels"
)

/*
Expand All @@ -20,6 +21,7 @@ func fastfailRedisRequest() protocol.FastFailFn {

func parseRedisRequest() protocol.ParsePkgFn {
return func(message *protocol.PayloadMessage) (bool, bool) {
message.AddByteArrayUtf8Attribute(constlabels.RequestPayload, message.GetData(0, protocol.GetPayLoadLength(protocol.REDIS)))
return true, false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redis

import (
"github.com/Kindling-project/kindling/collector/pkg/component/analyzer/network/protocol"
"github.com/Kindling-project/kindling/collector/pkg/model/constlabels"
)

/*
Expand All @@ -24,6 +25,7 @@ func fastfailResponse() protocol.FastFailFn {

func parseResponse() protocol.ParsePkgFn {
return func(message *protocol.PayloadMessage) (bool, bool) {
message.AddByteArrayUtf8Attribute(constlabels.ResponsePayload, message.GetData(0, protocol.GetPayLoadLength(protocol.REDIS)))
return true, false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ trace:
redis_command: "get"
is_error: false
error_type: 0
request_payload: "*2\r\n$3\r\nget\r\n$3\r\nkey\r\n"
response_payload: "$3\r\nabc\r\n"
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ var spanProtocol = []extraLabelsParam{
{constlabels.SpanHttpStatusCode, constlabels.HttpStatusCode, Int64},
{constlabels.SpanHttpTraceId, constlabels.HttpApmTraceId, String},
{constlabels.SpanHttpTraceType, constlabels.HttpApmTraceType, String},
{constlabels.SpanHttpRequestHeaders, constlabels.HttpRequestPayload, String},
{constlabels.SpanHttpRequestHeaders, constlabels.RequestPayload, String},
{constlabels.SpanHttpRequestBody, constlabels.STR_EMPTY, StrEmpty},
{constlabels.SpanHttpResponseHeaders, constlabels.HttpResponsePayload, String},
{constlabels.SpanHttpResponseHeaders, constlabels.ResponsePayload, String},
{constlabels.SpanHttpResponseBody, constlabels.STR_EMPTY, StrEmpty},
}, extraLabelsKey{HTTP}},
{[]dictionary{
Expand All @@ -239,13 +239,15 @@ var spanProtocol = []extraLabelsParam{
{constlabels.SpanDnsRCode, constlabels.DnsRcode, FromInt64ToString},
}, extraLabelsKey{DNS}},
{[]dictionary{
{constlabels.SpanDubboRequestBody, constlabels.DubboRequestPayload, String},
{constlabels.SpanDubboResponseBody, constlabels.DubboResponsePayload, String},
{constlabels.SpanDubboRequestBody, constlabels.RequestPayload, String},
{constlabels.SpanDubboResponseBody, constlabels.ResponsePayload, String},
{constlabels.SpanDubboErrorCode, constlabels.DubboErrorCode, Int64},
}, extraLabelsKey{DUBBO}},
{[]dictionary{
{constlabels.SpanRedisCommand, constlabels.RedisCommand, String},
{constlabels.SpanRedisErrorMsg, constlabels.RedisErrMsg, String},
{constlabels.SpanRedisRequestPayload, constlabels.RequestPayload, String},
{constlabels.SpanRedisResponsePayload, constlabels.ResponsePayload, String},
}, extraLabelsKey{REDIS}},
{
[]dictionary{}, extraLabelsKey{UNSUPPORTED},
Expand Down
6 changes: 4 additions & 2 deletions collector/pkg/model/constlabels/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ const (
SpanDubboRequestBody = "dubbo.request_body"
SpanDubboResponseBody = "dubbo.response_body"

SpanRedisCommand = "redis.command"
SpanRedisErrorMsg = "redis.error_msg"
SpanRedisCommand = "redis.command"
SpanRedisErrorMsg = "redis.error_msg"
SpanRedisRequestPayload = "redis.request_payload"
SpanRedisResponsePayload = "redis.request_payload"

NetWorkAnalyzeMetricGroup = "netAnalyzeMetrics"
)
Expand Down
21 changes: 9 additions & 12 deletions collector/pkg/model/constlabels/protocols.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package constlabels

const (
ContentKey = "content_key"
ContentKey = "content_key"
RequestPayload = "request_payload"
ResponsePayload = "response_payload"

HttpMethod = "http_method"
HttpUrl = "http_url"
HttpApmTraceType = "trace_type"
HttpApmTraceId = "trace_id"
HttpRequestPayload = "request_payload"
HttpResponsePayload = "response_payload"
HttpStatusCode = "http_status_code"
HttpMethod = "http_method"
HttpUrl = "http_url"
HttpApmTraceType = "trace_type"
HttpApmTraceId = "trace_id"
HttpStatusCode = "http_status_code"

DnsId = "dns_id"
DnsDomain = "dns_domain"
Expand All @@ -27,10 +27,7 @@ const (
KafkaVersion = "kafka_version"
KafkaCorrelationId = "kafka_id"
KafkaTopic = "kafka_topic"
KafkaPartition = "kafka_partition"
KafkaErrorCode = "kafka_error_code"

DubboRequestPayload = "request_payload"
DubboResponsePayload = "response_payload"
DubboErrorCode = "dubbo_error_code"
DubboErrorCode = "dubbo_error_code"
)